user3131148
user3131148

Reputation: 353

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

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?

Upvotes: 0

Views: 395

Answers (1)

Lukis
Lukis

Reputation: 652

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

Upvotes: 2

Related Questions