I want my score to always be in the front. I’ve got objects spawning and crossing the score, I want them to always appear behind it. Anyone knows how to achieve this? [import]uid: 14018 topic_id: 5233 reply_id: 305233[/import]
http://developer.anscamobile.com/reference/index/objecttofront [import]uid: 12108 topic_id: 5233 reply_id: 17396[/import]
I don’t know how to adjust that example to fit my situation? My object does not belong to any group or anything. It’s just a display.newText object that prints the score. I tried writing it like this:
local score = 0
local showScore = display.newText(score, 18, 15)
showScore:setTextColor(125, 255, 255)
showScore.size = 25
showScore:toFront()
That doesn’t work though [import]uid: 14018 topic_id: 5233 reply_id: 17398[/import]
try making it a physics body
physics.addBody(showScore, “static” )
then try calling
showScore:toFront() see if that helps ( oh and i a newbie so its just a thought )
good luck [import]uid: 11860 topic_id: 5233 reply_id: 17406[/import]
Nope, still not working…
I think I need to type in something else also to make it know that it needs to be in front of everything, not only a certain group? [import]uid: 14018 topic_id: 5233 reply_id: 17467[/import]
Every time you create a display object, it is placed on the top of the display order. So when you create your score text object, it’s on top, but each subsequent object is placed on top of it. Your toFront() method is doing what it’s supposed to do, but only at that specific instant. The solution here is to make a group for all your display objects (if you’re using the director class you should already be inserting into the localGroup group), and leave the score outside of it and on top of it.
[lua]local objectGroup = display.newGroup()
local score = 0
local showScore = display.newText(score, 18, 15)
showScore:setTextColor(125, 255, 255)
showScore.size = 25
– showScore:toFront() – Not needed because showScore was created AFTER objectGroup so it’s on top
for i=1, 10 do
local o = display.newRect(0,0,150,150)
objectGroup:insert(o)
end[/lua]
That will create 10 squares and insert them all into the objectGroup, and leave your score on top of them all. [import]uid: 12405 topic_id: 5233 reply_id: 17529[/import]
i’ve anwered this in your other thread.
http://developer.anscamobile.com/forum/2011/01/20/3-unanswered-questions-developer-support-board
put the score in a completely separate display group above the objectGroup
[import]uid: 6645 topic_id: 5233 reply_id: 17721[/import]
I didnt work for me too, but then i placed it after my background and it works
So just place it after your background object [import]uid: 11559 topic_id: 5233 reply_id: 17992[/import]