Disappearing ChangeableText - android

I have a problem. When i create a changeable text then some letters disappears. I tried with sever fonts and it's not changing!
Piece of code:
FONT:
FontFactory.setAssetBasePath("font/");
this.mFontTexture = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
And the changeabletext:
ChangeableText ty = new ChangeableText(20, CAMERA_HEIGHT / 2 - 80, mFont, "Game over!");
this.mScene.attachChild(ty);

I had it when the BitmapTextureAtlas was too small. Try making it larger (Maybe 512x512), it also depends on the font size.

Related

Issue with using filters with libgdx, mipmapping specifically

I am currently running into issues right now when I render my background image for my app. It has jagged edges in it as you can see:
http://imgur.com/a/doqvI
Now, here is the code which I am using to load the image in, and I have tried all possible combinations of the filtering so this is not the only one I have tried.
newPenguinGraphic = new Texture(Gdx.files.internal("data/1024Set1.png"),true);
texture.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Nearest);
Screen setup:
float gameWidth = 330;
float gameHeight = screenHeight / (screenWidth / gameWidth);
int midPointY = (int) (gameHeight / 2);
Cam:
cam = new OrthographicCamera();
cam.setToOrtho(true, 330, gameHeight);
Graphic:
MainBackground = new BGScroller(0, yPos-165, 330, 220, SCROLL_SPEED, yPos);
The size of the original image is 688x459 also btw.
A question I have been wondering, do I need to generate the mipmap png files before and load them in manually or does libgdx literally create them at runtime? Please help, and thanks!!

LibGDX 9 Patch Images aren't working with TextButtonStyle and TextureAtlas

I am attempting to create a simple game using LibGDX. I am trying to use 9 Patch images as the backgrounds to the buttons on the menu however it appears the 9 Patch qualities of the images are being ignored.
I have two images, "active.9.png" and "rest.9.png". These are square images that represent the button in it's active or rest state. I used this tool to create them: http://romannurik.github.io/AndroidAssetStudio/nine-patches.html so I am sure they meet 9 Patch requirements. Below is a picture of "active.9.png":
Because I am using LibGDX and there will be many assets I wanted to use a TextureAtlas to store my button images. After running the TexturePacker things still seem to be working, because the images have "split" defined which I think suggests they have been recognised as 9 Patch files. Below is "buttons.pack":
buttons.png
format: RGBA8888
filter: Nearest,Nearest
repeat: none
active
rotate: false
xy: 1, 1
size: 226, 225
split: 59, 57, 58, 58
orig: 226, 225
offset: 0, 0
index: -1
rest
rotate: false
xy: 229, 1
size: 226, 225
split: 59, 57, 58, 58
orig: 226, 225
offset: 0, 0
index: -1
Next I tried to create a TextureAtlas from this pack, create a Skin, and load the images into the Skin.
TextureAtlas buttonAtlas = new TextureAtlas("images/buttons/buttons.pack");
skin = new Skin();
skin.addRegions(buttonAtlas);
skin.add("rest", buttonAtlas.createPatch("rest"));
skin.add("active", buttonAtlas.createPatch("active"));
Finally I tried to apply this Skin to the button. I have tried two different ways..
Method 1:
TextButtonStyle buttonStyle = new TextButtonStyle();
buttonStyle.up = new NinePatchDrawable(buttonAtlas.createPatch("rest"));
buttonStyle.down = new NinePatchDrawable(buttonAtlas.createPatch("active"));
Output 1:
Method 2:
TextButtonStyle buttonStyle = new TextButtonStyle();
buttonStyle.up = new NinePatchDrawable(new NinePatch(new Texture(Gdx.files.internal("images/buttons/rest.9.png"))));
buttonStyle.down = new NinePatchDrawable(new NinePatch(new Texture(Gdx.files.internal("images/buttons/active.9.png"))));
Output 2:
Whilst output 2 looks like it is better, it actually seems as though the 9 Patch qualities are ignored and the image has been simply stretched to fit.
I would really appreciate any help with this, I am completely stumped and there doesn't seem to be any up to date tutorials or documentation available.
Thanks for your time
I think one of the mistakes is the image line.
I use draw9patch, I do not know if it is the tool you use, do not know.
this tool can be found at: yourAndroid-sdk/tools/-->draw9patch
"lookVertical Path" for example:
//variable Class:
private TextureAtlas buttonsAtlas;
private NinePatch buttonUpNine;
private TextButtonStyle textButtonStyle;
private TextButton textButton;
private BitmapFont font;
//add in Show or created for example:
buttonsAtlas = new TextureAtlas("data/ninePatch9/atlasUiScreenOverflow.atlas");
buttonUpNine = buttonsAtlas.createPatch("buttonUp");
font = new BitmapFont(); //** default font, for test**//
font.setColor(0, 0, 1, 1); //** blue font **//
font.setScale(2); //** 2 times size **//
textButtonStyle = new TextButtonStyle();
textButtonStyle.up = new NinePatchDrawable(buttonUpNine);
textButtonStyle.font = font;
textButton = new TextButton("test", textButtonStyle);
textButton.setBounds(100, 250, 250, 250);
add in stage for example:
yourStage.addActor(textButton);
//
eg: if your button is greater than or equal to the side of ninePath, looks like this: (sorry for my English Hope you understand me well)
textButton.setBounds(100, 250, 250, 250);
look good.
but if it is less than nine line for example 100 look this:
textButton.setBounds(100, 150, 250, 100);
asset for you used for test if you need:
//atlasUiScreenOverflow.atlas
atlasUiScreenOverflow.png
size: 232,231
format: RGBA8888
filter: Nearest,Nearest
repeat: none
buttonUp
rotate: false
xy: 2, 2
size: 230, 229
split: 49, 51, 49, 52
orig: 230, 229
offset: 0, 0
index: -1
//atlasUiScreenOverflow.png
there are several ways to use ninePatch, but this is the one that occurred to me right now for this case I hope, well understood, and to help you something.
Edit: I just tested the tool you use and works well.
You use textButton = new TextButton("test", textButtonStyle); ?

AndEngine:why those sprites get distorted?

I am facing 2 problems.
Questions are listed in picture above.
And main code snippets like this:
My device has a 1024x600 resolution.
Engine:
this.mCamera = new Camera(0, 0,*device'width*,*device'height*);
final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), this.mCamera);
engineOptions.getTouchOptions().setNeedsMultiTouch(true);
Background:
BitmapTextureAtlas bta = new BitmapTextureAtlas(mGame.getTextureManager(),WIDTH_SCENE_PNG,HEIGHT_SCENE_PNG, TextureOptions.BILINEAR);
ITextureRegion it = BitmapTextureAtlasTextureRegionFactory.createFromResource(bta, mGame, R.drawable.bg_main, 0, 0);
bta.load();
final Sprite sprite = new Sprite(0, 0,*device'width*,*device'height*,it, mGame.getVertexBufferObjectManager());
SpriteBackground bg = new SpriteBackground(sprite);
bg.setColor(Color.PINK);
setBackground(bg);
Sprites:
BitmapTextureAtlas btaTools = new BitmapTextureAtlas(mGame.getTextureManager(), 30, 40);
ITextureRegion itDelete = BitmapTextureAtlasTextureRegionFactory.createFromResource(btaTools, c, R.drawable.sprite_delete,0,0);
btaTools.load();
The distortions could come from the TextureOptions. For the TextureAtlas of your background sprite you use the TextureOptions.BILINEAR. The TextureAtlas of your tools however don't use any options. I guess they have transparent areas? When you use transparent sprites try TextureOptions.NEAREST_PREMULTIPLYALPHA or TextureOptions.BLINEAR_PREMULTIPLYALPHA. I for one use TextureOptions.NEAREST and it works fine for me (even with transparency). Try out some of the options maybe the distortions go away.
The size of your background: for the TextureAtlas bta you already use those constants WIDTH_SCENE_PNG and HEIGHT_SCENE_PNG, why don't you use them for the size of you sprite as well? Anyway, my guess is, that your camera has a different size. For a fullscreen image try:
final Sprite sprite = new Sprite(0, 0,mEngine.getCamera().getWidth(),mEngine.getCamera().getHeight(),it, mGame.getVertexBufferObjectManager());
Christoph
I fixed my problem.
The point is that I moved my resources(png images) from project's drawable-hdpi folder to drawable foler, sprites look nice then.
raw or asset folders are also OK.
Your answer is also helpful for me.Thank you! #Christoph

How to use two BitmapTextureAtlases in AndEngine?

I have to work with big textures in my project so I can't put all the textures into the one BitmapTextureAtlas. I tried to put them into two atlases:
textureAtlas = new BitmapTextureAtlas(2048, 2048, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
textureAtlas2 = new BitmapTextureAtlas(1024, 2048, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
foo = BitmapTextureAtlasTextureRegionFactory.createFromAsset(textureAtlas ,this,"foo.png",0,0);
bar = BitmapTextureAtlasTextureRegionFactory.createFromAsset(textureAtlas2,this,"bar.png",0,0);
But when I try to use bar
Sprite sBar = new Sprite(0,0,bar);
scene.attachChild(sBar);
the only thing I can see is the white rectangle instead of my image. And I have no idea what is wrong here.
OK, I got it. I just forgot about this:
getEngine().getTextureManager().loadTexture(textureAtlas2);

AndEngine getting error: Supplied pTextureAtlasSource must not exceed bounds of Texture

im new to android gaming and started andengine and facing problem while using createTiledFromAsset
the code where im getting problem is
#Override
public void onLoadResources() {
mBitmapTextureAtlas = new BitmapTextureAtlas(128, 128,
TextureOptions.BILINEAR);
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory
.createTiledFromAsset(this.mBitmapTextureAtlas, this,
"move.png", 0, 0, 10, 1);
mEngine.getTextureManager().loadTexture(mBitmapTextureAtlas);
}
#Override
public Scene onLoadScene() {
mEngine.registerUpdateHandler(new FPSLogger());
mMainScene = new Scene();
mMainScene
.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
player = new AnimatedSprite(0, 0, mPlayerTextureRegion);
mMainScene.attachChild(player);
return mMainScene;
}
im not getting the error as my BitmapTextureAtlas is of 128*128 and each tiled part coming from createTiledFromAsset should be of 78*85 as the passed arguments to it are 1 row and 10 columns and my source image is of 779*85 which means when the width is tiled to 10 parts then 779/10=78 approx which will be width of each tiled part and as row is 1 so 85/1=85 hence the width*height of each tiled part which is to be placed on the BitmapTextureAtlas is 78*85 and the BitmapTextureAtlas itself has size 128*128 then why the error saying Supplied pTextureAtlasSource must not exceed bounds of Texture
what is happening here ...? or im not understanding the actual functions ...? if im wrong then how the process of createTiledFromAsset is working........?
I found the same problem too. I am using a large sprite sheet, and try to use it. after searching, I found some clue in this tutorial: getting-started-working-with-images and i realize that the value of width and height used in:
BitmapTextureAtlas(WIDTH, HEIGHT ,TextureOptions.BILINEAR);
must be higher than the image size. for example if I use 1200*100 sprite sheet, I must use the width and height higher than 1200*100.
BitmapTextureAtlas(2047, 128, TextureOptions.BILINEAR);
If I understand BitmapTextureAtlas correctly, you are trying to put 779*85 image into the small space of 128*128. TextureAtlas is a large canvas on which you are supposed to place many images. These images are later accessed using object called TextureRegion, which basically specifies the size and coordinates of the smaller picture on the canvas. The method createTiledFromAsset probably copies the original image 1:1 onto the TextureAtlas and saves the coordinates of the tiles.
Please note that TextureRegion has nothing to do with the image itself, it is merely a "pointer" to the place on TextureAtlas where the image is stored.
To get the idea of what a TextureAtlas actually is, look at the awesome pictures at the bottom of this page:
http://www.blackpawn.com/texts/lightmaps/default.html

Categories

Resources