Smooth out spawn/transition.to function

I am using this code to spawn a object but the object is not falling (transition) smooth in the game.

yForBack = 6000 yForB1A = 2000 yForB1B = 3000 yForB2A = 2000 yForB2B = 3000 yForB3A = 2000 yForB3B = 3000 yForGCa = 2000 yForGCb = 3000 local screenGroup = self.view local randomBackC = function() local backC = display.newImage("Cloud"..tostring(math.random(1, 4))..".png") backC.x = math.random (0, 450); backC.y = -50 physics.addBody( backC, { density=.1, bounce=0.1, friction=.2, radius=45, filter=nonfilter } ) backC.name = "badclouts" physics.addBody(backC, {bounce=0, filter=b}) backC.isSensor = true backC.rotation = math.random(-20,20) -- Rotate the object backC:applyForce( 0, yForBack, backC.x, backC.y ) -- apply the force to your cloud transition.to( backC, { time=yForBack, y=600, } ) backC.gravityScale = 0.0 print("yForBack " .. yForBack) local cleanup cleanup = function() if backC then if backC.y \>600 then backC:removeSelf() backC = nil end end end Runtime:addEventListener("enterFrame", cleanup) end randomBackC1 = timer.performWithDelay( 500, randomBackC, 0 ) local function speatTimer() yForBack = yForBack - 1 yForB1A = yForB1A - 1 yForB1B = yForB1B - 1 yForB2A = yForB2A - 1 yForB2B = yForB2B - 1 yForB3A = yForB3A - 1 yForB3B = yForB3B - 1 yForGCa = yForGCa - 1 yForGCb = yForGCb - 1 end local SpeedTimerall = timer.performWithDelay( 100, speatTimer, 500 )  

Is there anything i can do to make it smoother ?

Kevin-

@mmk,

Hi.  Transitions are primarily for moving ‘non-physics’ bodies.  You can certainly use them with physics bodies, but when you combine forces and transitions you are going to get some strange effects and perhaps side-effects.

I’m not sure what ‘non-smooth’ effects you’re seeing, but try this:

  1. Don’t apply a force and use a transition.  Just use the transition.

  2. Either turn off gravity for the game OR for each object that has both a body and uses transitions

Ex: 

obj.gravityScale = 0 -- Turns off gravity effects for this object. 
  1. Clear linear and angular damping for objects that have a physics body and use transitions:

Ex:

obj.linearDamping = 0 obj.angularDamping = 0 
  1. Experiment w/ different easing effects for your transitions:

Ex:

transition.to(backC, { time=yForBack, y=600, transition=easing.inExpo}) 

Question: Do you have the capacity to make a video and show us the problem?  (http://www.screencast-o-matic.com/)

its every time “randomBadC1 = timer.performWithDelay( math.random(1000, 5000), randomBad1, 0 )” it shocks a bit, that what i mean whit  the objects not  ‘non-smooth’ effects. its not so bad on the pc but on the phone its noticeable

You could try making your fps 60 in your config.lua file. Its not the best way to go about fixing this but it’s helped smoothing stuff out for me in the past.

@mmk,

Hi.  Transitions are primarily for moving ‘non-physics’ bodies.  You can certainly use them with physics bodies, but when you combine forces and transitions you are going to get some strange effects and perhaps side-effects.

I’m not sure what ‘non-smooth’ effects you’re seeing, but try this:

  1. Don’t apply a force and use a transition.  Just use the transition.

  2. Either turn off gravity for the game OR for each object that has both a body and uses transitions

Ex: 

obj.gravityScale = 0 -- Turns off gravity effects for this object. 
  1. Clear linear and angular damping for objects that have a physics body and use transitions:

Ex:

obj.linearDamping = 0 obj.angularDamping = 0 
  1. Experiment w/ different easing effects for your transitions:

Ex:

transition.to(backC, { time=yForBack, y=600, transition=easing.inExpo}) 

Question: Do you have the capacity to make a video and show us the problem?  (http://www.screencast-o-matic.com/)

its every time “randomBadC1 = timer.performWithDelay( math.random(1000, 5000), randomBad1, 0 )” it shocks a bit, that what i mean whit  the objects not  ‘non-smooth’ effects. its not so bad on the pc but on the phone its noticeable

You could try making your fps 60 in your config.lua file. Its not the best way to go about fixing this but it’s helped smoothing stuff out for me in the past.