earthquake movement

Hi,

Newbie here, developping my first game. Beg you to be indulgent if I ask improper questions…Thanks!

 I would like to have an object (which for your  reference is displayed on the centre of the screen) moving over a one second time period, in a sort of ‘shaking’ or ‘trembling’ way while staying in place (center of the screen), like it’s affected by an earthquake or it’s the mouth of a volcano about to be erupting (matter of fact the object has circular shape).

Which direction should I look towards? multi-transitions? Tried them for a rather much simpler kind of movement and it turned out to be a functional but pretty intricated solution… Are there other ways I’m not aware of??

Thanks a lot!

Hi @akak,

If the effect is very subtle, you might be able to just move the object around positionally (shift it in block-steps). But for a smoother effect, multi-transitions is better. If you take this approach, I suggest you set up one transition handle which holds the current transition until onComplete, which then triggers the next in series, but the handle holds that new transition as well, and so forth in sequence. This way, you won’t have a large number of transition handles going on simultaneously with “delays” between each, and one handle will be easier to deal with (pause, resume, cancel, etc.)

Brent

Hi Brent,

thanks again for the answer!

I’m sorry, being a neophyte at corona and programming in general I don’t quite grasp your suggestion, well I do but not in details.

Here’s the first attempt i made with a mult-transition loop, It does work for the first ‘round’ but doesn’t engage the cicle a second time (meaning trans3 doesn’t make trans1 to strat again). Any idea on how to proceed from here and/or apply your suggestions?

Thanks whole alot!

local function trans3 ()  
     transition.to( ahole, {time=1000, x= centerX -10, onComplete=trans1 )
 end

local function trans2 ()
    transition.to (ahole, {time = 1000, x=centerX, onComplete=trans3})
end

local function trans1 ()
    transition.to( ahole, {time=1000, x=centerX+10, onComplete=trans2} )
end

trans1 ()

–time is set very slow to see the effect of the transition, the result effect should much more fast, as a trembling movement.

check this out. I resolved with this clunky code. Seems too lenghty to me, if you have suggestions to synthetize or structurally get on it with another approach they’d be more than welcome. Thanks!

function shaking ()
 
 function trans3 ()  
     transition.to( ahole, {time=10, x= centerX -5, onComplete=trans1} )
 end

 function trans2 ()
    transition.to (ahole, {time = 10, x=centerX, onComplete=trans3})
end

 function trans1 ()
    transition.to( ahole, {time=10, x=centerX+5, onComplete=trans2} )
end

trans1 ()

end

shaking ()

local function cancelshake () --only way I figured to stop the whole thing!

transition.cancel (ahole)
ahole.x=centerX

end

Hi @akak,

You should build one function that handles this, not several. Store each successive transition data inside a table and sequence through it like this:

[lua]

local currentIndex = 1

local thisTrans

local transTable = {

   { time=500, x=centerX-10 },

   { time=500, x=centerX },

   { time=500, x=centerX+10 }

}

local function doNextTrans()

   if ( thisTrans ) then

      transition.cancel( thisTrans )

   end

   if ( transTable[currentIndex] ) then

      local transData = transTable[currentIndex]

      transData.onComplete = doNextTrans

      thisTrans = transition.to( ahole, transData )

      currentIndex = currentIndex+1

   end

end

doNextTrans()

[/lua]

Brent

dear lord… thanks a lot. It’s just I need to study and learn proper and efficient syntax coding.

Hi @akak,

If the effect is very subtle, you might be able to just move the object around positionally (shift it in block-steps). But for a smoother effect, multi-transitions is better. If you take this approach, I suggest you set up one transition handle which holds the current transition until onComplete, which then triggers the next in series, but the handle holds that new transition as well, and so forth in sequence. This way, you won’t have a large number of transition handles going on simultaneously with “delays” between each, and one handle will be easier to deal with (pause, resume, cancel, etc.)

Brent

Hi Brent,

thanks again for the answer!

I’m sorry, being a neophyte at corona and programming in general I don’t quite grasp your suggestion, well I do but not in details.

Here’s the first attempt i made with a mult-transition loop, It does work for the first ‘round’ but doesn’t engage the cicle a second time (meaning trans3 doesn’t make trans1 to strat again). Any idea on how to proceed from here and/or apply your suggestions?

Thanks whole alot!

local function trans3 ()  
     transition.to( ahole, {time=1000, x= centerX -10, onComplete=trans1 )
 end

local function trans2 ()
    transition.to (ahole, {time = 1000, x=centerX, onComplete=trans3})
end

local function trans1 ()
    transition.to( ahole, {time=1000, x=centerX+10, onComplete=trans2} )
end

trans1 ()

–time is set very slow to see the effect of the transition, the result effect should much more fast, as a trembling movement.

check this out. I resolved with this clunky code. Seems too lenghty to me, if you have suggestions to synthetize or structurally get on it with another approach they’d be more than welcome. Thanks!

function shaking ()
 
 function trans3 ()  
     transition.to( ahole, {time=10, x= centerX -5, onComplete=trans1} )
 end

 function trans2 ()
    transition.to (ahole, {time = 10, x=centerX, onComplete=trans3})
end

 function trans1 ()
    transition.to( ahole, {time=10, x=centerX+5, onComplete=trans2} )
end

trans1 ()

end

shaking ()

local function cancelshake () --only way I figured to stop the whole thing!

transition.cancel (ahole)
ahole.x=centerX

end

Hi @akak,

You should build one function that handles this, not several. Store each successive transition data inside a table and sequence through it like this:

[lua]

local currentIndex = 1

local thisTrans

local transTable = {

   { time=500, x=centerX-10 },

   { time=500, x=centerX },

   { time=500, x=centerX+10 }

}

local function doNextTrans()

   if ( thisTrans ) then

      transition.cancel( thisTrans )

   end

   if ( transTable[currentIndex] ) then

      local transData = transTable[currentIndex]

      transData.onComplete = doNextTrans

      thisTrans = transition.to( ahole, transData )

      currentIndex = currentIndex+1

   end

end

doNextTrans()

[/lua]

Brent

dear lord… thanks a lot. It’s just I need to study and learn proper and efficient syntax coding.