Is there a way/javascript code to store and repeat a position an object?

Jun 26, 2021

Hi all, 

I am designing a game in which the learner needs to drag a group of objects to an area. After moving to the next level/slide I need to keep all the changes the learner made as is.

 

Now, two challenges are here: 

 

First, getting the positions of the objects. 

Second, moving the objects to the latest positions. 

 

So .. any help here is highly appreciated. 

 

Thank you .. 

4 Replies
Math Notermans

Best to share a sample to work from...then i can show it properly. If using SL360 you can use GSAP's get functionality.

Here some help on GSAP...
A clear explanation of the position parameter...
https://greensock.com/blog/learning/position-parameter/

And then you offcourse need to get the current dynamic position..
https://greensock.com/docs/v3/GSAP/gsap.getProperty()

So with code like this you can get the actual x and y of an element.

var myElement = document.querySelector("[data-acc-text='someAccName']");
var elXPos = gsap.getProperty(myElement, "x", "px");
var elYPos = gsap.getProperty(myElement, "y", "px");
console.log("x: "+elXPos+" | y: "+elYPos);

Where 'someAccName' is the accessibility name of your element.

Kind regards,
Math