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); ?
Related
I've tflite model which has input shape: (5,128,256,3) and have 3 classes.
*note: First dimension 5 is not batch size. If batch size is considered then it is (None, 5, 128, 256, 3)
So now to test my model in android I want to feed it with 5 images.
So first I've created ByteBuffer and allocated sufficient storage and later converted it to FloatBuffer.
val imageBuffer = ByteBuffer.allocateDirect(5 * 256 * 128 * 3 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer()
I've read images, done all the necessary preprocessing and used put method of FloatBuffer to store it into imageBuffer.
Now when trying to run interpreter.run(imageBuffer, output) I'm getting error as shown below:
tensorflow/lite/kernels/unpack.cc:67 data->num != input_shape->data[axis] (5 != 128)
So I have solved the problem with simple resizing of the interpreter from
interpreter.resize(5, 128, 256, 3) -> interpreter.resize(1, 5, 128, 256, 3)
So that now data->num = input_shape->data[axis] which are
5 respectively.
I'm currently trying to create a website that contains a WebGL canvas. Everything worked fine and I got my plane rendered, but when I opened my website on my samsung galaxy SIII mini, the planes origin point seems to be different
You can check the website at http://portfolio.kamidesigns.be
The canvas is located under thesis -> Occluder simplification using planar sections
Here are some images to show what's wrong.
Desktop
Cellphone
The plane on my cellphone is located on the top right corner although the positions of the vertices of the plane are
var positions = new Float32Array([-0.5, 0.5, 0,
-0.5, -0.5, 0,
0.5, 0.5, 0,
0.5, -0.5, 0]);
If someone can help me, it would be very much appreciated.
You have a bunch of typos in your code which prevent vertex array object from being created properly. This leads to "default values" being fed through the vertex pipeline resulting in different behavior on different browsers.
Firstly, change your VAO initialization to this ( you missed var vao initialization):
function createVAO()
{
var vao = gl.extOESVertexArrayObject.createVertexArrayOES();
gl.extOESVertexArrayObject.bindVertexArrayOES(vao);
return vao;
}
Secondly, in your storeDataInAttributeList calls you need to supply the result of gl.getAttribLocation for attributeNumber. This is a good thing to do to make your code stay correct if you modify the shader.
storeDataInAttributeList(program.aPosition, 3, positions);
storeDataInAttributeList(program.aTextureCoords, 2, textureCoords);
storeDataInAttributeList(program.aNormals, 3, normals);
And lastly, in your shader the inNormal attrib is not used which results in gl.getAttribLocation(program, "inNormal"); returning -1
You may want to safe-guard your storeDataInAttributeList against such cases like this:
function storeDataInAttributeList(attributeNumber, coordinateSize, data)
{
if( attributeNumber >= 0 )
{
vbo = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
gl.enableVertexAttribArray(attributeNumber);
gl.vertexAttribPointer(attributeNumber, coordinateSize, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, null);
}
}
After making these 3 changes your page started displaying the same results on android/pc browser.
My final advice would be to avoid using OES_vertex_array_object extensions as e.g. my stock browser on Samsung Galaxy Tab 2 doesn't support it ( not that old a device ).
Sorry if this problem was asked before. I have searched around but I didn't find any thread about this, So I post the question here.
I am really new on Andengine. I am trying to load a Tiled Sprite and create an animation with it.
Here are my codes:
public void loadGameResources() {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/player/");
mSapoTextureAtlas = new BitmapTextureAtlas(mActivity.getTextureManager(),256,178,TextureOptions.DEFAULT);
mPlayerDownITiledTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mPlayerTextureAtlas, mActivity.getAssets(), "player.png", 0,0,3,1);
mPlayerTextureAtlas.load();
}
What I expect is that the player can do some actions like walking but I don't. Please see the attached screenshots to see the real result. I think that my codes split the original texture into 3 parts rather than just split 3 sprites at first row.
Please take a look and help me to fix this. Thanks a lot!
And here is how I create the animation:
AnimatedSprite player= new AnimatedSprite(100,100,40,40,mResourceManager.mPlayerDownITiledTextureRegion,mVertexBufferObjectManager);
player.animate(500);
player.setZIndex(100);
attachChild(sapo);
What I understood is that you want to animate the player in each direction properly. For that
According to library method
BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(pBitmapTextureAtlas, pAssetManager, pAssetPath, pTextureX, pTextureY, pTileColumns, pTileRows);
Your code will change as below
mSapoTextureAtlas = new BitmapTextureAtlas(mActivity.getTextureManager(),256,256,TextureOptions.DEFAULT);
mPlayerDownITiledTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mPlayerTextureAtlas, mActivity.getAssets(), "player.png", 0,0,3,4);
To animate player in different directions use this technique
define an array as
long[] ANIMATE_DURATION = new long[] { 200, 200, 200 };
AnimatedSprite player = new AnimatedSprite(x, y, this.mPlayerTextureRegion,this.getVertexBufferObjectManager());
// Down
player.animate(ANIMATE_DURATION, 0, 2, true);
// Up
player.animate(ANIMATE_DURATION, 9, 11, true);
// Right
player.animate(ANIMATE_DURATION, 6, 8, true);
// Left
player.animate(ANIMATE_DURATION, 3, 5, true);
look this Example for more information.
If you have doubt ask me. Hope this helped!
First: Atlas should be in power of two so change it size to 256x256.
Second:
mPlayerDownITiledTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mPlayerTextureAtlas, mActivity.getAssets(), "player.png", 0,0,3,1);
Last two digits say how many rows and columns you have. You declared 3 columns and 1 row.
Three: Zindex at 100 is needed only if you have so many layers. If not you dont need it.
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.
I've searched the web for help and although it looked like a solution it turned out to not work so good. For starters I'd like to say I've just jumped into android programming (this is my first day) I really learn by trial and error I'd like it that if you could help me you'd give me hints rather than paste the code in front of me.
my tileset
http://img217.imageshack.us/img217/4654/tileseth.png
the result
http://img199.imageshack.us/img199/7913/resultx.png
the issues I'm having is 1. it is obviously not splitting the image in 32 by 32 bits. is what I'm trying to achieve is take my big image and split it into 9* smaller images of 32 by 32 portions. Secondary the image quality gets distorted and I can't work out why.
*I don't want to use a 9 patch as there will be more then 9 images soon just a fluke that atm I have 9 images
my code (evidently plagiarized from the internet)
tilesetSliced = Bitmap.createScaledBitmap(bmp, 96, 96, true);
tileset[0] = Bitmap.createBitmap(tilesetSliced, 0, 0, 32, 32);
tileset[1] = Bitmap.createBitmap(tilesetSliced, 32, 0, 32, 32);
tileset[2] = Bitmap.createBitmap(tilesetSliced, 64, 0, 32, 32);
tileset[3] = Bitmap.createBitmap(tilesetSliced, 0, 32, 32, 32);
tileset[4] = Bitmap.createBitmap(tilesetSliced, 32, 32, 32, 32);
tileset[5] = Bitmap.createBitmap(tilesetSliced, 64, 32, 32, 32);
I'll make it more efficent once I got it working >.< any help would be great
the on draw
public void onDraw(Canvas canvas) {
//update();
for(int x=0; x<= mapWidth; x++){
for(int y = 0; y <= mapHeight; y++){
canvas.drawBitmap(tileset[map[x][y]], x *32, y*32, null);
}
}
}
o.k some more debugging has shead light on something 1. I removed the scaledbitmap that stopped the quality being destroyed (orginally ahd it due to bugs) however I found out that for some reason it thinks the width of my tileset is 64 when its 96 any help would be nice on this.
You may have more luck with a Bitmap Factory to generate your tilesetSliced. Within it is an Options class that allows you to set the sample size (inSampleSize) which can be used to scale down your image. It may not be precise enough for your needs, however.
Your images are likely distorted due to the scaling down process. Are you able to create these images with the right dimensions or pre-scale them?