这是未经编辑的代码,因此您可以了解一下,我使用的是 WVC 方法,这是主要的渲染方法,如果您想查看此处调用的方法,请告诉我。我知道代码需要优化所以如果您看到任何重大问题,请让我知道我应该做什么.. ty
public void render() {
player01_class player01 = world.getPlayer01();
if ((player01.getPosition().x) > (CAMERA_WIDTH / 2)) {
cam.position.set((player01.getPosition().x), (cam.position.y), 0);
//cam.zoom = 3f;
cam.update();
} else if ((player01.getPosition().x) < (CAMERA_WIDTH / 2)) {
cam.position.set((player01.getPosition().x), (cam.position.y), 0);
//cam.zoom = 3f;
cam.update();
}
if ((player01.getPosition().y) > (CAMERA_HEIGHT / 2)) {
cam.position.set((cam.position.x), (player01.getPosition().y) , 0);
//cam.zoom = 3f;
cam.update();
} else if ((player01.getPosition().y) < (CAMERA_HEIGHT) / 2) {
cam.position.set((cam.position.x), (cam.position.y) , 0);
//cam.zoom = 3f;
cam.update();
}
clipBounds = new Rectangle(cam.position.x - 10, cam.position.y - 10, cam.viewportWidth, cam.viewportHeight);
ScissorStack.calculateScissors(cam, spriteBatch.getTransformMatrix(), clipBounds, scissors);
ScissorStack.pushScissors(scissors);
spriteBatch.setProjectionMatrix(cam.combined);
spriteBatch.begin();
//bg_pilot.setPosition(player01.getPosition().x / 1.05f - 10, 0);
//bg_pilot.draw(spriteBatch, 1f);
pangodavillageBG_x = player01.getPosition().x;
spriteBatch.draw(new TextureRegion(pangodavillageBG01), pangodavillageBG_x / 1.80f, 2 , 25, 25);
spriteBatch.draw(new TextureRegion(pangodavillageBG02), pangodavillageBG_x / 1.80f + 25, 2 , 25, 25);
spriteBatch.draw(new TextureRegion(pangodavillageBG03), pangodavillageBG_x / 1.80f + 50, 2 , 25, 25);
spriteBatch.draw(new TextureRegion(pangodavillageBG04), pangodavillageBG_x / 1.80f + 75, 2 , 25, 25);
spriteBatch.draw(new TextureRegion(pangodavillageFG01), pangodavillageBG_x / 2.00f, 0 , 25, 25);
spriteBatch.draw(new TextureRegion(pangodavillageFG02), pangodavillageBG_x / 2.00f + 25, 0 , 25, 25);
spriteBatch.draw(new TextureRegion(pangodavillageFG03), pangodavillageBG_x / 2.00f + 50, 0 , 25, 25);
spriteBatch.draw(new TextureRegion(pangodavillageFG04), pangodavillageBG_x / 2.00f + 75, 0 , 25, 25);
// drawClouds();
UpdateTime();
drawBlocks();
//if (controller.edit_toggle) {
drawEditBlocks();
//}
drawItems();
drawPowerUps();
drawPlayer01();
drawBadGuy();
drawUIItems();
//stage.act(Gdx.graphics.getDeltaTime());
// stage.draw();
bmpfont.draw(spriteBatch, "FPS: " + Gdx.graphics.getFramesPerSecond(), cam.position.x - 10, cam.position.y + 7);
bmpfont.drawMultiLine(spriteBatch, "playerX: " + (int)player01.getPosition().x + " Y: " + (int)player01.getPosition().y, cam.position.x - 10, cam.position.y + 6, 1f, HAlignment.LEFT);
// bmpfont.drawMultiLine(spriteBatch, "rx1: " + rectx1 + " ry1: " + recty1, cam.position.x - 10, cam.position.y + 5, 1, HAlignment.LEFT);
// bmpfont.drawMultiLine(spriteBatch, "block: " + currentBlock_counter, cam.position.x - 10, cam.position.y + 5, 1, HAlignment.LEFT);
//bmpfont.drawMultiLine(spriteBatch, "badx: " + badGuy.getPosition().x + " badguyy: " + badGuy.getPosition().y, cam.position.x - 10, cam.position.y + 4, 1, HAlignment.LEFT);
//bmpfont.drawMultiLine(spriteBatch, "cvelocity: " + badGuy.getAcceleration() + " VBGy: " + badGuy.blockCollidedwithBGY , cam.position.x - 10, cam.position.y + 3, 1f, HAlignment.LEFT);
bmpfont.drawMultiLine(spriteBatch, "mouseX: " + mouseX + " Y: " + mouseY , cam.position.x - 10, cam.position.y + 5, 1f, HAlignment.LEFT);
//bmpfont.drawMultiLine(spriteBatch, "mousexX: " + mouseRawX + " Y: " + mouseRawY , cam.position.x - 10, cam.position.y + 3, 1f, HAlignment.LEFT);
bmpfont.drawMultiLine(spriteBatch, "camposX: " + (int)cam.position.x + " camposY: " + (int)cam.position.y, cam.position.x - 10, cam.position.y + 4, 1f, HAlignment.LEFT);
bmpfont.drawMultiLine(spriteBatch, "H: " + WorldTime_hour + " M: " + WorldTime_min + " S: " + (int)WorldTime_sec, cam.position.x + 6, cam.position.y + 7, 1f, HAlignment.LEFT);
//bmpfont.drawMultiLine(spriteBatch, "TileNumber: " + mapTile_ID + " block_collide_bool: " + map_block_collide_bool, cam.position.x - 10, cam.position.y + 3, 1f, HAlignment.LEFT);
//bmpfont.drawMultiLine(spriteBatch, " aY: " + addButtonRect, cam.position.x, cam.position.y + 2, 1f, HAlignment.LEFT);
// bmpfont.drawMultiLine(spriteBatch, "m: " + rect_mouse + " a: " + addButtonRect, cam.position.x - 10, cam.position.y + 2, 1f, HAlignment.LEFT);
//bmpfont.drawMultiLine(spriteBatch, "mapTileID: " + mapTile_ID, cam.position.x - 10, cam.position.y + 2, 1f, HAlignment.LEFT);
// bmpfont.drawMultiLine(spriteBatch, "Game Mode: " + edit_toggle , cam.position.x - 10, cam.position.y + 1, 1f, HAlignment.LEFT);
spriteBatch.end();
if (debug) {
drawDebug();
//drawCollisionBlocks();
// drawCollisionToggleBlocks();
drawEditMenu();
}
spriteBatch.begin();
//updateParticles();
spriteBatch.end();
// spriteBatch.setProjectionMatrix(cam.combined);
spriteBatch.begin();
bmpfont.setScale(.03f);
bmpfont.setColor(new Color(1,1,1,1));
bmpfont.draw(spriteBatch, "ADD", cam.position.x - 9.5f, cam.position.y + 9.65f);
bmpfont.draw(spriteBatch, "DEL", cam.position.x - 7.9f, cam.position.y + 9.65f);
bmpfont.draw(spriteBatch, "MODE", cam.position.x - 5.4f, cam.position.y + 9.65f);
bmpfont.draw(spriteBatch, "BLK", cam.position.x - 2.9f, cam.position.y + 9.65f);
bmpfont.draw(spriteBatch, "ITM", cam.position.x - 1.35f, cam.position.y + 9.65f);
bmpfont.draw(spriteBatch, "BAD", cam.position.x - -0.1f, cam.position.y + 9.65f);
spriteBatch.end();
spriteBatch.flush();
ScissorStack.popScissors();
bmpfont.setColor(new Color(1,1,1,1));
bmpfont.setScale(.04f);
}
这是drawBlocks方法:
private void drawBlocks() {
player01_class player01 = world.getPlayer01();
displayBlock_x[3] = player01.getPosition().x;
displayBlock_y[3] = cam.position.y + 8;
for (Block block : world.getBlocks()) {
//spriteBatch.draw(blockTextureRegion, block.getPosition().x * ppuX, block.getPosition().y * ppuY, Block.SIZE * ppuX, Block.SIZE * ppuY);
switch (block.blockID)
{
case 0:
spriteBatch.draw(new TextureRegion(blockTextureRegion), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 1:
spriteBatch.draw(new TextureRegion(blockTextureRegion_metal), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 2:
spriteBatch.draw(new TextureRegion(btr_basket), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 3:
spriteBatch.draw(new TextureRegion( btr_sand ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 4:
spriteBatch.draw(new TextureRegion( btr_stone1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 5:
spriteBatch.draw(new TextureRegion( btr_brick ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 6:
spriteBatch.draw(new TextureRegion( btr_jewel ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 7:
spriteBatch.draw(new TextureRegion(btr_waterlike), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 8:
spriteBatch.draw(new TextureRegion(btr_dirtfull1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 9:
spriteBatch.draw(new TextureRegion( btr_dirtleftside1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 10:
spriteBatch.draw(new TextureRegion(btr_dirtrightside1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 11:
spriteBatch.draw(new TextureRegion( btr_dirttop1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 12:
spriteBatch.draw(new TextureRegion( btr_dirt_leftgrassend1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 13:
spriteBatch.draw(new TextureRegion( btr_dirt_rightgrassend1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 14:
spriteBatch.draw(new TextureRegion( btr_grass1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 15:
spriteBatch.draw(new TextureRegion(btr_grass_leftend1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 16:
spriteBatch.draw(new TextureRegion( btr_grass_rightend1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 17:
spriteBatch.draw(new TextureRegion(btr_grasspatch1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 18:
spriteBatch.draw(new TextureRegion(sand_full_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 19:
spriteBatch.draw(new TextureRegion(marble_white_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 20:
spriteBatch.draw(new TextureRegion(marble_darkwhite_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 21:
spriteBatch.draw(new TextureRegion(stone_darkgrey_2), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 22:
spriteBatch.draw(new TextureRegion( stone_darkgrey_3 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 23:
spriteBatch.draw(new TextureRegion( stone_grey_1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 24:
spriteBatch.draw(new TextureRegion( stone_grey_2 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 25:
spriteBatch.draw(new TextureRegion( stoneinset_grey_1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 26:
spriteBatch.draw(new TextureRegion(stoneinset_darkgrey_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 27:
spriteBatch.draw(new TextureRegion(stoneoutset_grey_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 28:
spriteBatch.draw(new TextureRegion( stoneoutset_darkgrey_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 29:
spriteBatch.draw(new TextureRegion(stone_decogrey_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 30:
spriteBatch.draw(new TextureRegion( stone_decodarkgrey_1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 31:
spriteBatch.draw(new TextureRegion( stone_decogrey_2 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 32:
spriteBatch.draw(new TextureRegion( stone_decodarkgrey_2 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 33:
spriteBatch.draw(new TextureRegion( stone_decoblue_1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 34:
spriteBatch.draw(new TextureRegion(stone_decodarkblue_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 35:
spriteBatch.draw(new TextureRegion( stone_decogreen_1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 36:
spriteBatch.draw(new TextureRegion(stone_decodarkgreen_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 37:
spriteBatch.draw(new TextureRegion(stone_decoyellow_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 38:
spriteBatch.draw(new TextureRegion( stone_decodarkyellow_1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 39:
spriteBatch.draw(new TextureRegion( stone_decoorange_1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 40:
spriteBatch.draw(new TextureRegion( stone_decodarkorange_1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 41:
spriteBatch.draw(new TextureRegion( stone_decopurple_1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 42:
spriteBatch.draw(new TextureRegion(stone_decodarkpurple_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 43:
spriteBatch.draw(new TextureRegion( woodpanel_top_1 ), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 44:
spriteBatch.draw(new TextureRegion(woodpanel_mid_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
case 45:
spriteBatch.draw(new TextureRegion(woodpanel_bottom_1), block.getPosition().x , block.getPosition().y , block.getSize(), block.getSize());
break;
}
}
if (currentBlock_counter > 45) {
currentBlock_counter = 0;
}
}
这是drawPlayer方法:
private void drawPlayer01() {
player01_class player01 = world.getPlayer01();
player01Frame = player01.isFacingLeft() ? playerIdleLeft : playerIdleRight;
if(player01.getState().equals(State.WALKING)) {
player01Frame = player01.isFacingLeft() ? walkLeftAnimation.getKeyFrame(player01.getStateTime(), true) :
walkRightAnimation.getKeyFrame(player01.getStateTime(), true);
} else if (player01.getState().equals(State.JUMPING)) {
if (player01.getVelocity().y > 0) {
player01Frame = player01.isFacingLeft() ? player01JumpLeft : player01JumpRight;
} else {
player01Frame = player01.isFacingLeft() ? player01FallLeft : player01FallRight;
}
} else if (player01.getState().equals(State.ATTACKING)) {
player01Frame = player01.isFacingLeft() ? playerAtkLeft : playerAtkRight;
}
//spriteBatch.draw(player01Frame, player01.getPosition().x * ppuX, player01.getPosition().y * ppuY, player01.SIZE * ppuX, player01.SIZE * ppuY);
//Attack
if (player01.boolWeapon_isStriking) {
int a = 0;
player01Frame = player01.isFacingLeft() ? playerAtkLeft : playerAtkRight;
sword01Frame = player01.isFacingLeft() ? sword01L : sword01R;
//if(System.currentTimeMillis() - lastPressProcessed > 20) {
if (!player01.isFacingLeft()) {
player01.weaponPosition.set(player01.getPosition().x + 1, player01.getPosition().y);
} else if (player01.isFacingLeft()){
//player01Frame = player01.isFacingLeft() ? sword01L : sword01R;
player01.weaponPosition.set(player01.getPosition().x - 1.5f, player01.getPosition().y);
}
//spriteBatch.draw(player01Frame, player01.getPosition().x, player01.getPosition().y, player01.getSizeW() , player01.getSizeH() );
spriteBatch.draw(new TextureRegion(sword01Frame), player01.weaponPosition.x, player01.weaponPosition.y - 0.00f, player01.getWeaponSizeW() , player01.getWeaponSizeH());
}
spriteBatch.draw(player01Frame, player01.getPosition().x, player01.getPosition().y, player01.getSizeW() , player01.getSizeH() );
}