Hi there!
I am trying to implement some sprite functionality into my project and need some help with that. (the VirtualButtons sample is what I am currently working on, however this should not be of much relevance here)
I have some markers with each marker being augmented by a 2D plane object - merely a texture (as png - utilizing the alpha channel).
Now what I am trying to do is to animate this texture. I was looking into various ways of doing this and came to the conclusion that sprites might be a solid choice for my purpose.
Imagine this to be the frames of a texture:
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12
I want to start the texture with frame 1 when focusing the corresponding tracker. After an interaction (e.g. swipe on the smartphone's screen) i want to animate from this first frame until let's say frame 8. then, after another interaciton (maybe double-tap) the remaining frames should be following.
I have my png files with each containing the sprites for one tracker. now when the interaction was/is executed, I want to update the focused marker's corresponding texture as mentioned before. my question is now, how to achieve this the most efficient way?
What I am doing is:
When first initializing, I loadTextureFromAPK by refering to the whole sprite.png and retrieving bitmap data from the desired section of this bitmap. Now when the interaction was executed, I remove the entry of the mTextures Vector and add a new one with the desirect section of the bitmap to the same location of this Vector. At this point I also need to update the .cpp file. This is the first point I got stuck - how do I update this single texture in the cpp file - could you provide a short code snippet for this purpose? I initialized a native method in the .java to be called in the c++ code passing the index of the now changed texture entry of the mTextures Vector.
I understand large textures to be causing an outofmemory error - how could I prevent this to happen in my case, since the sprite files will probably be more or less large pngs? How do i completely remove the old texture to clean up the memory for the next texture?
Is there another way of achieving this - keeping in mind that I don't want a simple texture animation to run in an infinite loop but need to stop the animation in a certain frame and continue it from that point later on?
Any additional information that might be helpful?