java - LIBGDX how to add sprite from a texture atlas -
i need know how can add sprite texture atlas can implement sprite main menu.
here code main menu:
public class mainmenu implements screen { crazyzombies game; stage stage; textureatlas atlas; skin skin; spritebatch batch; textureregion firstlayer; textureregion secondlayer; textureregion thirdlayer; textureregion fourthlayer; textureregion fifthlayer; textureregion sixthlayer; textureregion seventhlayer; textureregion eighthlayer; textureregion ninthlayer; textureregion tenthlayer; textureregion eleventhlayer; public mainmenu(crazyzombies game){ this.game = game; } @override public void render(float delta) { gdx.gl.glclear(gl10.gl_color_buffer_bit); gdx.gl.glclearcolor(0.09f, 0.28f, 0.2f, 1); batch.begin(); batch.end(); } @override public void resize(int width, int height) { gdx.input.setinputprocessor(stage); } @override public void show() { batch = new spritebatch(); skin = new skin(); } @override public void hide() { dispose(); } @override public void pause() { } @override public void resume() { } @override public void dispose() { batch.dispose(); skin.dispose(); atlas.dispose(); stage.dispose(); } public void loadlayers() { textureatlas atlas = new textureatlas(gdx.files.internal("data/mainmenu/mainmenu.pack")); firstlayer = atlas.findregion("1layer"); } }
so need go getting firstlayer onto screen , every way have tried ended crash.
you not doing right. render method doesn't have draw. take @ superjumper demo in libgdx.
to answer on how create sprite-
sprite mysprite; ... ... mysprite = new sprite(sometextureregion); mysprite.setsize(some_width, some_height); mysprite.setorigin(some_width/2f, some_height/2f); mysprite.setposition(world.sprite.bounds.x, world.sprite.bounds.y); ... ... mysprite.draw(batch);
Comments
Post a Comment