3 unanswered questions from the Developer Support-board

I was adviced to post in this board instead, so here it is

  1. How do I make physical bodies not bounce off each other? Instead I want them to just go through each other, is this possible?

  2. 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?

I’ve tried writing my code like this:

local score = 0

local showScore = display.newText(score, 18, 15)

showScore:setTextColor(125, 255, 255)
showScore.size = 25
showScore:toFront()

This doesn’t work though

  1. 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]

  1. Can’t help you there I don’t use physics

  2. 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.

  3. 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]

For 2, how are you updating your score? The way you have it set it up there it won’t update when the score value changes.

So you need to have a function for that and add a runtime enterframe listener for it. Like so:

[lua]local textupdate = funtion()
showScore.text = score
showScore:toFront()
end

Runtime:addEventListener( “enterFrame”, textupdate)[/lua]

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]

Ahh thanks, didn’t think about that! [import]uid: 14018 topic_id: 5286 reply_id: 17523[/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.

Edit: for moving physics objects also check out this thread:
http://developer.anscamobile.com/forum/2010/12/02/crash-when-i-try-move-object-changing-x-and-y-attributes

You might need to implement a short timer before you execute the move code. [import]uid: 10835 topic_id: 5286 reply_id: 17527[/import]

for (1) use sensors or collision index/filters

for (2), i dont see a need to constantly send the score graphic toFront…

just create 2 display groups, one for inserting your game objects (player, enemies etc) and then another one above that for inserting your score etc

[lua]local world = display.newGroup()
local hud = display.newGroup()[/lua]

[import]uid: 6645 topic_id: 5286 reply_id: 17707[/import]

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]

thanks a lot this did it [import]uid: 14018 topic_id: 5286 reply_id: 17787[/import]