我设法将背景绘制成水平,但在将Ken绘制到屏幕上时遇到了麻烦,我已经编码了他的所有功能并引用了PNG文件。
我的问题是,如果我尝试在create()方法中初始化Assets,它将记录输入== null!
我只需要朝正确的方向移动poointer即可将Ken画在背景上,然后其余的就可以放进去了。
FightGame类
public class FightGame extends ApplicationAdapter {
private OrthographicCamera camera;
private SpriteBatch batch;
private AbstractScene activeScene;
private FPSLogger fpsLogger = new FPSLogger();
@Override
public void create() {
try {
Assets.init();
}catch(IOException e){
e.printStackTrace();
}
camera = new OrthographicCamera(768, 224);
camera.position.x = 240;
camera.position.y = 160;
Touch.setCamera(camera);
batch = new SpriteBatch();
changeScene(new GameScene(new Dojo(), new Ken(true)));
}
@Override
public void dispose() {
batch.dispose();
activeScene.dispose();
}
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
update();
batch.setProjectionMatrix(camera.combined);
activeScene.render(batch);
}
public void update() {
camera.update();
activeScene.update();
fpsLogger.log();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
public void changeScene(AbstractScene scene) {
if (activeScene != null)
activeScene.dispose();
activeScene = scene;
InputMultiplexer multiplexer = new InputMultiplexer();
multiplexer.addProcessor(new GestureDetector(activeScene));
multiplexer.addProcessor(activeScene);
Gdx.input.setInputProcessor(multiplexer);
}
}
资产类别
public class Assets {
// basic movement
public static BufferedImage[] idle1 = new BufferedImage[6],
parry_f1 = new BufferedImage[8],
parry_b1 = new BufferedImage[8],
crouch1 = new BufferedImage[1];
// ground attack
public static BufferedImage[] punch1 = new BufferedImage[8],
quick_punch1 = new BufferedImage[4],
crouch_punch1 = new BufferedImage[3],
crouch_attack1 = new BufferedImage[5],
uppercut1 = new BufferedImage[8];
// ground kick
public static BufferedImage[] kick_low1 = new BufferedImage[5],
upper_kick1 = new BufferedImage[10];
// air attack
public static BufferedImage[] air_punch1 = new BufferedImage[7],
air_kick1 = new BufferedImage[6],
punch_down1 = new BufferedImage[4];
// jumps
public static BufferedImage[] back_flip1 = new BufferedImage[8],
front_flip1 = new BufferedImage[8],
jump1 = new BufferedImage[11];
// hurt
public static BufferedImage[] crouch_hit1 = new BufferedImage[2],
crouch_hit_back1 = new BufferedImage[4],
hit_stand1 = new BufferedImage[2],
hit_stand_back1 = new BufferedImage[4],
knockback1 = new BufferedImage[4],
recover1 = new BufferedImage[5];
// misc.
public static BufferedImage[] win1 = new BufferedImage[10],
dead1 = new BufferedImage[1];
public static void init() throws IOException {
SpriteSheet ss_crouch1 = new SpriteSheet(ImageLoader.loadImage("ken/crouch.png"));
SpriteSheet ss_crouch_punch1 = new SpriteSheet(ImageLoader.loadImage("/ken/crouch_punch.png"));;
SpriteSheet ss_hit_stand_back1 = new SpriteSheet(ImageLoader.loadImage("/ken/hit_stand_b.png"));
SpriteSheet ss_idle1 = new SpriteSheet(ImageLoader.loadImage("/ken/idle.png"));
SpriteSheet ss_kick_low1 = new SpriteSheet(ImageLoader.loadImage("/ken/kick_low.png"));
SpriteSheet ss_parry_back1 = new SpriteSheet(ImageLoader.loadImage("/ken/parry_b.png"));
SpriteSheet ss_parry_front1 = new SpriteSheet(ImageLoader.loadImage("/ken/parry_f.png"));
SpriteSheet ss_punch1 = new SpriteSheet(ImageLoader.loadImage("/ken/punch.png"));
SpriteSheet ss_quick_punch1 = new SpriteSheet(ImageLoader.loadImage("/ken/quick_punch.png"));
SpriteSheet ss_upper_kick1 = new SpriteSheet(ImageLoader.loadImage("/ken/upper_kick.png"));
SpriteSheet ss_jump1 = new SpriteSheet(ImageLoader.loadImage("/ken/jump.png"));
SpriteSheet ss_front_flip1 = new SpriteSheet(ImageLoader.loadImage("/ken/front_flip.png"));
SpriteSheet ss_back_flip1 = new SpriteSheet(ImageLoader.loadImage("/ken/back_flip.png"));
SpriteSheet ss_air_punch1 = new SpriteSheet(ImageLoader.loadImage("/ken/air_punch.png"));
SpriteSheet ss_air_kick1 = new SpriteSheet(ImageLoader.loadImage("/ken/air_kick.png"));
SpriteSheet ss_punch_down1 = new SpriteSheet(ImageLoader.loadImage("/ken/punch_down.png"));
// ============================================ SPRITE CROPPING ============================================
// loops through frame slices and stores in array ...
// basic movement:
for (int i = 0; i < 6; i++)
idle1[i] = ss_idle1.crop(57, 106, 57 * i, 0);
for (int i = 0; i < 8; i++)
parry_f1[i] = ss_parry_front1.crop(70, 110, 70 * i, 0);
for (int i = 0; i < 8; i++)
parry_b1[i] = ss_parry_back1.crop(70, 110, 70 * i, 0);
crouch1[0] = ss_crouch1.crop(54, 73, 0, 0);
// aerial moves
jump1[0] = ss_jump1.crop(61, 124, 0, 0);
jump1[1] = ss_jump1.crop(61, 124, 0, 0);
jump1[2] = ss_jump1.crop(61, 124, 0, 0);
for (int i = 3; i < 11; i++)
jump1[i] = ss_jump1.crop(61, 124, 61 * (i - 2), 0);
for (int i = 0; i < 8; i++)
front_flip1[i] = ss_front_flip1.crop(83, 125, 83 * i, 0);
for (int i = 0; i < 8; i++)
back_flip1[i] = ss_back_flip1.crop(83, 125, 83 * i, 0);
// ground attacks
for (int i = 0; i < 8; i++)
punch1[i] = ss_punch1.crop(103, 103, 103 * i, 0);
for (int i = 0; i < 4; i++)
quick_punch1[i] = ss_quick_punch1.crop(95, 102, 95 * i, 0);
for (int i = 0; i < 3; i++)
crouch_punch1[i] = ss_crouch_punch1.crop(89, 72, 89 * i, 0);
// ground kick
for (int i = 0; i < 5; i++)
kick_low1[i] = ss_kick_low1.crop(118, 105, 118 * i, 0);
for (int i = 0; i < 10; i++)
upper_kick1[i] = ss_upper_kick1.crop(135, 108, 135 * i, 0);
// air attacks
for (int i = 0; i < 7; i++)
air_punch1[i] = ss_air_punch1.crop(84, 95, 84 * i, 0);
for (int i = 0; i < 4; i++)
punch_down1[i] = ss_punch_down1.crop(68, 88, 68 * i, 0);
for (int i = 0; i < 6; i++)
air_kick1[i] = ss_air_kick1.crop(106, 83, 106 * i, 0);
// hurt
for (int i = 0; i < 4; i++)
hit_stand_back1[i] = ss_hit_stand_back1.crop(79, 104, 79 * i, 0);
}
}
ImageLoader类
public class ImageLoader {
public static BufferedImage loadImage(String path) {
try {
return ImageIO.read(ImageLoader.class.getResource(path));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
还有其他需要上课的地方吗?
谢谢。