1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
public class TestScene2d implements Screen {
final static int SCREEN_HEIGHT = 480;
final static int SCREEN_WIDTH = 800;
Stage stage;
int posCurseurX,posCurseurY;
Skin skin;
Image squareImage;
@Override
public void show() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
skin = new Skin();
skin.add("Square", new Texture("assets/player.png"));
}
@Override
public void render(float arg0) {
stage.draw();
stage.act(Gdx.graphics.getDeltaTime());
Gdx.input.setInputProcessor(new InputController() {
@Override
public boolean mouseMoved(int x, int y) {
// Récupérer la position du curseur
posCurseurX = x;
posCurseurY=y;
System.out.println("X: "+posCurseurX);
System.out.println("Y: "+posCurseurY);
return true;
}//FIN MOUSE MOVED
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
if(button == Buttons.LEFT){
squareImage = new Image(skin, "Square");
squareImage.setBounds(posCurseurX, (SCREEN_HEIGHT - posCurseurY), 32, 32);
stage.addActor(squareImage);
}
return true;
}//FIN TOUCHDOWN
});//FIN INPUT CONTROLLER
}//FIN RENDER
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resize(int arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
} |
Partager