Stuck!! Trying to affect a screen asset that's already commited to a movement cycle

Hi everyone… I have a graphic in the background of my app that’s moving (slowly):

[lua]
local function animateCloudSlow ( event )
cloud.rotation = cloud.rotation + 0.0003
cloud.x = cloud.x - 0.008
cloud.y = cloud.y + 0.03
cloud.xScale = cloud.xScale + 0.00001
cloud.yScale = cloud.yScale + 0.00001
[/lua]

This is triggered by a runtime listener and as you can see, it’s not doing much…

The problem arises when I want to affect (update) those parameters… I’m trying to get one of my function-buttons (using an object event listener) to basically accelerate all of those variables by having it trigger an alternative function with different settings. But it won’t, for a reason I don’t understand yet, override the original function… If I make large changes like " cloud.xScale = cloud.xScale + 2", it does have an effect, but it’s immediate, rather than a gradual change.

As this screen object belong to one of many ‘parallax’ groups, I don’t want to use ‘transition.to’, so I’m a bit stuck.

Any help will be gratefully appreciated.

Best regards

Mark [import]uid: 176868 topic_id: 37480 reply_id: 67480[/import]

Hi Mark,

I think we’ll need a bigger picture of your code to help you out. Can you post a bit more?

Cheers,
Thomas [import]uid: 70134 topic_id: 37480 reply_id: 145656[/import]

Hi @markr1,
Can you just set the “movement” values to variables and adjust them on the fly? Like this:

local scaleVal = 0.00001  
  
local function animateCloudSlow ( event )  
 cloud.xScale = cloud.xScale + scaleVal  
 cloud.yScale = cloud.yScale + scaleVal  
end  
  
local function adjustScale()  
 scaleVal = 0.0006  
end  
timer.performWithDelay( 2000, adjustScale, 1 )  

Otherwise, you can remove the Runtime listener on this function and add a new Runtime listener that points to an alternative (faster-scaling) function. But that design gets a bit clumsy, so the first option is probably better if it fits the design concept of your app.

Brent [import]uid: 200026 topic_id: 37480 reply_id: 145657[/import]

Thanks Brent, I totally forgot about scaleVal… I actually used an ‘elseif’ in the end… I put the ‘two’ sets of variables in the same block, one executed if the button was ‘pressed’ the other if it wasn’t. Your solution is more elegant though. Thanks. [import]uid: 176868 topic_id: 37480 reply_id: 145668[/import]

Hi Mark,

I think we’ll need a bigger picture of your code to help you out. Can you post a bit more?

Cheers,
Thomas [import]uid: 70134 topic_id: 37480 reply_id: 145656[/import]

Hi @markr1,
Can you just set the “movement” values to variables and adjust them on the fly? Like this:

local scaleVal = 0.00001  
  
local function animateCloudSlow ( event )  
 cloud.xScale = cloud.xScale + scaleVal  
 cloud.yScale = cloud.yScale + scaleVal  
end  
  
local function adjustScale()  
 scaleVal = 0.0006  
end  
timer.performWithDelay( 2000, adjustScale, 1 )  

Otherwise, you can remove the Runtime listener on this function and add a new Runtime listener that points to an alternative (faster-scaling) function. But that design gets a bit clumsy, so the first option is probably better if it fits the design concept of your app.

Brent [import]uid: 200026 topic_id: 37480 reply_id: 145657[/import]

Thanks Brent, I totally forgot about scaleVal… I actually used an ‘elseif’ in the end… I put the ‘two’ sets of variables in the same block, one executed if the button was ‘pressed’ the other if it wasn’t. Your solution is more elegant though. Thanks. [import]uid: 176868 topic_id: 37480 reply_id: 145668[/import]