我希望使用动画
渲染特定的帧batch.draw(Animation.getKeyFrame(time,true),x,y);
例如,当我点击某个地方时,我希望动画更改为第二个图像而不是仅仅循环来自TextureAtlas的帧。
更新
public void newBitter(){
Sprite spr= Pools.obtain(Sprite.class);
bitters.add(spr);
spr.setPosition(rX, Y);
} //the sprites are not rendered I just need them for the c
oordinates
while(Iterator.hasNext()){
Sprite sprite=Iterator.next();
batch.draw(frames[frameCounter],sprite.getX(),sprite.getY());
sprite.translateY(-300 * deltaTime);
if(touched==true && gameObj.pos.x>=sprite.getX() && gameObj.pos.x<=sprite.getX()+82
&& gameObj.pos.y>=sprite.getY() && gameObj.pos.y<=sprite.getY()+82){
frameCounter=1;
} //here I render the frames/animation based on the sprite coordinates, If the sprite is clicked the counter for the frames ==1 or +=1
}
}
答案 0 :(得分:1)
将所有动画帧保留在集合中,然后根据以下条件修改当前帧ID:
Animation animation;
...
TextureRegion[] frames = animation.getKeyFrames();
int currentFrameId = 0;
...
if( clickedOnSomething() ) //let the clickedOnSomething method return true when clicked
{
currentFrameId++; //or another change due to some conditions
}
...
batch.draw(frames[currentFrameId], x, y);