Slow down animation with a button press

Hi.

I’m having some issues with slowing down the speed of my scrolling back ground with a button press and then restoring the original speed once you depress. So far I’ve been using simple Transitions that loop once they go a curtain distance off the screen.

This has not been working for me, I just get choppy breaks and it does not restore to the correct position.

Any help would be appreciated!

[code]
local function speedChange(event)

if event.phase == “began” then

mountain_big.x = mountain_big.x - xOffset*0.100

elseif ( event.phase == “ended” or event.phase == “canceled” ) then

mountain_big.x = mountain_big.x - xOffset

end
end
[import]uid: 66329 topic_id: 19022 reply_id: 319022[/import]

Rather than the way your doing it.

Create a speed variable

ie :

local speed = 1  

then have that speed move your background, on button press increase the speed, on release decrease it :slight_smile: [import]uid: 84637 topic_id: 19022 reply_id: 73358[/import]

How exactly would I assign this variable? I’m using some of the code from the Horse animation template.
changing the “xOffset” changes the speed of that layer
Thanks!

[code]
local xOffset = ( 0.2 * tDelta )

[import]uid: 66329 topic_id: 19022 reply_id: 73379[/import]

Something like (code below should work out of the box) :

  
local offSets = {  
 [1] = {x = 0.2 \* tDelta \*0.100},  
 [2] = {x = 0.2 \* tDelta},  
}  
  
local theOffset = offSets[1].x  
  
local function speedChange(event)   
  
 if event.phase == "began" then  
 theOffSet = offSets[1].x   
 elseif ( event.phase == "ended" or event.phase == "canceled" ) then  
 theOffSet = offSets[2].x   
 end  
  
 mountain\_big:translate(-theOffSet, 0)  
  
 return true  
end   

[import]uid: 84637 topic_id: 19022 reply_id: 73761[/import]