I was thinking about how best to create sprites. I tried two methods (a) creating a local mesh on the fly and assigning it different texture coordinates as the sprite animates. clear the mesh after drawn. (b) pre-load all the frames in an array of mesh. I thought (a) would use up less memory as the mesh is generated on the fly, while (b) stores a huge amount of data (if you have lots of sprites) in the memory but might be faster run-time.
(a) actually crashes codea after 1000+ cycles, even with collectgarbage() and using only local meshes. It works fine on the ios simulator in xcode and in iphone/ipad. This leads me to think that there’s something about the mesh() in codea that has a memory leak and is causing codea to crash.
As expected, (b) has a small initial load time but runs slightly faster in run time.
@zapaper try using xCode to observe memory usage, I’m pretty sure the runtime for Codea and the runtime for xCode are designed to be exactly the same, literally identical so it may not crash on your iOS simulator because of the higher amount of memory on the mac compared to the iPad.
Also as Coder said make one mesh one time at the start or when needed and then just modify the mesh, takes up far less memory than it does to create a mesh every time.
Using a mesh single mesh and using Mesh:setRect and Mesh:setRecTex to change the position and texture works great. as long as you dont want to rotate the rectangels.
Ok Luatee is right: you have to create meshes on the start and only modify coords etc later. But if you need to recover memory, is there a possibility to remove meshes from memory?
wow, this is some time ago; not sure if I still hv the code that tested the two options. Essentially, say I have a spritesheet for NPC/monsters. I could pre-load all the meshes (method b), or change the texcoord/file each time I draw (method a). Method A will crash codea after awhile, but seemed to run alright on simulator.