It crashes because of these lines in Process_Globals:Attached is the wallpaper that I am trying to build (this is a random animation), it crashes after it starts, I am not sure why... Plz help :-(
Dim minscreen As Int = Min(LW.Graphics.Height, LW.Graphics.width)
Dim SH As Int = LW.Graphics.Height
Dim SW As Int = LW.Graphics.width
Using the Animation class is just a convenient way of animating things. It does not offer better performance.Thank you andymc, I really appreciate you sharing this. Your source code was very helpful not just as an animation example.
So if I understand this correctly, instead of using an animation you are animating each frame using draw. This seems very straight forward and easy to implement, but is it more efficient than using an atlas + animation?
As you say in the comments at the end, there are memory leaks because of the number of resources not disposed of. To avoid bothering with the numerous dispose() to call and to not miss one, you can use the AssetManager class. You load your resources when needed with MyAssetManager.Load and MyAssetManager.FinishLoading (to force their loading right now, and not wait for their loading in the background). To use a loaded resource, you call MyAssetManager.Get("myresource.ext") and, when the game ends, you clean up the memory with MyAssetManager.dispose.In my games I use textureregions to do my animation. You can download my source code here and take a look:
https://dl.dropboxusercontent.com/u/8673694/my games/Invaders-source.zip
The LW object is not initialized yet, so you cannot use it (and the Graphics class will be available only when the OpenGL surface is created, thus not before LG_Create). MinScreen, SH and SW should be set in the LG_Resize event.
Dim animregion As lgTextureRegion
animregion.InitializeWithTexture(texture)
Dim animsplit(,) As lgTextureRegion=animregion.Split(xsize,ysize)
Dim animframes (8) As lgTextureRegion '8 is the size of the one dimensional array, or number of frames
Dim index As Int = 0
For i=0 To 2-1 '2 is the number of columns in the sprite sheet (in yours its 1)
For j = 0 To 4-1 '4 is the number of rows in the sprite sheet (in yours its 4)
animframes(index)=animsplit(i,j) '2D to 1D
index=index+1
Next
Next
The flicker is due to the extra empty frames that you have in your image. The caveman example does not use a texture atlas, it just grabs equal frames from a spritesheet. Fred has another example called Textureatlas for texture atlas...
if you want to use this rather than an atlas i suggest you fix your spritesheet so that you don't have any empty frames. I don't use this texture packer software, but you probably have to learn more about how to use it and what you are getting out of it... For instance it looks like you have edge padding checked, and that's probably what's adding the extra space at the ends. Also, you have force POT checked, this will force the software to generate a texture that is a power of two, meaning the texture will be 2^n x 2^n regardless of the stuff your are adding.
The caveman method is simple to use in code, but you have to make sure that your spritesheet is flawless.
As far as the issue of the two dimensional array, you can transform it to a one dimensional array and extract any frame that you want from it. I use something like this:
B4X:Dim animregion As lgTextureRegion animregion.InitializeWithTexture(texture) Dim animsplit(,) As lgTextureRegion=animregion.Split(xsize,ysize) Dim animframes (8) As lgTextureRegion '8 is the size of the one dimensional array, or number of frames Dim index As Int = 0 For i=0 To 2-1 '2 is the number of columns in the sprite sheet (in yours its 1) For j = 0 To 4-1 '4 is the number of rows in the sprite sheet (in yours its 4) animframes(index)=animsplit(i,j) '2D to 1D index=index+1 Next Next
Hope this helps
Yup, the Texture Packer settings were definitely the issue. Thanks for the assist!
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?