createzone

【Question】
Can I set position of path constraint by code?
スクリーンショット 2021-06-21 11.47.44.png


If so, How can I do?

【current status】
1. spine file
It has one path which has one bone, and this bone's path constraint's position is 35%.

2. code for get path constraint's position
console.log("path constraint's position : " + this.skel?._skeleton.pathConstraints[0].position);
And it is success.
スクリーンショット 2021-06-21 11.43.27.png
У вас нет необходимых прав для просмотра вложений в этом сообщении.
createzone
  • Сообщения: 73

Nate

Yes, you can. You just get a reference to the path constraint and change the position. If your position is using the percent mode, you'd set it to eg 0.45 for 45%. Note if you have an animation that keys the path constraint position, you'd probably want to change it via code after applying the animation.
this.skel?._skeleton.pathConstraints[0].position = 0.45;
Аватара пользователя
Nate

Nate
  • Сообщения: 11399

createzone

Thank you, Nate.

One more question.
I try the code like this :
this.skel?.setAnimation(0, "animation1", true);
console.log("path constraint's position : " + this.skel?._skeleton.pathConstraints[0].position);
this.skel?._skeleton.pathConstraints[0].position = 0.45;
console.log("path constraint's position after set position : " + this.skel?._skeleton.pathConstraints[0].position);
https://gist.github.com/j-park-serori/37c0b116feff134c7923372a716ccc8a

And have error like this.
スクリーンショット 2021-06-21 13.20.15.png


In this case,
what is my missing point?

---

It solved!

I just change the code from
this.skel?._skeleton.pathConstraints[0].position = 0.45;
to
this.skel!._skeleton.pathConstraints[0].position = 0.45;
У вас нет необходимых прав для просмотра вложений в этом сообщении.
createzone
  • Сообщения: 73

Nate

Cool, glad you figured it out!
Аватара пользователя
Nate

Nate
  • Сообщения: 11399


Вернуться в Runtimes