2012-12-13 1 views
6

Ecco il mio codice:Qual è il modo più semplice per rendere l'immagine tangibile in libgdx?

@Override 
public void resize(int width, int height) { 
super.resize(width, height); 

stage.clear(); 

// background image 
Image backImage = new Image(backTexture); 
backImage.setX(0); 
backImage.setY(0); 
backImage.setWidth(800); 
backImage.setHeight(480); 

// start game image 
Image startImage = new Image(startTexture); 
startImage.setX(415); 
startImage.setY(180); 
startImage.setWidth(323); 
startImage.setHeight(69); 

stage.addActor(backImage); 
stage.addActor(startImage); 
} 

che sto creando gioco semplice e questo è il modo in cui sto creando menu principale. Voglio rendere il mio startImage touchable (cliccabile) in quanto non esiste un listener disponibile per la classe Image. Come dovrei farlo? O è meglio usare ImageButton? In questo modo avrei dovuto creare un atlante di immagini che sembra essere un po 'complicato per me ora ..

EDIT: Ho provato seguente:

startImage.addListener(new ClickListener() { 
    public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) 
    { 
     game.setScreen(new SplashScreen(game)); 
     return true; 
    } 
}); 

Ma ancora non funziona ..

EDIT:

Gdx.input.setInputProcessor(stage); 

deve essere chiamato. Risolto.

+0

trovato la soluzione qui: http://stackoverflow.com/questions/11373390/button-clicklistener-is-not-working-in-libgdx-game [1]: http://stackoverflow.com/questions/11373390/button-clicklistener-is-not-working-in-libgdx-game – milano

+0

Si prega di fornire la soluzione come una "risposta" e accettarlo. Vedi http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/ –

risposta

9

soluzione è chiamare seguente:

Gdx.input.setInputProcessor(stage);