gpt4 book ai didi

java - 如何渲染动画的特定帧?

转载 作者:行者123 更新时间:2023-12-01 11:11:25 25 4
gpt4 key购买 nike

我想要使用动画渲染特定帧

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

坐标

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
}
}

最佳答案

只需将所有动画帧保留在集合中,然后根据以下条件修改当前帧 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);

关于java - 如何渲染动画的特定帧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32313610/

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