pixijs / spine

Pixi.js plugin that enables Spine support.
Other
564 stars 217 forks source link

Jump to time? #280

Open Friksel opened 5 years ago

Friksel commented 5 years ago

I'd like to control SpineAnimations with either Greensock tweens (TimelineMax or TweenMax) or interactive locations like mouse or touch so I was looking for an update() method to manually show a certain frame or time of the animation.

To do this I set autoUpdate() to false and use the update() method to manually update animations to a state in the animation. Like a tip I found here (https://github.com/pixijs/pixi-spine/issues/164) it's easy to connect TweenMax to it. But it's not really convenient because we always have to keep track of and calculate the deltatime instead of direcly entering a target-time of the state we're after. This is especially the case when binding mousepositions to a static animation-state to animate using a mouse. And there are more examples where it would be a lot easier to just be able to enter a time here instead of having to keep track of the last update-time for all animations we control this way.

Is there some way build in pixi-spine that lets us go directly to a position in the animation? Or else, would it be possible to add a method to jump directly to a time in the animation? Something like jumpToTime(sec)? That would make things a lot easier and cleaner to use for a lot of usecases and make the spine runtime even greater than it is already!

Thanks!

ivanpopelyshev commented 5 years ago

Good idea! I'd like to see your PR on that, and I'll add your weenmax examples here.

Theoretically, there is no problem, you can just add something to AnimationState and see if animations work with it.

macguffin commented 5 years ago

You can do it using update(stopTime) but as this adds the stopTime to the current delta time you just need to set the trackTime = 0 before you call it.

Something like this..

animation.state.tracks[0].trackTime = 0;
animation.update(gotoTime);

It's possible to get the time for each frame from:

animation.state.tracks[0].animation.timlines
Friksel commented 5 years ago

@ivanpopelyshev I thought this would be a very easy addition, because in my mind it was just a matter of adding a new method which underwater keeps track of the last time it updated with the update() method, looks at the current time and adds the difference between the two as a parameter to a call to the update() method which uses delta-time. So I was surprised to see your response was to make a PR for this, 'cause I don't know anything on this lib and though to me it seemed like this would be a five minute job for somebody that knows the lib inside out. With all respect of course, cause I know as a developer nothing is ever going to be 'only five minutes', so I understand. Just thought it wasn't that much of a difficult request.

I took a look at the code and it seems like there is a lot going on in the update() method which for me as an outsider takes a lot of time to figure out first to prevent making bugs. I tried some things to see if there's a quick way to do this, but I am really missing the time and the knowledge of the lib and it would take me some time to dive into this deeper first. Time I don't have at the moment. I also didn't know about 'tracks' and see them for the first time in the lib and I have to figure out how to clone the project and edit it in my NPM-workflow which I never did before. So for me it would be way too much effort for 'such a simple request' (again with respect) which seems not to be hard for somebody knowing the lib and has the workflow setup compared to me not having time for it nor the knowledge of the lib and the workflow setup.

That said; I know where you're coming from and why you asked for a PR. Just thought it was a simple thing. Guess I was wrong. Can't say 'maybe later', because I'm just full of work for the following weeks, so that wouldn't be realistic I'm afraid. But who knows.

Anyway, keep up the great work!

ivanpopelyshev commented 5 years ago

With all respect of course, cause I know as a developer nothing is ever going to be 'only five minutes', so I understand. Just thought it wasn't that much of a difficult request.

Many of my answers are both sarcastic and serious, because I dont know whether to laugh or cry at those problems. I cant actually measure if its easy or hard, I guess we have to wait when someone has an Eureka moment. Sometimes there's an answer that was discovered a week before, sometimes I find solution for things that were requested a year ago.

You've got it right. All that complex thoughts I zip into one small sentence, and not everyone understands that process like you do.

Maybe correct answer should be "I don't see why it isn't possible but there's not enough research, we have to look around for some time before make an attempt". What do you think?

ivanpopelyshev commented 5 years ago

Btw, "like = unlike" in previous post. I meant positive, I dont feel double-negative rules in english.

In russian language for question "Do you want tea?" you might get answer "Yes no maybe".

It is only 4PM of Friday and I'm already fuzzy with words.

Friksel commented 5 years ago

@ivanpopelyshev Not shure if and what you're asking me now, but seems like we're on the same page.

ivanpopelyshev commented 5 years ago

You can also join kotlinlang slack and pester @badlogic about that idea :)

Friksel commented 5 years ago

@ivanpopelyshev I'm sorry. Guess we're having some miscommunications here; I completely lose you and don't have a clue what you're trying to say or ask last posts. To be clear: I'm perfectly fine with the feature not being implemented and understand you have reasons for that which is perfectly fine to me and very understandable and I think we're on the same page. Next to that Im a little too busy for some time now and coming weeks for chit chatting. No offense

ivanpopelyshev commented 5 years ago

No, you've got it right. I mean, in general, the feature is not about pixi runtime, its more about original spine runtime, and you can present it to @badlogic and maybe he knows that someone already implemented it, for example, for Unity.

Friksel commented 5 years ago

Ok, now I understand. Thanks. That's cleared up than.

jrainlau commented 3 years ago

You can jump to any time of the animation by setting the animationStart and animationEnd to the same time:

animation.state.tracks[0].animationStart = 1.5
animation.state.tracks[0].animationEnd = 1.5

now the animation was paused and freezing in 1.5(s)

Friksel commented 3 years ago

You can jump to any time of the animation by setting the animationStart and animationEnd to the same time

Not sure about that though. Looks to me as if it will loop that frame and so stays busy?