Skip to content

Commit

Permalink
Updated cocos2d-x to 2.0.3, added flipping x-axis ability, and readin…
Browse files Browse the repository at this point in the history
…g in scale x/y from .scml file, and finally re-exported .scml file to a6 with minor modifications on monster character.
  • Loading branch information
haxpor committed Oct 26, 2012
1 parent 57a00fd commit 225faa6
Show file tree
Hide file tree
Showing 294 changed files with 15,813 additions and 4,930 deletions.
2,678 changes: 1,426 additions & 1,252 deletions Spriter-Cocos2d-X.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "1.0">
</Bucket>
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0450"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D5912FD915F517FE00CEF463"
BuildableName = "Spriter-Cocos2d-X.app"
BlueprintName = "Spriter-Cocos2d-X"
ReferencedContainer = "container:Spriter-Cocos2d-X.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D5912FD915F517FE00CEF463"
BuildableName = "Spriter-Cocos2d-X.app"
BlueprintName = "Spriter-Cocos2d-X"
ReferencedContainer = "container:Spriter-Cocos2d-X.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D5912FD915F517FE00CEF463"
BuildableName = "Spriter-Cocos2d-X.app"
BlueprintName = "Spriter-Cocos2d-X"
ReferencedContainer = "container:Spriter-Cocos2d-X.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D5912FD915F517FE00CEF463"
BuildableName = "Spriter-Cocos2d-X.app"
BlueprintName = "Spriter-Cocos2d-X"
ReferencedContainer = "container:Spriter-Cocos2d-X.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Spriter-Cocos2d-X.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>D5912FD915F517FE00CEF463</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
42 changes: 32 additions & 10 deletions Spriter-Cocos2d-X/Classes/HelloWorldScene.cpp
@@ -1,6 +1,5 @@
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
#include "SpriterNode.h"

using namespace cocos2d;
using namespace CocosDenshion;
Expand Down Expand Up @@ -29,21 +28,27 @@ bool HelloWorld::init()
{
return false;
}

SpriterNode *n = SpriterNode::create( "Example.SCML" );

n->setPosition( ccp(200, 100) );
n->runAnimation( "Idle" );
// create a label to tell who see the demo
CCLabelTTF* label = CCLabelTTF::create("Flip X every 2 seconds.\nLeft monster should have bigger head.", "Thonburi", 30);
CCSize size = CCDirector::sharedDirector()->getWinSize();
label->setPosition( ccp(size.width / 2, size.height - 40) );
this->addChild(label, 1);

n1 = SpriterNode::create( "Example.SCML" );
n1->setPosition( ccp(200, 100) );
n1->runAnimation( "Idle" );

this->addChild( n );
this->addChild( n1 );

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile( "monster.plist" );
n = SpriterNode::create( "Example.SCML", "monster.png" );
n2 = SpriterNode::create( "Example.SCML", "monster.png" );

n->setPosition( ccp(600, 100) );
n->runAnimation( "Posture" );
n2->setPosition( ccp(600, 100) );
n2->runAnimation( "Posture" );

this->addChild( n );
this->addChild( n2 );
this->schedule(schedule_selector(HelloWorld::_flipSpriteX), 2);

return true;
}
Expand All @@ -56,3 +61,20 @@ void HelloWorld::menuCloseCallback(CCObject* pSender)
exit(0);
#endif
}

void HelloWorld::_flipSpriteX(float df)
{
// switch back and forth for flipping
if(n1->getIsFlipX() && n2->getIsFlipX())
{
n1->setIsFlipX(false);
n2->setIsFlipX(false);
}
else if(!n1->getIsFlipX() && !n1->getIsFlipX())
{
n1->setIsFlipX(true);
n2->setIsFlipX(true);
}

CCLog("Called _flipSprite()");
}
6 changes: 6 additions & 0 deletions Spriter-Cocos2d-X/Classes/HelloWorldScene.h
Expand Up @@ -2,6 +2,7 @@
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "SpriterNode.h"

class HelloWorld : public cocos2d::CCLayer
{
Expand All @@ -17,6 +18,11 @@ class HelloWorld : public cocos2d::CCLayer

// implement the "static node()" method manually
CREATE_FUNC(HelloWorld);

private:
SpriterNode *n1, *n2;

void _flipSpriteX(float df);
};

#endif // __HELLOWORLD_SCENE_H__
88 changes: 84 additions & 4 deletions Spriter-Cocos2d-X/Classes/SpriterNode.cpp
Expand Up @@ -230,6 +230,26 @@ void SpriterTimelineKey::setSpin(int spin)
_spin = spin;
}

double SpriterTimelineKey::getScaleX()
{
return _scaleX;
}

void SpriterTimelineKey::setScaleX(double scaleX)
{
_scaleX = scaleX;
}

double SpriterTimelineKey::getScaleY()
{
return _scaleY;
}

void SpriterTimelineKey::setScaleY(double scaleY)
{
_scaleY = scaleY;
}

SpriterAnimation::SpriterAnimation()
{
_mainline = new CCArray();
Expand Down Expand Up @@ -299,6 +319,8 @@ CCArray* SpriterAnimation::getTimelines()

SpriterNode::SpriterNode()
{
_playbackSpeed = 1.0;

_configRoot = NULL;
_curConfigNode = NULL;

Expand Down Expand Up @@ -503,6 +525,25 @@ void SpriterNode::initObjects()
timelineKey->setStartsAt(key->getPropertyCCString("time")->doubleValue());
timelineKey->setRotation(object->getPropertyCCString("angle")->doubleValue());

if(object->getPropertyCCString("scale_x")->doubleValue())
{
timelineKey->setScaleX(object->getPropertyCCString("scale_x")->doubleValue());
}
else
{
timelineKey->setScaleX(1.0);
}

if(object->getPropertyCCString("scale_y")->doubleValue())
{
timelineKey->setScaleY(object->getPropertyCCString("scale_y")->doubleValue());
}
else
{
timelineKey->setScaleY(1.0);
}


if (key->getPropertyCCString("spin")->intValue())
{
timelineKey->setSpin(key->getPropertyCCString("spin")->intValue());
Expand Down Expand Up @@ -591,11 +632,11 @@ void SpriterNode::update(float dt)

_duration += dt;

int milliseconds = _duration * 10000;
int milliseconds = _duration * 10000 * _playbackSpeed;
int startTime = _curKeyFrame->getStartsAt();
int endTime = _nextKeyFrame->getStartsAt();

if (endTime)
if (endTime == 0.0f)
{
endTime = _curAnimation->getDuration();
}
Expand All @@ -610,8 +651,8 @@ void SpriterNode::update(float dt)
}
if (milliseconds > _curAnimation->getDuration())
{
_duration -= milliseconds * 0.0001;
milliseconds -= 10000;
_duration -= milliseconds * 0.0001/_playbackSpeed;
milliseconds -= 10000 * _playbackSpeed;
}

for (int i=0; i<_spriteNodes->count(); i++)
Expand Down Expand Up @@ -670,6 +711,9 @@ void SpriterNode::update(float dt)
interpolate(curTimelineKey->getAnchorPoint().x, nextTimelineKey->getAnchorPoint().x, interpolationFactor),
interpolate(curTimelineKey->getAnchorPoint().y, nextTimelineKey->getAnchorPoint().y, interpolationFactor)));

sprite->setScaleX(interpolate(curTimelineKey->getScaleX(), nextTimelineKey->getScaleX(), interpolationFactor));
sprite->setScaleY(interpolate(curTimelineKey->getScaleY(), nextTimelineKey->getScaleY(), interpolationFactor));

double nextRotation = nextTimelineKey->getRotation();
double curRotation = curTimelineKey->getRotation();

Expand All @@ -682,6 +726,20 @@ void SpriterNode::update(float dt)
nextRotation -= 360;
}

// check to flip
if(_isFlipX)
{
// position
sprite->setPosition(CCPointMake(-sprite->getPosition().x, sprite->getPosition().y));

// scale
sprite->setScaleX(-sprite->getScaleX());

// rotation
nextRotation *= -1;
curRotation *= -1;
}

sprite->setRotation( - interpolate(curRotation, nextRotation, interpolationFactor) );
}
}
Expand All @@ -693,4 +751,26 @@ double SpriterNode::interpolate(double a, double b, double f)
if (f > 1) { f = 1.0; }
if (f == NAN) { f = 1.0; }
return a+(b-a)*f;
}

double SpriterNode::getPlaybackSpeed()
{
return _playbackSpeed;
}

void SpriterNode::setPlaybackSpeed(double pSpeed)
{
if(pSpeed != _playbackSpeed)
_playbackSpeed = pSpeed;
}

bool SpriterNode::getIsFlipX()
{
return _isFlipX;
}

void SpriterNode::setIsFlipX(bool b)
{
if(b != _isFlipX)
_isFlipX = b;
}

0 comments on commit 225faa6

Please sign in to comment.