dakikifr

Hi Nate.

I've updated my runtime in the hope to use events in my code (I'm using cocos2d-x).
I was previously on CommitID 7d7158894d61c3b37495008ea1f12838d2bebc22 and I'm now on 93c60a0bdf12c05a4de410a2893c19c915ef08ab.

I'm a bit lost with the new code and I'm having multiple issues due to the changes in AnimationState:

1/ My skeleton uses multiple animations.
My old code
Load and init:
#define MAIN_ANIM 0
#define BLINK_ANIM 1
#define EAT_ANIM 2
CCSkeletonAnimation* skeleton = CCSkeletonAnimation::createWithFile("skel.json","skel.atlas");
skeleton->addAnimationState(); // For BLINK_ANIM
skeleton->addAnimationState(); // For EAT_ANIM

// Start animations
skeleton->setAnimation("walk",true,MAIN_ANIM);
skeleton->setAnimation("blink",true",BLINK_ANIM);
Now when some event occurs in my game, I change my main animation, and I want to clear the blink one, I used to do that:
skeleton->setAnimation("run",true,MAIN_ANIM);
skeleton->clearAnimation(BLINK_ANIM); // Stop blinking animation when running
From time to time, I start another animation (not using the same bones than the main one) like this:
skeleton->setAnimation("eat",false,EAT_ANIM);
Now that I've updated the runtime, those functions don't compile, I have to change the code.
Firstly, I removed the 2 addAnimation calls during init.
I've moved the 3rd parameter for all the setAnimation calls, to the 1st one.
Now when the clearAnimation(BLINK_ANIM) is called, I've got an access violation in _TrackEntry_dispose, called from AnimationState_clearTrack, because current->previous is 0xfeeefeee (memory already freed).
I've tried this instead of the clearAnimation call: setAnimation(BLINK_ANIM,NULL,false) but in that case I've got a segfault in _AttachementTimeline_apply, called from CCScheduler::update because self is 0xcccccccc.

Am I doing something wrong? Have I missed the new concept of "tracks" that replaced the animation index?

2/ I'm using a different timeScale for each of my animation tracks
Like we discussed in this thread viewtopic.php?f=7&t=993
I've subclassed the CCSkeletonAnimation class and added a new method:
setStateTimeScale(float scale,int stateIndex) which allowed me to use a different timeScale in the CCSkeletonAnimation::update method.

With the new AnimationState code, how can I achieve what I did before?
I need the MAIN_ANIM to run at a different timeScale than the BLINK_ANIM for example.

Thanks for your time, keep up the good work, you're awesome!
dakikifr

Kickstarter Backer
  • Mesajlar: 40

Nate

I've fixed the crash from current->previous being freed twice. I'm not sure why you crashed in _AttachementTimeline_apply. You should be able to use NULL with set/addAnimation for the animation name.

I think you have got the idea of tracks just fine. It is just like the old multiple AnimationStates, except it is handled inside AnimationState and you don't have to add tracks, you can just use them by index number.

Unfortunately it isn't possible to have a time scale per track. I can add this tomorrow, would it be fine if the scale is per track entry, not per track? Eg, you'd have to set the scale after setting/adding an animation:
TrackEntry* entry = setAnimation(0, "blink", false);
entry->timeScale = 0.5;
// OR
setAnimation(0, "blink", false)->timeScale = 0.5;
// same thing for addAnimation
addAnimation(0, "walk", true, 0)->timeScale = 2;
You could always subclass setAnimation/addAnimation and adjust the scale based on the track index. That work for you?
Kullanıcı avatarı
Nate

Nate
  • Mesajlar: 12208

Nate

Committed time scale. There are two: per AnimationState and per track entry (not track index). :sleepy:
Kullanıcı avatarı
Nate

Nate
  • Mesajlar: 12208

dakikifr

Hi Nate, and thanks again for your quick support.

Unfortunatly it still doesn't work (haven't tested the timeScale code, but it looks like it's exactly what I need).

Taking the latest git version (ba60fb99bddb5b65358dbce314a062c541a19664), and this ExampleLayer.cpp file:
#include "ExampleLayer.h"
#include <iostream>
#include <fstream>
#include <string.h>

using namespace cocos2d;
using namespace spine;
using namespace std;

CCScene* ExampleLayer::scene () {
CCScene *scene = CCScene::create();
scene->addChild(ExampleLayer::create());
return scene;
}

bool ExampleLayer::init () {
if (!CCLayer::init()) return false;

skeletonNode = CCSkeletonAnimation::createWithFile("spineboy.json", "spineboy.atlas");
skeletonNode->setAnimation(0, "walk", true);

CCSize windowSize = CCDirector::sharedDirector()->getWinSize();
skeletonNode->setPosition(ccp(windowSize.width / 2, 20));
addChild(skeletonNode);

scheduleUpdate();

return true;
}
//#define CRASH_ME
void ExampleLayer::update (float deltaTime) {
static float elapsed = 0.0f;
elapsed += deltaTime;

if(elapsed >= 2.0f)
{
#ifdef CRASH_ME
skeletonNode->clearAnimation(0);
#endif /* CRASH_ME */
skeletonNode->setAnimation(0, "jump", true);
}
}
Maybe I missed something, but isn't it possible to change a currently running animation using setAnimation?
Because on my computer, when the 2sec mark is hit the walk animation stops but the boy reverts to setupPose forever and is not jumping.
Additionaly, if you #define CRASH_ME, you'll get the crash I was talking about yesterday (still happening with latest repository).

Any clue? Am I doing something wrong?
What's the new correct way, to change an animation (for the same trackIndex)?

Thanks,
Kiki
dakikifr

Kickstarter Backer
  • Mesajlar: 40

Nate

Your code calls setAnimation every frame once elapsed >= 2. :) You need to call it just once to give the animation time to play.

I fixed the clearAnimation bug, thanks! I also renamed to clearTracks and clearTrack so it would be clearer. ;)
Kullanıcı avatarı
Nate

Nate
  • Mesajlar: 12208

dakikifr

Oups lol didn't see that. Fortunately this was not in my own code :)
I'll try the new clear function thanks, and I'll try to setAnimation(0,NULL) too, since it should do the same thing right?
dakikifr

Kickstarter Backer
  • Mesajlar: 40

Nate

As a result of this:
viewtopic.php?f=9&t=1338&p=6410#p6410
set/addAnimation no longer accept NULL to clear a track.
Kullanıcı avatarı
Nate

Nate
  • Mesajlar: 12208

dakikifr

Every things works perfectly now, thanks again Nate!
dakikifr

Kickstarter Backer
  • Mesajlar: 40

dakikifr

Hi Nate,

what's the best way to change a looping animation timeScale while it's running?

I've an animation I player forever (well, not really but let's just say that), but I sometimes want to change the timeScale for this animation (and only for that trackIndex).

The nice timeScale properties you added for me are great and works very well when "setting" the animation, but how can I change the value sometime later (without having to store the TrackEntry).

1/ Should I setAnimation with the same animation, if that does not reset the animation's position?
2/ Is there a way to get the TrackEntry based on trackIndex, so I can change the timeScale value on the fly (if that work)?

Thanks again for your support!
Kiki
dakikifr

Kickstarter Backer
  • Mesajlar: 40

Nate

Try:
AnimationState_getCurrent(trackIndex)->timeScale = 0.5;
Kullanıcı avatarı
Nate

Nate
  • Mesajlar: 12208

dakikifr

Perfect, thanks again (sorry I didn't see this function by myself, I searched other names but not a simple "getCurrent" :) )
dakikifr

Kickstarter Backer
  • Mesajlar: 40


Dön Runtimes