Incorrect ball jump effect when user interaction involved

Hello, newcomer here so please bear with me :slight_smile:

Situation

I develop a game viewed from TOP.

There is an object bouncing across the screen on platforms placed below it.

The bouncing effect of the object is simulated by using transition.to function where I scale up and then back down, so it seems the object is closer to the user when it is in highest point of the jump and then is falling away from the user. In the params of the transition.to function, I also change the y position, so the effect is more realistic.

Problem

My problem is that when I want to also change the position of the object based on user action (analog joystick) during the hero is bouncing the final effect is wrong. It is because I calculate the new y-position based on current y-velocity and actual y-position of the ball. Yet, the y-position is also used in the transition.to params, and I’m not able to dynamically change it there during one bounce. To give example:

Object call hero is at 0,0 position.
Now, the bounce effect code:
[blockcode]
local initialY = hero.y
transition.to( hero, { time = myTime, y = initialY-75, xScale = 1.2, yScale = 1.2, transition=easing.outQuad, onComplete = function()
transition.to( hero, { time = myTime, y = initialY, xScale = 1.0, yScale = 1.0, transition=easing.inQuad})end})
[/blockcode]

With that code he is moved to -75 and then back to 0 on the y-axis.
This is done in event handler for enterFrame event. There is also some mechanism preventing from starting another bounce when the hero is still bouncing - by simle checking and setting of isBouncing property in the second transition.to function call (I removed it from here for sake of simplicity)

Problems occur, when the user moves the hero along y-axis by his action, thus seting its vy to e.g. -3

The new position is calculated in enterFrame handler simply by

hero.y = hero.y + vy

The resulting effect is the hero is moving by -3 points in y-direction every frame, meaning he is e.g. at [0, -9] after 3 frames, but the bounce effect started at frame 1 is still using the original offset (-75) along the y-axis and not taking the -9 into consideration.

This all results in the fact, that the ball is not bouncing “high enough” when user moves it in negative values in the y-direction, or is bouncing “too high” when moved in positive direction.

The shadow placed under the hero, that is scaling the same way from 1 to 0.6 and back, works fine, because there is no y-offset used in the transition.to function call. It is moved by the user action only:

[blockcode]
transition.to( shadow, { time = myTime, xScale = 0.6, yScale = 0.6, transition=easing.outQuad, onComplete = function()
transition.to( shadow, { time = myTime, xScale = 1.0, yScale = 1.0, transition=easing.inQuad})
end})
[/blockcode]

Question

How would you handle this issue?

My ideas were:

  1. Not use transition.to at all and do the math in enterFrame manually - I wanted to avoid this !!!
  2. Use sprites - I lose some future game aspects I wanted to implement later, e.g. change hero attributes.

[import]uid: 149758 topic_id: 27266 reply_id: 327266[/import]

Hi tom.rada, and welcome to Corona,

Personally, I would suggest handling your bounce effect (up and down in relation to “camera”) using transitions, but handle your movement using either a Runtime listener or physics (if you were planning to use physics anyway, otherwise don’t). As you saw, it’s impossible to adjust the outcome of a transition mid-stream… I mean there are convoluted ways, like canceling and starting new transitions, but I wouldn’t suggest them. Handling your movement separate to your bounce should start getting this closer to where you’d like.

Hope this helps somewhat!

Brent Sorrentino
[import]uid: 9747 topic_id: 27266 reply_id: 110882[/import]