Sunday, 15 June 2014

android - Need help for adding button in menu screen using LIBGDX -



android - Need help for adding button in menu screen using LIBGDX -

i having 3 different screens contains splash screen, after menu screen , game screen. splash > menu > gamestarts.

how can add together image button ??

i want implement 3 buttons within menu screen, not getting thought start.

public class menuscreen implements screen { private spacegame game; private spritebatch batch; private sprite sprite; private texture texture; textureregion bg,play,spacegamelogo,button; orthographiccamera camera; vector3 touchpoint; private skin buttonskin; public menuscreen(spacegame game) { touchpoint = new vector3(); this.game=game; batch=new spritebatch(); bg=assetloader.bg; spacedebrislogo=assetloader.spacedebrislogo; button=assetloader.button; } @override public void show() { float w = gdx.graphics.getwidth(); float h = gdx.graphics.getheight(); photographic camera = new orthographiccamera(1, h / w); sprite = new sprite(bg); sprite.flip(false, true); sprite.setsize(1.0f, 1.0f * sprite.getheight() / sprite.getwidth() ); sprite.setorigin(sprite.getwidth() / 2, sprite.getheight() / 2); sprite.setposition(-sprite.getwidth() / 2, -sprite.getheight() / 2); } @override public void render(float delta) { batch.setprojectionmatrix(camera.combined); batch.begin(); sprite.draw(batch); batch.draw(spacedebrislogo, 33, 54, 50, 40); batch.end(); if (gdx.input.istouched()) { game.setscreen(new gamescreen()); dispose(); } }

there lot of methods it.. tell way do. first create button image, add together assets folder , load texture region. create sprite out of it.

sprite button1=new sprite(mytextureregion);

to check if button touched can utilize rectangle sprite check if touched image. in touchup method like

if(button1.getboundingrectangle.contains(screenx,screeny)) // thing

to create game more interesting add together rotation or scaling of sprite when clicked, looks better, can play it, or can create 2 textures, 1 touched downwards , 1 touched up.

android libgdx

No comments:

Post a Comment