Jump to content

Cocos2d-x 2.2.2 Spriter Implementation


Recommended Posts

Hello all. I wanted to implement Spriter into Cocos2d-x 2.2.2, so I scoured these forums and the internet, but wasn't too happy with the results. Generic C++ implementations and old Cocos2d-x implementations that weren't really set up to do things the "Cocos2d-x" way, meaning they weren't fully utilizing the CCNode hierarchy for transforms. I'm still working on this thing, but I wanted to go ahead and share it in its current state. Simple sprite and bone animations are functional: translation, rotation, scale, and colorizing.

Please note that some of the files in the attached archive need to be merged into the existing engine code. Also, for some reason unbeknownst to me, Cocos2d-x is set up to use reversed rotations(positive being clockwise), which I decided to change at the core level of the engine. Obviously this could break a lot of the built in tools, so some of you may want to just inverse the rotations in the Spriter implementation instead.

You can use this implementation like you do anything else in Cocos2d-x:

	CCSpriter* spriterTest = CCSpriter::create("anim/player/Player.scml");
spriterTest->setPosition(CCPointMake(512.0f, 384.0f));
addChild(spriterTest, 5);

My future plans for this are:

  • [*:1jditbpz]Add support for zindex
    [*:1jditbpz]Add support for parent swapping
    [*:1jditbpz]Add support for texture swaps(may already work, needs testing)
    [*:1jditbpz]Add support for default file defined pivots
    [*:1jditbpz]Add support for adding/removing sprites and bones during animation
    [*:1jditbpz]Add support for plists

Not sure how much further I'm going to go with it beyond that, but this should lay a good groundwork for someone to make it "fully featured". Because this is loosely based on work done by BruceWang and 568083142 on this forum, which was based on work done by James Hui (a.k.a. Dr.Watson), I've stuck with the BSD License.

CCSpriter.zip

Link to comment
Share on other sites

Well, supporting a number of those features actually went by pretty quickly. I don't plan on improving this for the next few weeks/months, except for any bugs that need fixing. The only thing from my list that I haven't implemented is the Plists support, as I'm not going to need that for a while. Here's a list of what I have done:

  • [*:6jyn9yxw]Added support for z index changes
    [*:6jyn9yxw]Added support for parent changes
    [*:6jyn9yxw]Added support for default file defined pivots
    [*:6jyn9yxw]Added support for adding/removing sprites and bones during animation
    [*:6jyn9yxw]Added support for nodes without animation
    [*:6jyn9yxw]Added memory cleanup on destroy

If you encounter any bugs, please let me know. Also, if you could attach an example SCML file that exemplifies the bug, I'll do my best to fix it quickly.

CCSpriter.zip

Link to comment
Share on other sites

  • 3 months later...
  • 3 months later...
  • 1 year later...
  • 1 month later...

I think it's a misprint

spriter/CCSpriterKey.cpp

CCSpriterTimelineVisualKey* CCSpriterTimelineVisualKey::create(XMLNode* node, int& index)
{
   ...
   		if (objectElement->QueryFloatAttribute("pivot_y", &floatValue) == XML_SUCCESS)
			key->m_vecPivot.y = floatValue;
		else
			key->m_vecPivot.x = -9000.0f; // <--------------- line 206
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...