Tweening from Javascript code block

I am looking for a way to tween between any two values (for example an objects position, but it could be anything else, perhaps an .alpha value or otherwise) in a JS code block.

  • that I could initialise with a starting and end value
  • that I could get a function() method that executes for each ‘tick’ on its way
  • that I could get a callback() method when it completes
  • that I could have a method to .cancel/stop the tween event midway if needed.

Is there such a way ? any examples around that do this ?

1 Like

I have added ‘tween’ behaviour to an object, and can use the tween commands in the event manager, but i want to force an object to initiate/stop tweens in the JS code, anyone know how to reference these tween behaviours from code ?

1 Like

@Wendigo maybe ?

Résumé

…Le message doit avoir au moins 20 caractères…

I have the same question and cant seem to find an answer anywhere. How do tween to a new position in a javascript block and not using events.

Just found out how. The object must have a tween behavior attached.

// get object by its name
const obj = runtimeScene.getObjects(objectName)[0];

// get attached tween behavior
let tween = obj.getBehavior("Tween");

// create a tween identifier using the object name
const tweenYName = obj.name + "PositionYTween";

// run the tween
tween.addObjectPositionYTween(tweenYName, 2000, "linear", 1000, false);

To check how to call tween functions, see this documentation page.

2 Likes

You are a legend! - over 3 years later and an answer appears! :smiley: I might still come back to GDevelop if there are heroes like you hanging around!

1 Like

Luckily you still have the same email address apparently :smile:

1 Like

I started to play with GDevelop recently. Don’t know how much it changed since 3 years ago, but I agree that a lot of questions remained unanswered. Glad I could help.