I’m trying to get this cloud to move right, then after it has done that move back across the screen. How can i go about doing this?
Please share code as text instead of as an image! You can use the Preformatted text option to get nice formatting as well.
You should not put a while loop in your code like that. It will block the whole main thread. Also note that a call to gui.animate() will start the animation and then continue on with the next line of code.
function init(self)
msg.post(".", “acquire_input_focus”)
local move = false
local Cloud1 = gui.get_node("Cloud1")
local Cloud2 = gui.get_node("Cloud2")
local right_edge = vmath.vector3(1024,580,0)
local left_edge = vmath.vector3(-64,580,0)
gui.animate(Cloud1, hash("position.x"), right_edge, gui.EASING_LINEAR, 10)
gui.animate(Cloud2, hash("position.x"), left_edge, gui.EASING_LINEAR, 8)
end
This gets one cloud to move from right to left and on from left to right, but I want them to repeat doing that until a button is pressed taking the player somewhere else.
You can set the playback to gui.PLAYBACK_LOOP_PINGPONG
to have it move back and forth forever, then use gui.cancel_animation()
to stop it later.
I’ve just tried that and it doesn’t repeat, just does it once, and they don’t move at a constant speed.
Can you share the updated code? And please check the editor console for errors.
function init(self)
msg.post(".", “acquire_input_focus”)
local move = false
local Cloud1 = gui.get_node("Cloud1")
local Cloud2 = gui.get_node("Cloud2")
local right_edge = vmath.vector3(1024,580,0)
local left_edge = vmath.vector3(-64,580,0)
gui.animate(Cloud1, hash("position.x"), right_edge, gui.PLAYBACK_LOOP_PINGPONG, 10)
gui.animate(Cloud2, hash("position.x"), left_edge, gui.PLAYBACK_LOOP_PINGPONG, 8)
end
there is no errors in the console
should be
gui.animate(Cloud1, hash("position.x"), right_edge, gui.EASING_LINEAR, 10, nil, nil, gui.PLAYBACK_LOOP_PINGPONG)
gui.animate(Cloud2, hash("position.x"), left_edge, gui.EASING_LINEAR, 8, nil, nil, gui.PLAYBACK_LOOP_PINGPONG)
now they aren’t moving at all
with this error:
bad argument #6 to ‘animate’ (number expected, got nil)
stack traceback:
[C]: in function 'animate
@Jimbo_Evans and @Potota: please take a look at the definition of go.animate in the API, both of you are calling go.animate with wrong parameters
I believe it is an animation of a GUI node, not a game object.
The second argument should either be a string or a constant such as gui.PROP_POSITION, not a hash. Try:
gui.animate(Cloud1, "position.x", right_edge, gui.PLAYBACK_LOOP_PINGPONG, 10)
My fault… sorry! Never used gui
I’ve tried that, the clouds move once, but then don’t move again. They also aren’t moving at a constant speed.
local Cloud1 = gui.get_node(“Cloud1”)
local Cloud2 = gui.get_node(“Cloud2”)
local right_edge = vmath.vector3(1024,580,0)
local left_edge = vmath.vector3(-64,580,0)
gui.animate(Cloud1, “position.x”, right_edge, gui.PLAYBACK_LOOP_PINGPONG, 10)
gui.animate(Cloud2, “position.x”, left_edge, gui.PLAYBACK_LOOP_PINGPONG, 8)
You’re still mixing up easing and playback
gui.animate(Cloud1, "position.x", right_edge, gui.EASING_LINEAR, 10, nil, nil, gui.PLAYBACK_LOOP_PINGPONG)
gui.animate(Cloud2, "position.x", left_edge, gui.EASING_LINEAR, 8, nil, nil, gui.PLAYBACK_LOOP_PINGPONG)
Ah, yes, that is absolutely correct!
Now they don’t move at all.
Did you change place on easing and playback?
This works and is confirmed in a small sample project:
function init(self)
local Cloud1 = gui.get_node("Cloud1")
local Cloud2 = gui.get_node("Cloud2")
local right_edge = vmath.vector3(1024,580,0)
local left_edge = vmath.vector3(-64,580,0)
gui.animate(Cloud1, hash("position.x"), right_edge, gui.EASING_LINEAR, 10, 0, nil, gui.PLAYBACK_LOOP_PINGPONG)
gui.animate(Cloud2, hash("position.x"), left_edge, gui.EASING_LINEAR, 10, 0, nil, gui.PLAYBACK_LOOP_PINGPONG)
end
Thank you, now works perfectly. I had removed the hash like in the previous replies which made it not work. Thank you.