Libgdx:雪碧想要停止移动;

时间:2015-03-10 20:24:31

标签: java libgdx

我试图让精灵走到鼠标位置。但是,当单击鼠标并且精灵走到鼠标位置时,它不会停止并继续向同一方向移动。

这是我的代码:



public void render(float delta) {
    Gdx.gl.glClearColor(1,1,1,1);
	Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);	
		
	if(Gdx.input.isTouched()){
	    projected= new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
	    cam.unproject(projected);
			
	    if(position.x != projected.x || position.y != projected.y){
	
                pathX = projected.x - position.x;
		pathY = projected.y - position.y;
			
		distance = (float) Math.sqrt(pathX * pathX + pathY * pathY);
		directionX = pathX / distance;
		directionY = pathY / distance;
            }
	}
		
	position.x += directionX * Speed * delta;
	position.y += directionY * Speed * delta;
}




请帮助并非常感谢你。

1 个答案:

答案 0 :(得分:1)

这基本上是How to stop drawing a SpriteBatch animation in libgdx? ||的副本how do I pause the SpriteAnimation in libGDX with a button to be able to view the current frame when pause button is pressed?,请查看此文章以了解它是否有帮助。

简而言之,您希望跟踪玩家的移动以及当他们到达鼠标的x,y坐标时,将移动设置为false。让渲染中的逻辑仅在布尔值为真时呈现。