I’ve made a simple game involving polygons that scales out from the center of the screen.
It can be found here if anyone, for some perverse reason, should be interested…:
https://play.google.com/store/apps/details?id=com.gmail.runewinse.Ketchup&hl=en
But I’m not sure that I do his the most efficient way. As it is now I delete and recreate each polygon with a new, recalculated set of vertices per frame.
Since the polys essentially doesn’t do anything but scale I was certain that it would be a good idea to just create the polygon once (at leas until it’s off screen and need to be replaced) at the largest visible size and then use the width/height parameter and set the size of the polygon according to the z value (depth).
But I just cannot make it to work. The .width/.height seem to work in a way that (to me) is completely unexpected. Please consider the code below:
local vertices = {-300, -300, 300, -300, 300, 300, -300, 300} local poly = display.newPolygon(display.contentWidth/2, display.contentHeight/2, vertices ) poly:setFillColor(1,1,0,1) local function RedrawPoly() poly.width = 580 poly.height = 580 end local frameRedrawListener = function(e) RedrawPoly() end Runtime:addEventListener( "enterFrame", frameRedrawListener )
Here I initialize a polygon and then (per frame) try to set the width/height to a fixed number. But what happens? Run it and see for yourself!
It seems like what happens by setting the width/height is depending on the original size of the poly. Here the original width/height is 600x600. Each time i set the width/height to 580x580 it seems to make the poly scale down a bit. So repeatedly setting the size to 580x580 just keep shrinking the poly until it’s gone.
The larger the difference from the original to the new size the faster the shrinking. Unless, that is, the new size is larger than the original size, in which case the poly just keeps expanding… :rolleyes:
So… what’s going on here. Is what I’m trying to to impossible? Do I have to keep recreating all the evil polygons (of doom) for each and every frame or is there a way to scale them with some sort of control?