I was adviced to post in this board instead, so here it is
How do I make physical bodies not bounce off each other? Instead I want them to just go through each other, is this possible?
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?
Been searching for a solution to this but can’t find it anywhere… Is it possible to wrap the screen? So that when I reach the end of my screen I appear on the other side? And is it possible to “lock” the screen so that when I reach the top of my screen I stop?
Thanks in advance, [import]uid: 14018 topic_id: 5286 reply_id: 305286[/import]
When you call toFront() it pushes the object to the front once there and then - it’s not permanently at the forefront. If you add any other display objects to the screen after you make that call they will appear above your text. What you need to do is have a frame event which sets object:toFront(). This will ensure that your text always gets pushed to the front of the order index everytime the screen is redrawn.
You didn’t specify if you were asking about physics objects or sprites, I’ll talk about sprites because I don’t know all that much about physics:
To get an object to appear on the opposite side after it goes offscreen - you need to check the objects x coordinate. If object.x > display.contentWidth then it is offscreen and you should set object.x = 0 and animate from there to make it reappear on the other side.
If you want to set the top of the screen as a boundary you need to perform boundary checks similar to above - the fishies sample code that comes with Corona is a good example of this. [import]uid: 11393 topic_id: 5286 reply_id: 17518[/import]
That way every frame your score gets updated and brought to the front. I’m working for memory here, but that should work.
[import]uid: 10835 topic_id: 5286 reply_id: 17519[/import]
How do I fix the frame event that sets object:toFront()? Any good tutorial on this? I looked it up in the docs but I didn’t understand it…
Isn’t there any smoother way to wrap the screen? Instead of checking the coords? Also I checked the fishies example for the boundary-thing, but that example contained soo much code I could not make out what caused the boundaries… I’m going to use this for sprites that have physics bodies
Thanks a lot for your reply btw! [import]uid: 14018 topic_id: 5286 reply_id: 17520[/import]
For 3 depending on how you want the stop to be, instead of checking y coordinates you can simply add an invisible rectangle with a static physics body.
The shape tumbler sample does this and is well commented. Check it out. For wrapping the screen around you have to check for x values constantly.
It’s not as hard as it sound though. Just have in your runtime enterframe function (like the textupdate one above, you can even use the same so you have only 1 enterframe listener going) the following code:
[lua]if objectname.x < 0 then
objectname.x = display.contentWidth
end
if objectname.x > display.contentWidth then
objectname.x = 0
end [/lua]
I haven’t really tested this with dynamic body types. You might need to change the body type to kinetical before moving and then to dynamic after the move. I’ll leave the testing to that to you.
That’s a much better idea. Just make sure all your physics objects end up in the same group if you ever plan on moving it (like a camera following the player or something like that). Otherwise, glitchiness is sure to follow. [import]uid: 10835 topic_id: 5286 reply_id: 17708[/import]