現在我有MainStarting類,其中游戲循環和油漆每60 FPS發生。如何讓角色腿移動在Java
我有3個狀態爲字符1-迴避,2-跳躍和3-行走,並且每個狀態都有它自己的圖片,我將這張圖片稱爲一個按鍵。
現在我想讓他的腿不僅移動,而且我不理解這樣做的邏輯。 我需要多少圖片? 60圖像覆蓋整個運動循環[從左腿開始,然後從右腿開始,然後站立] 60 cups的FPS?
多數民衆贊成在我所說的圖片
public void init() {
setSize(800, 480);
setBackground(Color.BLACK);
setFocusable(true);
addKeyListener(this);
Frame frame = (Frame) this.getParent().getParent();
frame.setTitle("Q-Bot Alpha");
try {
base = getDocumentBase();
} catch (Exception e) {
// TODO: handle exception
}
// Here are the images , Only 3 images standing and jumping and ducking
character = getImage(base, "data/character.png");
characterDown = getImage(base, "data/down.png");
characterJumped = getImage(base, "data/jumped.png");
currentSprite = character;
background = getImage(base, "data/background.png");
heliboy = getImage(base, "data/heliboy.png");
}
,這裏是遊戲圈
public void run() {
while (true) {
robot.update();
if (robot.isJumped()) {
currentSprite = characterJumped;
} else if (robot.isJumped() == false && robot.isDucked() == false) {
currentSprite = character; // use switch case in case the character is moving so u can use 10 pictures of the Stick man animation with switch case
}
ArrayList projectiles = robot.getProjectiles();
for (int i = 0; i < projectiles.size(); i++) {
Projectile p = (Projectile) projectiles.get(i);
if (p.isVisible() == true) {
p.update();
} else {
projectiles.remove(i);
}
}
bg1.update();
bg2.update();
hb.update();
hb2.update();
repaint();
try {
Thread.sleep(17); // To get 60 FPS per second
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
然後我使用塗料的方法只是油漆的方法。 因此,我如何解決這個問題的任何幫助?
_「我需要多少圖片」_這取決於您希望動畫的順利程度。 60個動畫幀聽起來像是矯枉過正,但取決於你。 – Michael
嗯我不明白你是什麼矯枉過正的意思是,我知道60張圖片是很多,特別是我會做很多動畫,我不想消耗大量的CPU資源。那麼是否有另一種方法或解決方案? – user3293240
overkill =超過需要 – Michael