What to do when an imagesheet is too wide? - android

I'm trying to develop for Android, using Lua and Corona Simulator. The maximum image size that Android accepts is 2048x2048 pixels. I currently have an imagesheet that's 148 pixels high and 4690 pixels wide. The sheet consists of 35 images on a single line. Is there a way I can break this imagesheet up in multiple lines of frames and still use the Simple animation method listed here (http://docs.coronalabs.com/api/library/graphics/newImageSheet.html) rather than the complex one, or do I really have to declare each frame individually?
I have tried scaling the image down to a width of 1995 pixels, and then scaling it back up inside the program, but this (obviously) resulted in terrible resolution. I also tried (although this was with another image that presented the same issue) breaking the image up into two lines, so it was twice as high and half as wide, but I couldn't get this to work with the Simple method in Corona I mentioned above. The Complex method seems like a last resort, because it's a ton of work and code declaring each frame in the imagesheet individually by x, y, width and height.

The sequence navigates your texture image from left to right, top to bottom. So use a 5x7 grid of sub-images (5 rows, 7 columns, instead of 1 row, 35 columns), sequenced in this manner. Your image would then be 740 x 938.
Alternately, you could have multiple image sheets and switch between them as required.

Related

Is it useful to divide a vector xml background into m*n childview small background? (Android)

I am new to android, some people says that don't use a large size png to be a background of some rpg game. They prefer to use small pixie drawable to make up a rpg game in 15-20 years ago.
However, svg path seems to be different.
I want to ask if I have a 1080(W)*2133(H) mobile phone,
If I have some paths to be drawn on canvas, like a clock with some details and text inside.
Is there any advantage to use clipRect with Rect size = w/m * h/n,
with the same paths didn't simplified for each smaller view.
e.g.
I want to draw a background like this
[A B]
[C D]
I divide the view into 4 smaller views [A] [B] [C] [D] and use clipRect to draw.
However, some paths, say path1, path2 ,path3 ,path4 ,path5 ,path6 will pass through more than 1 view of views A,B,C,D for each path. so I need to use the command drawPath for all these paths in each view.
Question 1:
I think although I divide the large view into these 4 smaller views,
I make the work harder and do m*n-1 more extra works=.=
Question 2:
Is it useful (e.g. save memory or CPU?) if I divide the view into 10 x 10 smaller views while I have a view of size [w/30,h/30] with animation moving over these views?

loading an image, is the width/height pixel count maintained

I have read all about supporting different screens and I understand the concept of Density Pixels (DP). However one thing I am not sure about. Lets say I have an image file which is 200 by 200 pixels and I loaded it using xml with wrap_content attributes at the top left of the screen (0,0). Now let's say I want to place a textview programmatically beside it.
If I put the text view at coordinates (250,0). Does that mean that the text view will never overlap the image and will always be to the right no matter what the device density/screen size is.
I understand the distance ( gap) will be different but I am hoping my theory of not overlapping will hold.
I tried it on 2 device and no issues but I am not sure if this is coincendence
Thanks
If you are using px unit it will always remain the same. But if you are using dp unit instead of pixel you cannot definitely be sure.
By the way you should use toRightOf property instead of this approach if you only want this.

Is there any way to ignore libgdx images Limitation? (images must be power of two)

In libgdx framework we can only use images power of two (64x256, 128x32, etc) Because OpenGL requires it.
Is there any good way to "pass" this limitation? For example: Use images 800x480.
Do set Texture.setEnforcePotImages(false); and you do not have the limitation anymore. So it's not true that you just can use pictures with the size power of two. It's just a "can have" not a "must have".
Regards
You can use non pot textures, e.g. by using opengl es2.0. But it is good practice to at least try to use pot textures. For example by packing multiple images into a single texture. This also reduces the amount of texture switches. See: http://code.google.com/p/libgdx/wiki/TexturePacker.
Do this before loading the image:
GLTexture.setEnforcePotImages(false);
This will ignore the power 2 check.
The Best practice is to not to use your images directly. Instead use TexturePacker tool avalilable in LibGdx nightlies to generate Image Atlas. To know more :- https://github.com/libgdx/libgdx/wiki/Texture-packer
For some textures you can just make it a power of two.
For a background of 800 X 480 you can just make it 1024 x 512 by adding transparent space to the top and to the right. Then when drawing the texture just simply place in on the origin. (The left hand corner) One thing to note is that this technique causes resulting files to end up a tad larger.
Before resizing (800 X 480)
After resizing (1024 x 512)
This, of course, can be easily done in GIMP. Go to Image -> Canvas Size. Then enter the desired width and height. Gimp will place the image in the left upper corner of the transparent space, but we want it in the lower left corner. To move it simply enter the highest Y offset. (You can enter too larger of a number and Gimp will correct it)
use open gl2.0 for removing this limitation

Drawable resource file max dimension

I've created a single sprite sheet for my game app, with each frame 100x100 px.
Everything's been working well until after I added a few more rows to the sprite sheet, then suddenly nothing gets drawn onto the screen any more. I reverted the sprite sheet back to an earlier version, which had less rows, and everything works again.
The sprite that works is 400w*900h px, and the one that stopped working is 400w*1400h px... I suppose there's a middle ground somewhere I just haven't bothered to look for it.
My question is what is there a dimension limitation on the resource image files? And is there another way to get around what I just descripted other than splitting it into different files?
Thanks in advance
edit: getMaximumBitmapHeight() helped a little: On my testing device (nexus galaxy) it's only 2000 something... And on the emulator is in the 30k range :S Is there a way to set the allowed size? And if anyone knows... how different is it from phone to phone
The Canvas class has a method getMaximumBitmapHeight() (& width , naturally ) to give you this information for a given device, you can just print it in a log message.
On possible work-around is adding columns. Your image is only 400px wide but 1400 in height. It could be that 1400 is too wide but I very much doubt 400px is too wide.

Android sprite moves when it is supposed to be stationary

I created a sprite that is 18 frames long and it is supposed to be stationary and run through the frames and loop the animation, but when it runs it moves slowly across the screen as it animates until it hits the last frame then jerks back to the original position where it was suppose to stay at.
I don't know the reason it does this and have tried to make it smaller sizes and larger sizes, at some sizes it does not move but just animates likes its supposed to do.
If anyone has an answer to why this happens and how to stop it from moving and stay where it is supposed to be it would be greatly appreciated.
I use only 1 row for the sprite and I used gimp to create the sprite and saved it as a png.
The code is rather long thats why I didn't add it but it based on this tutorial
aquarium live wallpaper tutorial
I think I found my answer though, I had the png sprite in a folder I created named drawable, where I put all the images, I tried it again but put the sprite in the other folders this time and it didn't move, I tried scaling the sprite also which made it go a bit wonky, I was hoping on using scaling instead so it stayed the same size for all screens, this works for normal images but for sprites it causes some issues, maybe I'll try that with the largest size in the drawable-large-mdpi folder and see if it causes any issues that way.
I'll update with that method and let you know.
It would be nice to have just one image and scale it instead according to screen size.
Okay I found the answer finally and it might help those creating sprites,the width when divided into the amount frames has to be a whole number since the measurements are in int not float or double, so it moves because when the frame gets divided it came out to a fraction instead which caused it to moves (I guess) whatever that float extra measurement was.
Example: if the sprite was 100 pixels high and 1082 px wide and I had 15 frames the width of each frame would then be 72.133333333px wide for each frame causing an error that would move the image that extra length while keeping the animation looking nice. now if it was 1080px wide each frame would then be 72px wide a nice whole number and then would animate perfectly.
So for those creating there own sprites make sure the wide equals out to be a whole number when the frames get divided (My problem was I was creating one image scaling it down and not checking the width of each frame so only one image size usually work, sometimes I got lucky and got two, I should of figured this out because it all runs in int not float for measuring the width.
Hope this helps out someone else making sprites.
Sam

Categories

Resources