Skip to content Skip to sidebar Skip to footer

Sprite Not On Position

my sprites are not on position on diffrent screen sizes. What i have to do? My headline actor looks like: package actors; public class Headline extends Actor{ public static fina

Solution 1:

Use viewport for your requirement, I supposed APP_WIDTH and APP_HEIGHT is constant.

publicclassMenuScreenimplementsScreen {

  publicMenuScreen(Main game) {
     ViewPort viewPort=new ExtendViewport(Constants.APP_WIDTH,Constants.APP_HEIGHT);
     this.stage = new Stage(viewPort);
     this.game = game;
     this.sb = game.sb;
     setHeadline();
  }

  privatevoidsetHeadline() {
     atlas = new TextureAtlas(Gdx.files.internal(Constants.HEADLINES_IMAGE_ATLAS_PATH));
     stage.addActor(new Headline(atlas.findRegion(Constants.MENUHEADLINE_REGION_NAMES)));
  }

  @Override
  publicvoidresize(int width, int height) {
    stage.getViewport().update(width,height);
  }
}

HeadLine is an Actor having TextureRegion, why not you use Image for your requirement, if you want some extra property then extend your HeadLine with Image class.

Image image=newImage(newTexture("badlogic.jpg"));
image.setPosition(100,100);   // positon fit for all device screen.
stage.addActor(image);

EDIT

publicclassHeadlineextendsImage {

   publicHeadline(TextureRegion textureRegion) {
       super(textureRegion);
   }
}

And In setHeadline() method of MenuScreen

stage.addActor(newHeadline(atlas.findRegion(Constants.MENUHEADLINE_REGION_NAMES)));

Post a Comment for "Sprite Not On Position"