gpt4 book ai didi

java - 在 Java (Android) libgdx 中,触摸时绘制/渲染动画

转载 作者:太空宇宙 更新时间:2023-11-04 11:45:34 26 4
gpt4 key购买 nike

在 Java (Android) libgdx 中,当刚刚触摸时绘制/渲染动画,否则它将显示动画中的特定帧。问题是当我触摸屏幕时,它只会渲染一秒钟的动画。

   //@render   Spritebatch sb;

if(Gdx.input.justTouched()){
sb.draw((Texture) animation.getKeyFrame(timePassed,true), Gdx.graphics.getWidth() * 0.03f, Gdx.graphics.getHeight() * 0.03f, (Gdx.graphics.getWidth() * 1 / 6), (Gdx.graphics.getHeight() / 2) + (Gdx.graphics.getHeight() * 0.13f));
}

else{
sb.draw(shot[1], Gdx.graphics.getWidth() * 0.03f, Gdx.graphics.getHeight() * 0.03f, (Gdx.graphics.getWidth() * 1 / 6), (Gdx.graphics.getHeight() / 2) + (Gdx.graphics.getHeight() * 0.13f));
}

最佳答案

第二个参数 getKeyFrame(..) 启用循环,无论动画是否循环。设定为真。为什么不使用animation.getKeyFrame(stateTime)而不是animation.getKeyFrame(float stateTime, booleanlooping)。确保 Animation.PlayMode 已循环。

 if(!Gdx.input.justTouched()){
sb.draw(shot[1], Gdx.graphics.getWidth() * 0.03f, Gdx.graphics.getHeight() * 0.03f, (Gdx.graphics.getWidth() * 1 / 6), (Gdx.graphics.getHeight() / 2) + (Gdx.graphics.getHeight() * 0.13f));
}
else{
sb.draw((Texture) animation.getKeyFrame(timePassed,true), Gdx.graphics.getWidth() * 0.03f, Gdx.graphics.getHeight() * 0.03f, (Gdx.graphics.getWidth() * 1 / 6), (Gdx.graphics.getHeight() / 2) + (Gdx.graphics.getHeight() * 0.13f));
}

关于java - 在 Java (Android) libgdx 中,触摸时绘制/渲染动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42384311/

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