Cocos2d-x v3.9 released!

Regarding “Frame callback function”.

Is it documented or is there an example on how it works? I’ve tried searching the API documentation in the site but couldn’t find anything related to it.

What I want is to have a certain callback called when a frame index is reached in an animation. This new feature, if I understood correctly, seems to do exactly this.

Sorry, you want a callback that is called every frame?

No.

I want a callback which is called at a certain frame.
Example: I have an animation with 5 frames and I want to have a callback called when the animation switches to frame 3 (or any other index which I choose).

Maybe I misunderstood the feature but it seems from the original post that it does this same thing.

edit: I thought this feature was something like: given an Animate action when a certain frame index is reached in its animation a callback would be called.

To do that, I will try something like this:


...
    auto func = CallFuncN::create([&](Node* sender){
        
        //do or call something..
        
    });
    
    sprite->runAction(animWithCallBack(5, 3, func));
....    
Action* XYZ::animWithCallBack(int total, int callat, CallFuncN* func)
{
    Vector<SpriteFrame*> animFrames1;
    Vector<SpriteFrame*> animFrames2;
    
    for(int i = 0; i < total; i++)
    {
        auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(StringUtils::format("amim_%d.png", i));
        if (i < callat)
        {
            animFrames1.pushBack(frame);
        }
        else
        {
            animFrames2.pushBack(frame);
        }
    }

    float duraFrame = 0.1;
    auto animate1 = Animate::create(Animation::createWithSpriteFrames(animFrames1, duraFrame));
    auto animate2 = Animate::create(Animation::createWithSpriteFrames(animFrames2, duraFrame));
    auto seq = Sequence::create(animate1, func, animate2, NULL);
    auto rep = RepeatForever::create(seq);

    return rep;
}

Which platform has this issue?

All of them, it seems. At least iOS, Android and Win32 where I have tested.

Why scrips can be used only in JS/LUA projects?
Why it does not have native support on c++ projs?

2 Likes

sorry, what?

Oh, sorry, i’ve edited my last message.

“Why scrips can be used only in JS/LUA projects?”

You say:
“Lua component can only be used in lua projects, Javascript component can only be used in Javascript projects.”

Why i can’t call lua and js scripts from c++ projs natively?

can I ask the same question for 4th time, and get some answer?
Will in new release be new spidermonkey??? we need speed on js.

are you using my staging version of the Programers Guide?

Let me ask @ricardo to answer this. I am not sure.

@likon @slackmoehrle
We would like to update cocos2d-x to every new Spidermonkey release but is not that easy:

  • spidermonkey breaks its API too frequently. That means:
    • we need to spend time learning the new API
    • it will break backwards compatibility
    • we have to support multiple versions of Spidermonkey
  • Most of the VM improvements are associated with the JIT, that means that iOS users won’t get any performance benefit

That being said, if you really want cocos2d-x to have the latest version of Spidermonkey, please help us by sending a PR. Thanks.

I understand…
you said that most of the improvements are associated with JIT? what does it mean? SpiderMonkey is c++ project what it has anything to do with JIT?

Sorry?
I’ve used some version a long time ago…

Now i can’t found any answers about this question.

You said this. But can you tell me where you see this? I updated the text to explain why. I will be posting a new version soon.

In top of topic

Thanks, I see. I am updating the Programmers Guide with this, so here is a staging version: http://slackmoehrle.github.io/10/index.html

What about changing the spidermonky to something simple as :
http://duktape.org/
Check :
http://duktape.org/guide.html
, no JIT, very fast

@Meir_yanovich
thanks. interesting. Although we need JIT in the rest of the platforms.