Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Is there a Layer/Sprite permanently on top of everything (Sprites like Scenes, etc)? — Gideros Forum

Is there a Layer/Sprite permanently on top of everything (Sprites like Scenes, etc)?

MellsMells Guru
edited August 2013 in General questions
Hi,

I would like to display fps and texture memory usage independently of my scene manager, on top of everything.
Is such a layer/Sprite available in Gideros?
twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps

Comments

  • SinisterSoftSinisterSoft Maintainer
    edited August 2013
    Just add a sprite to stage after you have added the SceneManager - or before if you want Scene Manager above the game.

    I use scene manager whilst the game is running underneath on stuff I'm writing now - this way it looks more like a traditional arcade game - the game self-plays underneath in demo mode whilst the player picks his options/starts the game for real.
    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
  • ar2rsawseenar2rsawseen Maintainer
    edited August 2013 Accepted Answer
    Also we could use some overriding hackery (also known as witchcraft) :)
    Which would work also if you add elements tot he stage without sceneManager.
    as you want it always to be on top, we would want it to add to stage, so let's override stage addChild method to look for a "superLayer" :)
    stage.__addChild = Sprite.addChild
    function stage:addChild(child)
    	print("adding child")
    	if stage.__superLayer and stage:contains(stage.__superLayer) then
    		local ind = stage:getChildIndex(stage.__superLayer)
    		stage:addChildAt(child, ind)
    	else
    		stage:__addChild(child)
    	end
    end
    then just for test, let's create a red text and set it as superLayer
    local text1 = TextField.new(nil, "text1")
    text1:setScale(4)
    text1:setPosition(100, 100)
    text1:setTextColor(0xff0000)
    stage:addChild(text1)
     
    stage.__superLayer = text1
    stage:addChild(text1)
    now we simple add another text in same position, but this time blue text, using simple addChild method
    local text2 = TextField.new(nil, "text2")
    text2:setScale(4)
    text2:setPosition(100, 100)
    text2:setTextColor(0x0000ff)
    stage:addChild(text2)
    And let's run the project.
    Wow, red text is still on the blue text, although we added blue text after red text, what a sorcery :)
    +1 -1 (+2 / -0 )Share on Facebook
  • lol, yes that works too, but it's a bit crazy. :)
    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
  • @SinisterSoft, @ar2rsawseen
    thanks, I wanted to check if it was already available before adding yet another Sprite on top.

    This _superLayer implementation is interesting :)
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
Sign In or Register to comment.