gpt4 book ai didi

java - 我如何让我的 spaceship 移动?

转载 作者:行者123 更新时间:2023-11-29 07:40:44 25 4
gpt4 key购买 nike

我做了这些方法:

public Player(double x, double y){
this.x = x;
this.y = y;

ImageLoader loader = new ImageLoader();
SpriteSheet ss = new SpriteSheet(loader.loadImage("/Pics/TheSpriteSheet.png"));
this.image = ss.grabImage(1, 1, 32, 32);
}
public void tick(){
this.x++;
}
public void render(Graphics g){
g.drawImage(image, (int) x, (int) y, null);
}

然后我把它放在主类的 tick 方法中,它每纳秒左右被调用一次。

public void tick(){
playerClass.tick();
}

最佳答案

看起来您只是在更新 spaceship 的 x 位置,但并未重绘屏幕。因此,x 位置增加了,但您不会在屏幕上看到它!

您可能会使用类似spaceShip.repaint();

关于java - 我如何让我的 spaceship 移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30507786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com