I want to show some text over a playing sprite animation at some certain frames.
How is this possible to achieve in corona?
I tried to create a display text object and put it inside the group where sprite object is but didn’t work.
I want to show some text over a playing sprite animation at some certain frames.
How is this possible to achieve in corona?
I tried to create a display text object and put it inside the group where sprite object is but didn’t work.
Use groups to sort layers:
local below = display.newGroup() local above = display.newGroup() -- Insert the sprite into 'below' -- Insert the text into 'above'
Tried your suggestion but didn’t work. Here is my situation:
local asprite=display.newSprite(image\_sheet, sequenceData) asprite:play() spritegroup:insert(asprite) maingroup:insert(spritegroup) local atext= display.newtext("My Text Here") atext.x=0 atext.y=0 spritegroup:insert(atext)
That is not what I said to do.
do this:
-- Creation order sets layering order for groups local spritegroup = display.newGroup() -- bottom local textGroup= display.newGroup() -- middle local maingroup = display.newGroup() -- top -- Inserting groups into another group changes the child groups relative layering maingroup:insert(spritegroup) maingroup:insert(textGroup) -- Now, textgroup is OVER spritegroup, -- both are in mainGroup, -- anything inserted into maingroup at this time WILL be over both spritegroup and textgroup, -- as well as their contents. local asprite=display.newSprite(image\_sheet, sequenceData) asprite:play() spritegroup:insert(asprite) local atext= display.newtext("My Text Here") atext.x=0 atext.y=0 textGroup:insert(atext)
i understand, but that’s how my situation is.
main group contains the spritegroup and all coordinations are according to the main group, if i remove it entire app will be a real mesh.
and I’m not saying to remove main group. Simply create sub-groups for different content and put them in maingroup.
You’re going to have to use this technique if you want to ensure order. Others may tell you to use toFront() or toBack(), but those are kind of stop-gap solutions and only help with gross order changes.
Hi @roaminggamer,
Thank you for your explanation, i like it and understand the hierarchy on corona.
I created an individual module to test separately your code and works fine if i set the text after i create the sprite,
but as i want to create the text at a certain point when animation is playing (to simplify it when event=“began”)
it won’t work anymore:
Working example:
-- Creation order sets layering order for groups local spritegroup = display.newGroup() -- bottom local textGroup= display.newGroup() -- middle local maingroup = display.newGroup() -- top -- Inserting groups into another group changes the child groups relative layering maingroup:insert(spritegroup) maingroup:insert(textGroup) -- Now, textgroup is OVER spritegroup, -- both are in mainGroup, -- anything inserted into maingroup at this time WILL be over both spritegroup and textgroup -- as well as their contents. local asprite=display.newSprite(image\_sheet, sequenceData) asprite:play() spritegroup:insert(asprite) local atext= display.newtext("My Text Here") atext.x=0 atext.y=0 textGroup:insert(atext)
show text when animation plays:
-- Creation order sets layering order for groups local spritegroup = display.newGroup() -- bottom local textGroup= display.newGroup() -- middle local maingroup = display.newGroup() -- top -- Inserting groups into another group changes the child groups relative layering maingroup:insert(spritegroup) maingroup:insert(textGroup) -- Now, textgroup is OVER spritegroup, -- both are in mainGroup, -- anything inserted into maingroup at this time WILL be over both spritegroup and textgroup -- as well as their contents. local function spriteListener(event) -- body if event=="began" then local atext = display.newText("My Text Here", 0, 0, native.systemFont, 14 ) atext:setFillColor(1.0,1.0,0.0) textGroup:insert(atext) end end local asprite=display.newSprite(image\_sheet, sequenceData) asprite:play() asprite:addEventListener( "sprite", spriteListener) spritegroup:insert(asprite)
Hi @roaminggamer,
Thank you for your explanation, i like it and understand the hierarchy on corona.
I created an individual module to test separately your code and works fine if i set the text after i create the sprite,
but as i want to create the text at a certain point when animation is%
Have I misunderstood the question. I thought you were having a layering problem. Are you trying to have your text update at specific points during the animation?
If so, use a sprite listener: http://docs.coronalabs.com/api/event/sprite/phase.html
Here. I made an example:
https://www.youtube.com/watch?v=Bp2HyZssb-c&feature=youtu.be&hd=1
Get the sample here:
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/02/spriteListeners.zip
Use groups to sort layers:
local below = display.newGroup() local above = display.newGroup() -- Insert the sprite into 'below' -- Insert the text into 'above'
Tried your suggestion but didn’t work. Here is my situation:
local asprite=display.newSprite(image\_sheet, sequenceData) asprite:play() spritegroup:insert(asprite) maingroup:insert(spritegroup) local atext= display.newtext("My Text Here") atext.x=0 atext.y=0 spritegroup:insert(atext)
That is not what I said to do.
do this:
-- Creation order sets layering order for groups local spritegroup = display.newGroup() -- bottom local textGroup= display.newGroup() -- middle local maingroup = display.newGroup() -- top -- Inserting groups into another group changes the child groups relative layering maingroup:insert(spritegroup) maingroup:insert(textGroup) -- Now, textgroup is OVER spritegroup, -- both are in mainGroup, -- anything inserted into maingroup at this time WILL be over both spritegroup and textgroup, -- as well as their contents. local asprite=display.newSprite(image\_sheet, sequenceData) asprite:play() spritegroup:insert(asprite) local atext= display.newtext("My Text Here") atext.x=0 atext.y=0 textGroup:insert(atext)
i understand, but that’s how my situation is.
main group contains the spritegroup and all coordinations are according to the main group, if i remove it entire app will be a real mesh.
and I’m not saying to remove main group. Simply create sub-groups for different content and put them in maingroup.
You’re going to have to use this technique if you want to ensure order. Others may tell you to use toFront() or toBack(), but those are kind of stop-gap solutions and only help with gross order changes.
Hi @roaminggamer,
Thank you for your explanation, i like it and understand the hierarchy on corona.
I created an individual module to test separately your code and works fine if i set the text after i create the sprite,
but as i want to create the text at a certain point when animation is playing (to simplify it when event=“began”)
it won’t work anymore:
Working example:
-- Creation order sets layering order for groups local spritegroup = display.newGroup() -- bottom local textGroup= display.newGroup() -- middle local maingroup = display.newGroup() -- top -- Inserting groups into another group changes the child groups relative layering maingroup:insert(spritegroup) maingroup:insert(textGroup) -- Now, textgroup is OVER spritegroup, -- both are in mainGroup, -- anything inserted into maingroup at this time WILL be over both spritegroup and textgroup -- as well as their contents. local asprite=display.newSprite(image\_sheet, sequenceData) asprite:play() spritegroup:insert(asprite) local atext= display.newtext("My Text Here") atext.x=0 atext.y=0 textGroup:insert(atext)
show text when animation plays:
-- Creation order sets layering order for groups local spritegroup = display.newGroup() -- bottom local textGroup= display.newGroup() -- middle local maingroup = display.newGroup() -- top -- Inserting groups into another group changes the child groups relative layering maingroup:insert(spritegroup) maingroup:insert(textGroup) -- Now, textgroup is OVER spritegroup, -- both are in mainGroup, -- anything inserted into maingroup at this time WILL be over both spritegroup and textgroup -- as well as their contents. local function spriteListener(event) -- body if event=="began" then local atext = display.newText("My Text Here", 0, 0, native.systemFont, 14 ) atext:setFillColor(1.0,1.0,0.0) textGroup:insert(atext) end end local asprite=display.newSprite(image\_sheet, sequenceData) asprite:play() asprite:addEventListener( "sprite", spriteListener) spritegroup:insert(asprite)
Hi @roaminggamer,
Thank you for your explanation, i like it and understand the hierarchy on corona.
I created an individual module to test separately your code and works fine if i set the text after i create the sprite,
but as i want to create the text at a certain point when animation is%
Have I misunderstood the question. I thought you were having a layering problem. Are you trying to have your text update at specific points during the animation?
If so, use a sprite listener: http://docs.coronalabs.com/api/event/sprite/phase.html
Here. I made an example:
https://www.youtube.com/watch?v=Bp2HyZssb-c&feature=youtu.be&hd=1
Get the sample here:
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/02/spriteListeners.zip