Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Draw priority — Gideros Forum

Draw priority

totebototebo Member
edited July 2016 in General questions
With this code, the shape is never visible. Why is that? Does addChild happen with a delay, or on the next frame? Maybe Gideros waits until the whole chunk of code is ready before it draws?

I'm looking to show a loading screen before some heavy duty work, and bumped into this issue. Is there a safe way to detect when the shape is showing, so I can start the heavy lifting afterwards?
local shape = Shape.new()
shape:setFillStyle(Shape.SOLID, 0xff0000, 1)
shape:beginPath()
shape:moveTo(0,0)
shape:lineTo(100, 0)
shape:lineTo(100, 100)
shape:lineTo(0, 100)
shape:lineTo(0, 0)
shape:endPath()
shape:setPosition(0, 150)
stage:addChild(shape)	
 
for i=1, 100000000 do
end
 
shape:removeFromParent()
My Gideros games: www.totebo.com

Comments

  • totebototebo Member
    edited July 2016
    Perhaps even more curiously, why doesn't the shape become visible with this code?
    local shape = Shape.new()
    shape:setFillStyle(Shape.SOLID, 0xff0000, 1)
    shape:beginPath()
    shape:moveTo(0,0)
    shape:lineTo(100, 0)
    shape:lineTo(100, 100)
    shape:lineTo(0, 100)
    shape:lineTo(0, 0)
    shape:endPath()
    shape:setPosition(0, 150)
     
    local onAddedToStage =
    	function()
    		for i=1, 100000000 do
    		end
    		shape:removeFromParent()
    	end
     
    shape:addEventListener( Event.ADDED_TO_STAGE, onAddedToStage )
     
    stage:addChild(shape)
    My Gideros games: www.totebo.com
  • totebototebo Member
    edited July 2016
    This works! Why?! Is it "safe"?
    local shape = Shape.new()
    shape:setFillStyle(Shape.SOLID, 0xff0000, 1)
    shape:beginPath()
    shape:moveTo(0,0)
    shape:lineTo(100, 0)
    shape:lineTo(100, 100)
    shape:lineTo(0, 100)
    shape:lineTo(0, 0)
    shape:endPath()
    shape:setPosition(0, 150)
     
    local heavy =
    	function()
    		for i=1, 100000000 do
    		end
    		shape:removeFromParent()
    	end
     
    Timer.delayedCall( 1, heavy )
     
    stage:addChild(shape)
    My Gideros games: www.totebo.com
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    so to simplyfy things, gideros works like this
    run code
    render

    which together is frame

    so it does

    runcode
    render
    runcode
    render
    runcode
    render
    runcode
    render

    all the time under the hood

    Delay runs code on next enter frame or basically next time code is run, all other examples are on the same runcode time

    Likes: totebo, antix

    +1 -1 (+2 / -0 )Share on Facebook
  • totebototebo Member
    Thanks, got it.
    My Gideros games: www.totebo.com
Sign In or Register to comment.