graphics - Scaling textures in libgdx on resizing -
i set texture resize gdx.graphics.getwidth()
, gdx.graphics.getheight()
every time render function calls. in fact when launch app, texture sets full screen (as want). when change size of app, texture draws in dumb way, while want full screen time.
here code:
package com.leopikinc.bobdestroyer; import com.badlogic.gdx.applicationadapter; import com.badlogic.gdx.gdx; import com.badlogic.gdx.audio.music; import com.badlogic.gdx.graphics.gl20; import com.badlogic.gdx.graphics.texture; import com.badlogic.gdx.graphics.g2d.spritebatch; public class bobdestroyer extends applicationadapter { spritebatch batch; texture mainscreen; music intromusic; float volume; @override public void create () { volume = 1f; batch = new spritebatch(); mainscreen = new texture(gdx.files.internal("data/firstlevel.png")); intromusic = gdx.audio.newmusic(gdx.files.internal("data/intromusic.mp3")); intromusic.setlooping(true); intromusic.setvolume(volume); intromusic.play(); } @override public void render () { gdx.gl.glclearcolor(1, 1, 1, 0); gdx.gl.glclear(gl20.gl_color_buffer_bit); batch.begin(); batch.draw(mainscreen, 0, 0, gdx.graphics.getwidth(), gdx.graphics.getheight()); batch.end(); } @override public void resize(int width, int height){ } }
you should use viewport deal different aspect ratios.
here example of stretchviewport
can display fullscreen texture.
public class mygdxgame extends applicationadapter { spritebatch batch; texture img; private viewport viewport; private camera camera; @override public void create() { camera = new orthographiccamera(); viewport = new stretchviewport(gdx.graphics.getwidth(), gdx.graphics.getheight()); viewport.setcamera(camera); batch = new spritebatch(); img = new texture("badlogic.jpg"); } @override public void render() { camera.update(); gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); batch.begin(); batch.draw(img, 0, 0, viewport.getworldwidth(),viewport.getworldheight()); batch.end(); } @override public void resize(int width, int height) { viewport.update(width, height); } }
before changing screen sizes :
after changing screen sizes:
Comments
Post a Comment