所以,我有一个将对象绘制到屏幕的功能,只要按下鼠标左键,就会调用此功能。问题是因为计算机工作得非常快,程序认为我按住鼠标左键0.5秒并且该函数被多次调用。我该如何防止它发生?
提前致谢。
功能:
public void drawAll(){
batch.begin();
for( int i = 0; i < 10000; i++){
if( Assets.draws[i].draw == true ){ batch.draw( Assets.draws[i].sprite, Assets.draws[i].x, Assets.draws[i].y); }
}
batch.end();
}
public void pressedLeft(){
float x = Gdx.input.getX();
float y = Gdx.input.getY();
boolean contin = true;
for( int i = 0; i < 10000; i++){
if( contin == true && Assets.draws[i].draw == false ){ Assets.draws[i].draw = true; contin = false; Assets.draws[i].x = x; Assets.draws[i].y = y; }
}
}
@Override
public void render(){
.
.
.
drawAll();
if( Gdx.input.isButtonPressed( Input.Buttons.LEFT ) ){ pressedLeft(); }
}