Calm your boots John, this is exactly what I've done.
Single mesh, and only setVertex to move the squares. To be able to use easing I use MovieClip to do that part, but using a custom attribute for the tween so it uses setVertex instead. Code attached. Turns out GTween is faster that MovieClip in this case.
Just setting position is a lot faster, so it's likely GTweeen and MovieClip causing the slowdown. Maybe there is another way of using the easing library that is faster?
Edit: Just tested the same code on an iOS device, where it is slower than with many Shapes! To be continued...
I think you have to abandon MovieClip and GTween in this case. You cannot consider the individual squares as "objects", the entire mesh is an object.
Here is an update of the code above that shows a simple animation. It's like what you did originally but just linear interpolation. (If you want to use the inOutSine etc just look in the easing.lua file that comes with GTween.)
function rgb(r,g,b)returnmath.floor(r)*65536+math.floor(g)*256+math.floor(b)endlocal size=50local frame=0local xtarget={}local ytarget={}local mesh=Mesh.new()function update()if moving thenfor i=1,1000dolocal x=xtarget[i]*frame/200local y=ytarget[i]*frame/200local vstart=(i-1)*4
mesh:setVertex(vstart+1,x+0,y+0)
mesh:setVertex(vstart+2,x+size,y+0)
mesh:setVertex(vstart+3,x+size,y+size)
mesh:setVertex(vstart+4,x+0,y+size)end
frame=frame+1if(frame==200)then
moving=falseprint("finished moving")endendendfor i=1,1000dolocal vstart=(i-1)*4local istart=(i-1)*6
xtarget[i]=math.random(100)
ytarget[i]=math.random(100)local x,y=0,0
mesh:setVertex(vstart+1,x+0,y+0)
mesh:setVertex(vstart+2,x+size,y+0)
mesh:setVertex(vstart+3,x+size,y+size)
mesh:setVertex(vstart+4,x+0,y+size)local r =math.random(255)local g =math.random(255)local b =math.random(255)local a =math.random()local hexcol=rgb(r,g,b)
mesh:setColor(vstart+1,hexcol,a)
mesh:setColor(vstart+2,hexcol,a)
mesh:setColor(vstart+3,hexcol,a)
mesh:setColor(vstart+4,hexcol,a)
mesh:setIndex(istart+1,vstart+1)
mesh:setIndex(istart+2,vstart+2)
mesh:setIndex(istart+3,vstart+3)
mesh:setIndex(istart+4,vstart+1)
mesh:setIndex(istart+5,vstart+3)
mesh:setIndex(istart+6,vstart+4)end
stage:addChild(mesh)
mesh:setY(100)-- Mem and fpslocal sceneDebug = SceneDebug.new()
sceneDebug:addEventListener( Event.ENTER_FRAME, sceneDebug.update, sceneDebug )
stage:addChild( sceneDebug )
moving=true
stage:addEventListener(Event.ENTER_FRAME,update)
Note, no MovieClip or GTween and it runs at 60 FPS.
Wow, this is a lot faster. I think you're right; inheriting from Sprite and/or creating a GTween/MovieClip for each square seems to slow things down a lot. Thanks a lot!
And the same for other easings. You need to add easing.lua to your project. This assumes you want it to complete after 200 frames.
This amount of maths in Lua may slow things down again, in which case LuaJIT would be better since it compiles the Lua code. But I don't think you are actually using as many as 1000 squares in the real game...?
Some of the easing functions use math.sin etc and, as @SinisterSoft says, it may be better to replace this with a local sine function. At the top of easing.lua you can put
localsin=math.sin
etc and then just use "sin" instead of "math.sin". Might make a difference...
This trick speeds up EVERYTHING used more than once, not just methods. I localised all "self." variables and methods used more than once when moving the squares each frame and it increased fps by 5-10 (!). Genius.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
Back to the squares! With the 2016-06 release I've had the pleasure to revisit drawing squares, with the addition of Pixel and Particles. In my tests Pixel is marginally faster than Mesh (not much in it), but Particles is miles ahead of Mesh - on some devices.
I've used the same test as above, with 1,000 particles with a 64x64 Texture. For animation I've used the quite brilliant setParticleSpeed. The results:
iPad Mini Retina: 60 fps (in fact, I can add up to 3,000 particles without a slowdown) iPhone 5: 12fps iPod touch 5th generation: 4ps
On iPad Mini the squares look perfect and it runs fantastically. On iPhone5 and iPod touch, apart from the speed difference, the squares are jagged and appear to be leaning slightly. Any ideas why this could be?
It's early days for particles. I'm sure that @hgy29 will appreciate any feedback or ideas you may have.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
I personally think that adding a way to have a different texture x,y,w,h within the same 'master' texture would be a good idea.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
Yes, thanks for the feedback! Anthony discovered that particles rendering is not consistent across devices (GL_POINT primitive implementation is not that well defined), so to overcome this I'll have to change the way I am rendering them, possibly less efficiently...
@hgy29 I haven't installed the latest Gideros yet but how do a bunch of particles compare against a pool of sprites? I've found pooled sprites are terribly good.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
Yeah on the iPad Mini straight up particles just FLY. Since I'm partial to square particles, however, I have to use a texture which seems to slow things down a lot.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
Comments
Single mesh, and only setVertex to move the squares. To be able to use easing I use MovieClip to do that part, but using a custom attribute for the tween so it uses setVertex instead. Code attached. Turns out GTween is faster that MovieClip in this case.
Just setting position is a lot faster, so it's likely GTweeen and MovieClip causing the slowdown. Maybe there is another way of using the easing library that is faster?
Edit: Just tested the same code on an iOS device, where it is slower than with many Shapes! To be continued...
Here is an update of the code above that shows a simple animation. It's like what you did originally but just linear interpolation. (If you want to use the inOutSine etc just look in the easing.lua file that comes with GTween.)
Likes: totebo
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
Any idea how I would replace:
This amount of maths in Lua may slow things down again, in which case LuaJIT would be better since it compiles the Lua code. But I don't think you are actually using as many as 1000 squares in the real game...?
Some of the easing functions use math.sin etc and, as @SinisterSoft says, it may be better to replace this with a local sine function. At the top of easing.lua you can put
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
Likes: SinisterSoft
Likes: totebo
https://deluxepixel.com
Likes: totebo
https://deluxepixel.com
Also still looking for the answer to the question above.
I've used the same test as above, with 1,000 particles with a 64x64 Texture. For animation I've used the quite brilliant setParticleSpeed. The results:
iPad Mini Retina: 60 fps (in fact, I can add up to 3,000 particles without a slowdown)
iPhone 5: 12fps
iPod touch 5th generation: 4ps
On iPad Mini the squares look perfect and it runs fantastically. On iPhone5 and iPod touch, apart from the speed difference, the squares are jagged and appear to be leaning slightly. Any ideas why this could be?
I've attached the Gideros project to this post.
Likes: totebo
https://deluxepixel.com
https://deluxepixel.com
Likes: antix
https://deluxepixel.com
Likes: antix
Likes: SinisterSoft
Likes: totebo, antix
https://deluxepixel.com
Likes: SinisterSoft