Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Dynamic shape — Gideros Forum

Dynamic shape

ShiNeShiNe Member
edited December 2011 in General questions
Hi.
I can't figure how to draw a dynamic shape without losing memory.
I've putted a shape creation piece of code to enter_frame function. It works well but it raises a lot of memory every second.
frameCounter = 0
function onEnterFrame()
 
	frameCounter = frameCounter + 1
	--after frame 1 start to remove shape
	if frameCounter > 1 then
		stage:removeChild(shape)
	end
 
	if frameCounter > 60 then
		frameCounter = 2
	end
 
 
	--CreateShape
	shape = Shape.new()
	shape:setLineStyle(4, 0x000000)
	shape:setFillStyle(Shape.SOLID, 0xff0000, 0.5)
	shape:beginPath(Shape.NON_ZERO)
	local x1,y1 = actors[2]:getPosition()
	shape:moveTo(x1, y1)
	for i=2,#actors do
 
		if i==#actors then
			l = 2
		else
			l = i+1
		end
 
 
		local x2,y2 = actors[l]:getPosition()
 
 
		shape:lineTo(x2, y2)
 
	end
	shape:closePath()
	shape:endPath()
	stage:addChild(shape)
 
 
end
 
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
BTW thank you for the engine.
Tagged:

Comments

  • Create that shape once out side the enterFrame event. What you do here is you create a new shape at everyframe. At the beginning 60 shapes each second. You can't see them as the are overlapping each other.
  • atilimatilim Maintainer
    Yes, as @MikeHart said create shape once. And then before creating your geometry at each frame call shape:clear().
  • ShiNeShiNe Member
    edited December 2011
    OK. I think that you didn't understand me. I have a moving points(x1,y1, and others x2,y2) that I use for shape creating. This is why I need to change a path every frame.
    I did as you said but it's still raises the memory.
    shape = Shape.new()
    stage:addChild(shape)
    --Created shape once
    frameCounter = 0
    function onEnterFrame()
     world:step(1/60, 8, 3)
     
    	frameCounter = frameCounter + 1
     
    	if frameCounter > 1 then
    		shape:clear()
    	end
     
     
    	shape:setLineStyle(4, 0x000000)
    	shape:setFillStyle(Shape.SOLID, 0xff0000, 0.5)
    	shape:beginPath(Shape.NON_ZERO)
    	local x1,y1 = actors[2]:getPosition()
    	shape:moveTo(x1, y1)
    	for i=2,#actors do
    		if i==#actors then
    			l = 2
    		else
    			l = i+1
    		end
    		local x2,y2 = actors[l]:getPosition()
    		shape:lineTo(x2, y2)
    	end
    	shape:endPath()
     
    end
     
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
    Please point me out because I'm working on this for a few days now
  • atilimatilim Maintainer
    edited December 2011
    If this way still raises memory, than there is possibility of bug. Let me look it now.
    Edit: Yes memory usage is increasing :) Will be fixed. Thank you.
  • ShiNeShiNe Member
    edited December 2011
    Hey. Thanks
  • gorkemgorkem Maintainer
    Fixed for 2011.9. Thanks for reporting.
Sign In or Register to comment.