Corona SDK: How do I get an object to float from the bottom of a screen to the top?

StackOverflow https://stackoverflow.com/questions/23531455

  •  17-07-2023
  •  | 
  •  

Question

I'm pretty new to the sdk so forgive me. I want an object to float/transition from the bottom of the screen to the top and keep going until it is out of the device. How do I do that without hard coding the values since all screens have different heights?

Was it helpful?

Solution

First place your object on the bottom of the screen:

object.y = (display.contentHeight + display.screenOriginY * -2) + object.contentHeight * 0.5 
//if starting outside of the screen

object.y = (display.contentHeight + display.screenOriginY * -2) - object.contentHeight * 0.5 
//if starting at the bottom of the screen

then perform transition.to

transition.to(object, { time = 500, y = 0 - display.screenOriginY })

I wrote it from my memory, so it may not work by copy + paste, but idea stays the same.

object - this is your object you want to transform

display.screenOriginY - this is the distance from the top of the actual screen to the top of the content area (more info here: https://docs.coronalabs.com/api/library/display/screenOriginY.html )

You may also need to read about transitions: http://docs.coronalabs.com/api/library/transition/to.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top