Text remains on screen when not needed

Hi,

I am trying to send a warning to the player by displaying a text on screen when he is getting close to the edge of the playing field.

The text displays allright, the problem is that when the player is back inside the ‘safe zone’ the text remains on screen. Like if the player gets the warning message and then moves inside (say, indicator.x like 200), the text remains on display for the rest of the game. I want the text on display only when indicator.x is between 245 and 260.

Any help, please?

Here is the code:

if indicator.x\>245 and indicator.x\<260 then local warning1 = display.newText("Carefull, you are close to the edge!", 100, 500, native.systemFont, 40) warning1:setTextColor(255, 0, 0) end

Does that mean you have that in a runtime listener? I’d highly advise against that since it’d be a waste of resources. You should just setup 2 invisible ‘walls’. one at x location 245 that triggers the text on collision and then another at 260 to hide or remove the text. Or if the player ins’t able to get passed 260 then you only need 1 wall at 245 that triggers the text once passed and hides it when they return

Thanks for the reply.

Yes I have it in a runtime listener that I use for some other functions.

Regarding the ‘invisible walls’, since my object is a physical object, if i set up that wall, how could I get indicator to get through the wall instead of colliding and bouncing off?

Thanks

You just have to set it as a sensor

http://jp.anscamobile.com/dev/reference/index/bodyissensor/index.html

Does that mean you have that in a runtime listener? I’d highly advise against that since it’d be a waste of resources. You should just setup 2 invisible ‘walls’. one at x location 245 that triggers the text on collision and then another at 260 to hide or remove the text. Or if the player ins’t able to get passed 260 then you only need 1 wall at 245 that triggers the text once passed and hides it when they return

Thanks for the reply.

Yes I have it in a runtime listener that I use for some other functions.

Regarding the ‘invisible walls’, since my object is a physical object, if i set up that wall, how could I get indicator to get through the wall instead of colliding and bouncing off?

Thanks

You just have to set it as a sensor

http://jp.anscamobile.com/dev/reference/index/bodyissensor/index.html