Move control with velocity

Questions and information about using Lua scripting with Storyboard

Moderator: jamiev

Move control with velocity

Postby atinir » Fri May 27, 2016 8:36 am

Hi :)

Is it possible to move a control with predefined velocity using LUA scripting?

Thanks :)
atinir
 
Posts: 25
Joined: Thu Apr 21, 2016 9:20 am

Re: Move control with velocity

Postby nschultz » Fri May 27, 2016 8:56 am

Hello Atinir,

Yes you can certainly accomplish this by creating an animation in lua. The lua api's available allow you to build up animations programmatically with the same level of control that you would have if you created them in the design tools.

Here is a link to the documentation where it describes how you would go about doing this.

http://www.cranksoftware.com/cranksoftw ... ml#d0e8812

Please take a look let me know if you have any questions.

Nik
nschultz
 
Posts: 26
Joined: Fri Jul 17, 2015 1:51 pm

Re: Move control with velocity

Postby atinir » Fri Aug 19, 2016 11:16 am

Thank you very much Nik ;) . I'll try it.
atinir
 
Posts: 25
Joined: Thu Apr 21, 2016 9:20 am

Re: Move control with velocity

Postby atinir » Wed Sep 07, 2016 7:02 am

Hi Nik,

I am using the animation function to move the control with constant velocity. The animation is triggered when I press a key, gre.keydown.
What I am trying to do is, by holding the key pressed, the control to move with constant velocity.. But when I hold the key pressed, the control moves constantly then it slows then again moves with constant velocity.
How can I do it so when user presses the key the control moves with constant velocity, but also when it holds the key pressed also it moves with constant velocity.

Thank you!

All the best, :)
atinir
 
Posts: 25
Joined: Thu Apr 21, 2016 9:20 am

Re: Move control with velocity

Postby nschultz » Wed Sep 07, 2016 8:46 am

Hello Atinir,

Just so I'm clear on what you are trying to accomplish could you confirm if you are looking for logic similar to this:

-press -> animation starts
-hold -> animation continues at a constant rate
-release -> animation stops or slows down

If so you are looking to build more complex logic, instead of using animations you might want to use timers to "animate" the controls position.
For example on press start the timer and on every iteration of the callback modify the position of your control, when you release change a state variable
which will control the behaviour of the callback and do any required timer cleanup. You will likely have to do a bit of math if you want to achieve ease-in and ease-out
style of transitions on press and release.

Please let me know if I've correctly understood what you are looking to do

Nik
nschultz
 
Posts: 26
Joined: Fri Jul 17, 2015 1:51 pm

Re: Move control with velocity

Postby atinir » Wed Sep 07, 2016 2:56 pm

Hi Nik,

Thank you for your suggestion. That is what I want to do, press key control moves with constant velocity then release key, control stops. I will try the thing with timer.
In the link that you post it, there as an example to slide the control only on x-axis, is it possible to do for x and y at the same time? I tired to define data["key"] = "mylayer.mycontrol.grd_x" and data["key"] = "mylayer.mycontrol.grd_y", but it does not work.

function create_animation(mapargs)
local data = {}

-- slide the x position 400 pixels over 2000 msec and auto-destroy
-- it on completion
id = gre.animation_create(60, 1)
data["rate"] = "linear"
data["duration"] = 2000
data["offset"] = 0
data["delta"] = 400
data["key"] = "mylayer.mycontrol.grd_x"
gre.animation_add_step(id, data)
end

Thank you :) All the best
atinir
 
Posts: 25
Joined: Thu Apr 21, 2016 9:20 am

Re: Move control with velocity

Postby nschultz » Wed Sep 07, 2016 3:43 pm

Hello Atinir,

Yes you can change multiple properties at once with animation or timers. In the code snippet you provided you would simply need to add a new step, so you could add the following after your call to gre.animation_add_step

data["delta"] = <whatever y position you want>
data["key"] = "mylayer.mycontrol.grd_y"
gre.animation_add_step(id, data)

You need to call "animation_add_step(id, data)" again to add the new step. Keep in mind that when we reuse "data" it will keep all the keys we had set previously so make sure you override everything that you need.

If you were to do this with data sets in a timer call back you would simply do the same thing but pass your data table into gre.set_data.

Cheers

Nik
nschultz
 
Posts: 26
Joined: Fri Jul 17, 2015 1:51 pm


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 2 guests

cron