How can i trigger a function when image hits bottom of the screen?

okay so i have this image in my game, I want it to trigger a function i have named “gameover()” whenever the image hits the bottom of the screen, how can i do this? i was thinking this would work but it didnt, any help? thanks!

local scroll = display.newImage( "scroll.png" )  
scroll.x = 165  
scroll.y = 230  
localGroup:insert(scroll)  
  
if (scroll.y \> 480) then  
gameover()  
end  

[import]uid: 10827 topic_id: 6764 reply_id: 306764[/import]

It would probably be helpful to post the rest of your code :slight_smile:

For example, what does your gameover() function look like?

You’ve created a display group and your post does not show where you’ve created it.

Here are some links you can take a look at:
http://developer.anscamobile.com/content/display-objects#Groups

Here’s a link about Events and Listeners that might be helpful to what you’re doing:
http://developer.anscamobile.com/content/events-and-listeners
[import]uid: 8045 topic_id: 6764 reply_id: 23607[/import]

all my game over function is only an image, thanks for those links, all i want to know is how can i make it load a function or change to another scene or anythingg, once it hits the bottom of the screen?

gameover = function() gameoverImage = display.newImage("gameover.png") gameoverImage.x = 160 gameoverImage.y = 240 localGroup:insert(gameoverImage) end [import]uid: 10827 topic_id: 6764 reply_id: 23610[/import]

That “if” statement only runs once but you need to check the position over and over. Use the “enterFrame” event. [import]uid: 12108 topic_id: 6764 reply_id: 23705[/import]

yesss! got it to work using the “enterFrame” event, thank you!! [import]uid: 10827 topic_id: 6764 reply_id: 23731[/import]