我怎么在暂停的libGDX与SpriteAnimation一个按钮,可以查看当前帧时暂停按钮pressed? [英] how do I pause the SpriteAnimation in libGDX with a button to be able to view the current frame when pause button is pressed?
问题描述
我试图用一个暂停/恢复按钮暂停动画,这样做:
I was trying to pause the animation with a pause/resume button, by doing this :
public static int gameStatus = 1;
public int gamePaused = 0;
public int gameRunning = 0;
public void create(){
gameRunning = 1;
//.. code
}
public void render(){
if(gameStatus == gameRunning){
//some code ..
pause.setClickListener( new ClickListener() {
@Override
public void click(Actor actor, float x, float y) {
System.out.println("pause is pressed");
//to stop the animation at a particular frame
spriteBatch.begin();
spriteBatch.draw(currentFrame, 100, 100);
spriteBatch.end();
if(gameStatus!=gamePaused)
{
gameStatus = gamePaused;
}
else
{
gameStatus = 1;
}
}
});
//rest of my render animation code ..
}
}
但是在桌面上,显示了当前帧的3/4和下一帧的1/4。知道为什么吗?而在Android的表现像整个图像是shivering.I'm也许不知道它,因为它再次调用并再次渲染()。我不明白为什么会出现在Android上的输出中和桌面版本的差异。难道他们不应该是一样的吗?我认为这是两者之间的一些索引问题。任何机构都经历了同样的问题?任何建议或一种合适的方式来暂停动画或教程链接将是非常有益的。三江源。
But on the desktop it shows 3/4th of the current frame and 1/4th of the next frame. Any idea why? And in android it behaves like the entire image is shivering.I'm wondering maybe its because its calling render() again and again. I dont understand why there is a difference in the ouput in android and the desktop version. Aren't they supposed to be the same? I think there is some indexing issue between the two. Any body else experienced the same issue? Any suggestions or a proper way to pause the animation or a tutorial link would be really helpful. Thankyou.
推荐答案
我也没有任何问题,闪烁像我不得不通过简单地从暂停的方法去除spriteBatch.draw()暂停执行,并通过使用一个布尔变量来知道何时渲染和何时不呈现序暂停动画。
这是我做的(以防人有同样的问题):
I did the pause implementation without any flickering issues like I had by simply removing the spriteBatch.draw() from the pause method, and by using a boolean variable to know when to render and when not to render inorder to pause the animation. This is how I did it (in case anyone had the same issues):
private boolean isPlaying = true;
@Override
public void pause() {
Gdx.app.log("pause():", "pausing the app");
if( isPlaying )
{
isPlaying = false;
}
else
{
isPlaying = true;
}
}
@Override
public void render() {
Gdx.app.log("123123", (!seekBar.isDragging())+"");
if( isPlaying )
// .. do the animation..
}
这篇关于我怎么在暂停的libGDX与SpriteAnimation一个按钮,可以查看当前帧时暂停按钮pressed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!