关于cocos2d x权威指南-x中demo的使用

关于Cocos2d-x中demo的使用_百度知道
关于Cocos2d-x中demo的使用
提问者采纳
自己新建个项目再把CLASS和RES文件夹完全替换,可能要在项目里添加.cpp和.h 运行里面的文件就可以在VS里添加项目了
提问者评价
其他类似问题
cocos2d的相关知识
按默认排序
其他1条回答
自己新建个项目再把CLASS和RES文件夹完全替换,可能要在项目里添加.cpp和.h 运行里面的文件就可以在VS里添加项目了
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁欢迎大家访问游戏开发网,有您更美好!
请记住本站网址,一定要搜藏哦亲!
Cocos2d-x 示例ClippingNodeTest之ScrollViewDemo、ShapeTest实现浅析
Cocos2d-x 示例ClippingNodeTest之ScrollViewDemo、ShapeTest实现浅析
围观163次 评论关闭 编辑日期: 字体:
1、ScrollViewDemo
此例子效果是点击遮罩区域后鼠标拖动精灵,精灵会根着一起移动,移动效果是利用触摸事件和精灵的setPostion位置来达到效果,遮罩是使用ClippingNode和DrawNode结合实现的,效果图:
代码比较简单,并且都是基本知识,如下:
void ScrollViewDemo::setup()
auto clipper = ClippingNode::create();
clipper-&setTag( kTagClipperNode );
clipper-&setContentSize(
Size(200, 200) );
clipper-&setAnchorPoint(
Point(0.5, 0.5) );
clipper-&setPosition( Point(this-&getContentSize().width / 2, this-&getContentSize().height / 2) );
clipper-&runAction(RepeatForever::create(RotateBy::create(1, 45)));
this-&addChild(clipper);
auto stencil = DrawNode::create();
//四边形四个顶点
Point rectangle[4];
rectangle[0] = Point(0, 0);
rectangle[1] = Point(clipper-&getContentSize().width, 0);
rectangle[2] = Point(clipper-&getContentSize().width, clipper-&getContentSize().height);
rectangle[3] = Point(0, clipper-&getContentSize().height);
Color4F white(1, 1, 1, 1);
stencil-&drawPolygon(rectangle, 4, white, 1, white);
//用四边形来当模板遮罩
clipper-&setStencil(stencil);
//设置精灵来作为“裁剪结点”的content
auto content = Sprite::create(s_back2);
content-&setTag( kTagContentNode );
content-&setAnchorPoint(
Point(0.5, 0.5) );
content-&setPosition( Point(clipper-&getContentSize().width / 2, clipper-&getContentSize().height / 2) );
clipper-&addChild(content);
_scrolling =
auto listener = EventListenerTouchAllAtOnce::create();
listener-&onTouchesBegan = CC_CALLBACK_2(ScrollViewDemo::onTouchesBegan, this);
listener-&onTouchesMoved = CC_CALLBACK_2(ScrollViewDemo::onTouchesMoved, this);
listener-&onTouchesEnded = CC_CALLBACK_2(ScrollViewDemo::onTouchesEnded, this);
_eventDispatcher-&addEventListenerWithSceneGraphPriority(listener, this);
void ScrollViewDemo::onTouchesBegan(const std::vector&Touch*&& touches, Event
Touch *touch = touches[0];
auto clipper = this-&getChildByTag(kTagClipperNode);
Point point = clipper-&convertToNodeSpace(Director::getInstance()-&convertToGL(touch-&getLocationInView()));
auto rect = Rect(0, 0, clipper-&getContentSize().width, clipper-&getContentSize().height);
_scrolling = rect.containsPoint(point);
_lastPoint =
void ScrollViewDemo::onTouchesMoved(const std::vector&Touch*&& touches, Event
if (!_scrolling)
Touch *touch = touches[0];
auto clipper = this-&getChildByTag(kTagClipperNode);
auto point = clipper-&convertToNodeSpace(Director::getInstance()-&convertToGL(touch-&getLocationInView()));
Point diff = point - _lastP
auto content = clipper-&getChildByTag(kTagContentNode);
content-&setPosition(content-&getPosition() + diff);
_lastPoint =
注意drag时为什么要把精灵的移动放到onTouchesMoved里面,而没有放到onTouchesEnded里面,如果想一步到位就放到onTouchesEnded里面,如果想时时动态就应该放到onTouchesMoved里面。
2、ShapeTest、ShapeInvertedTest、SpriteTest、SpriteNoAlphaTest、SpriteInvertedTest
请先阅读此文章:《》。
这6个例子相互对应,分别讲解了以形状(DrawNode)为stencil模板和以精灵为stencil模板产生出来的效果,代码特别简单,读完上面的文章就OK了,这里不贴出来。
2.1、先看以shape为模板的产生的效果
左边是没有设置setInverted(true);右边是设置setInverted(true),也主是显示底板与不显示底板:
2.2 以sprite为模板产生的效果
左边:模板精灵只设置了alpha的值,setAlphaThreshold(0.05f);
中间:模板精灵只设置了alpha的值,但是是设置为1,setAlphaThreshold(1);那就是相当于没有设置alpha一样,因为stencil只会处理alpha
比他小的,例子中之所以要这样写,是因为他的父类里面把alpha的值设置了0.05了,所以这里他设置回来。
右边:模板精灵既设置了alpha的值,setAlphaThreshold(0.05f);也设置了底板显示,setInverted(true);
3、NestedTest
主角头上一行文字,已经指明这个例子的真正目的是为了告诉我们最多8个,第9个会失败的哦。
功能:九个男主角进行重叠的模版遮罩的裁切。为什么是9?是为了说明
模版缓冲格式,告诉大家如果最多只有8位模版值,则第九个会失败的
void NestedTest::setup()
static int depth = 9;
Node* parent =
for (int i = 0; i & i++) {
int size = 225 - i * (225 / (depth * 2));
auto clipper = ClippingNode::create();
clipper-&setContentSize(Size(size, size));
clipper-&setAnchorPoint(Point(0.5, 0.5));
clipper-&setPosition( Point(parent-&getContentSize().width / 2, parent-&getContentSize().height / 2) );
clipper-&setAlphaThreshold(0.05f);
clipper-&runAction(RepeatForever::create(RotateBy::create(i % 3 ? 1.33 : 1.66, i % 2 ? 90 : -90)));
//这里和后面的 parent = clipper 构成了一个链式的关系,一层桥嵌套一层
parent-&addChild(clipper);
auto stencil = Sprite::create(s_pathGrossini);
stencil-&setScale( 2.5 - (i * (2.5 / depth)) );
stencil-&setAnchorPoint( Point(0.5, 0.5) );
stencil-&setPosition( Point(clipper-&getContentSize().width / 2, clipper-&getContentSize().height / 2) );
//最开始精灵"猪角"为隐藏的,随后才通过Show::create()显示出来
stencil-&setVisible(false);
stencil-&runAction(Sequence::createWithTwoActions(DelayTime::create(i), Show::create()));
毁五观,我一直觉得stencil和content不能为同一个对象,这里彻底打醒了我,他们可以相同
clipper-&setStencil(stencil);
clipper-&addChild(stencil);
看代码里面的注释!还算简单,但是让我开了眼了,还可以这样玩哦。
上面的8个例子基本是基于ClippingNode来进行操作的。大家会疑问后面还有好几个例子像RawStencilBufferTest之类的,他们已经不属于ClippingNode的范围了。
本文固定链接:
转载请注明:
作者:游戏开发
欢迎大家访问游戏开发网!
如果您觉得这篇文章有用处,请支持作者!鼓励作者写出更好更多的文章!
您可能还会对这些文章感兴趣!下次自动登录
现在的位置:
& 综合 & 正文
cocos2d-x TestCpp 中的Sprite的demo讲解
//sprite类,可以帮助我们实现游戏中各种精灵类,比如RPG游戏中的角色,NPC 怪物 飞行器 坐骑 武器 装备 衣服等等,射击游戏中的敌人,子弹,玩家角色,等等等,总之这个类是游戏的必备元素,是玩家直接看到的东西,功能也非常的强大,实现各种变形,运动,拉升,对称,效果过滤,动画播放,加载方式等等
#ifndef _SPRITE_TEST_H_
#define _SPRITE_TEST_H_
#include "cocos2d.h"
#include "../testBasic.h"
#include &string&
class SpriteTestDemo : public CCLayer
protected:
std::string
SpriteTestDemo(void);
~SpriteTestDemo(void);
virtual std::string title();
virtual std::string subtitle();
virtual void onEnter();
void restartCallback(CCObject* pSender);
void nextCallback(CCObject* pSender);
void backCallback(CCObject* pSender);
class Sprite1 : public SpriteTestDemo
Sprite1();
virtual std::string title();
void addNewSpriteWithCoords(CCPoint p);
void ccTouchesEnded(CCSet* touches, CCEvent* event);
class SpriteBatchNode1: public SpriteTestDemo
SpriteBatchNode1();
void addNewSpriteWithCoords(CCPoint p);
virtual void ccTouchesEnded(CCSet* touches, CCEvent* event);
virtual std::string title();
class SpriteColorOpacity : public SpriteTestDemo
SpriteColorOpacity();
void removeAndAddSprite(float dt);
virtual std::string title();
class SpriteBatchNodeColorOpacity : public SpriteTestDemo
SpriteBatchNodeColorOpacity();
void removeAndAddSprite(float dt);
virtual std::string title();
class SpriteZOrder : public SpriteTestDemo
SpriteZOrder();
void reorderSprite(float dt);
virtual std::string title();
class SpriteBatchNodeZOrder: public SpriteTestDemo
SpriteBatchNodeZOrder();
void reorderSprite(float dt);
virtual std::string title();
class SpriteBatchNodeReorder : public SpriteTestDemo
SpriteBatchNodeReorder();
virtual std::string title();
std::string subtitle();
class SpriteBatchNodeReorderIssue744: public SpriteTestDemo
SpriteBatchNodeReorderIssue744();
virtual std::string title();
std::string subtitle();
class SpriteBatchNodeReorderIssue766 : public SpriteTestDemo
SpriteBatchNodeReorderIssue766();
virtual std::string title();
virtual std::string subtitle();
void reorderSprite(float dt);
CCSprite* makeSpriteZ(int aZ);
CCSpriteBatchNode *batchN
CCSprite *sprite1;
CCSprite *sprite2;
CCSprite *sprite3;
class SpriteBatchNodeReorderIssue767 : public SpriteTestDemo
SpriteBatchNodeReorderIssue767();
virtual std::string title();
virtual std::string subtitle();
void reorderSprites(float dt);
class SpriteZVertex: public SpriteTestDemo
virtual void onEnter();
virtual void onExit();
SpriteZVertex();
virtual std::string title();
class SpriteBatchNodeZVertex: public SpriteTestDemo
virtual void onEnter();
virtual void onExit();
SpriteBatchNodeZVertex();
virtual std::string title();
class SpriteAnchorPoint : public SpriteTestDemo
SpriteAnchorPoint();
virtual std::string title();
class SpriteBatchNodeAnchorPoint : public SpriteTestDemo
SpriteBatchNodeAnchorPoint();
virtual std::string title();
class Sprite6 : public SpriteTestDemo
Sprite6();
virtual std::string title();
class SpriteFlip : public SpriteTestDemo
SpriteFlip();
void flipSprites(float dt);
virtual std::string title();
class SpriteBatchNodeFlip : public SpriteTestDemo
SpriteBatchNodeFlip();
void flipSprites(float dt);
virtual std::string title();
class SpriteAliased : public SpriteTestDemo
SpriteAliased();
virtual void onEnter();
virtual void onExit();
virtual std::string title();
class SpriteBatchNodeAliased : public SpriteTestDemo
SpriteBatchNodeAliased();
virtual void onEnter();
virtual void onExit();
virtual std::string title();
class SpriteNewTexture : public SpriteTestDemo
m_usingTexture1;
CCTexture2D*
m_texture1;
CCTexture2D*
m_texture2;
SpriteNewTexture();
virtual ~SpriteNewTexture();
void addNewSprite();
void ccTouchesEnded(CCSet* touches, CCEvent* event);
virtual std::string title();
class SpriteBatchNodeNewTexture : public SpriteTestDemo
CCTexture2D*
m_texture1;
CCTexture2D*
m_texture2;
SpriteBatchNodeNewTexture();
virtual ~SpriteBatchNodeNewTexture();
void addNewSprite();
void ccTouchesEnded(CCSet* touches, CCEvent* event);
virtual std::string title();
class SpriteFrameTest: public SpriteTestDemo
virtual void onEnter();
virtual void onExit();
virtual std::string title();
virtual std::string subtitle();
void startIn05Secs(float dt);
void flipSprites(float dt);
CCSprite *m_pSprite1;
CCSprite *m_pSprite2;
class SpriteFrameAliasNameTest : public SpriteTestDemo
virtual void onEnter();
virtual void onExit();
virtual std::string title();
virtual std::string subtitle();
class SpriteOffsetAnchorRotation: public SpriteTestDemo
SpriteOffsetAnchorRotation();
virtual void onExit();
virtual std::string title();
class SpriteBatchNodeOffsetAnchorRotation: public SpriteTestDemo
SpriteBatchNodeOffsetAnchorRotation();
virtual void onExit();
virtual std::string title();
class SpriteOffsetAnchorScale: public SpriteTestDemo
SpriteOffsetAnchorScale();
virtual void onExit();
virtual std::string title();
class SpriteBatchNodeOffsetAnchorScale: public SpriteTestDemo
SpriteBatchNodeOffsetAnchorScale();
virtual void onExit();
virtual std::string title();
class SpriteOffsetAnchorSkew : public SpriteTestDemo
SpriteOffsetAnchorSkew();
~SpriteOffsetAnchorSkew();
virtual std::string title();
class SpriteOffsetAnchorRotationalSkew : public SpriteTestDemo
SpriteOffsetAnchorRotationalSkew();
~SpriteOffsetAnchorRotationalSkew();
virtual std::string title();
class SpriteBatchNodeOffsetAnchorSkew : public SpriteTestDemo
SpriteBatchNodeOffsetAnchorSkew();
~SpriteBatchNodeOffsetAnchorSkew();
virtual std::string title();
class SpriteOffsetAnchorRotationalSkewScale : public SpriteTestDemo
SpriteOffsetAnchorRotationalSkewScale();
~SpriteOffsetAnchorRotationalSkewScale();
virtual std::string title();
class SpriteBatchNodeOffsetAnchorRotationalSkew : public SpriteTestDemo
SpriteBatchNodeOffsetAnchorRotationalSkew();
~SpriteBatchNodeOffsetAnchorRotationalSkew();
virtual std::string title();
class SpriteOffsetAnchorSkewScale : public SpriteTestDemo
SpriteOffsetAnchorSkewScale();
~SpriteOffsetAnchorSkewScale();
virtual std::string title();
class SpriteBatchNodeOffsetAnchorSkewScale : public SpriteTestDemo
SpriteBatchNodeOffsetAnchorSkewScale();
~SpriteBatchNodeOffsetAnchorSkewScale();
virtual std::string title();
class SpriteBatchNodeOffsetAnchorRotationalSkewScale : public SpriteTestDemo
SpriteBatchNodeOffsetAnchorRotationalSkewScale();
~SpriteBatchNodeOffsetAnchorRotationalSkewScale();
virtual std::string title();
class SpriteOffsetAnchorFlip : public SpriteTestDemo
SpriteOffsetAnchorFlip();
~SpriteOffsetAnchorFlip();
virtual std::string title();
virtual std::string subtitle();
class SpriteBatchNodeOffsetAnchorFlip : public SpriteTestDemo
SpriteBatchNodeOffsetAnchorFlip();
~SpriteBatchNodeOffsetAnchorFlip();
virtual std::string title();
virtual std::string subtitle();
class SpriteAnimationSplit : public SpriteTestDemo
SpriteAnimationSplit();
virtual void onExit();
virtual std::string title();
class SpriteHybrid: public SpriteTestDemo
m_usingSpriteBatchN
SpriteHybrid();
void reparentSprite(float dt);
virtual std::string title();
virtual void onExit();
class SpriteBatchNodeChildren: public SpriteTestDemo
SpriteBatchNodeChildren();
virtual void onExit();
virtual std::string title();
class SpriteBatchNodeChildrenZ : public SpriteTestDemo
SpriteBatchNodeChildrenZ();
virtual void onExit();
virtual std::string title();
class SpriteChildrenVisibility: public SpriteTestDemo
SpriteChildrenVisibility();
virtual void onExit();
virtual std::string title();
class SpriteChildrenVisibilityIssue665 : public SpriteTestDemo
SpriteChildrenVisibilityIssue665();
~SpriteChildrenVisibilityIssue665();
virtual std::string title();
virtual std::string subtitle();
class SpriteChildrenAnchorPoint: public SpriteTestDemo
SpriteChildrenAnchorPoint();
virtual void onExit();
virtual std::string title();
class SpriteBatchNodeChildrenAnchorPoint: public SpriteTestDemo
SpriteBatchNodeChildrenAnchorPoint();
virtual void onExit();
virtual std::string title();
class SpriteBatchNodeChildrenScale: public SpriteTestDemo
SpriteBatchNodeChildrenScale();
virtual std::string title();
class SpriteChildrenChildren: public SpriteTestDemo
SpriteChildrenChildren();
virtual std::string title();
class SpriteBatchNodeChildrenChildren: public SpriteTestDemo
SpriteBatchNodeChildrenChildren();
virtual std::string title();
class SpriteNilTexture: public SpriteTestDemo
SpriteNilTexture();
virtual std::string title();
std::string subtitle();
class SpriteSubclass : public SpriteTestDemo
SpriteSubclass();
virtual std::string title();
virtual std::string subtitle();
class AnimationCache : public SpriteTestDemo
AnimationCache();
virtual std::string title();
virtual std::string subtitle();
class NodeSort : public SpriteTestDemo
NodeSort();
virtual std::string title();
virtual std::string subtitle();
void reorderSprite(float dt);
CCNode *m_pN
CCSprite *m_pSprite1;
CCSprite *m_pSprite2;
CCSprite *m_pSprite3;
CCSprite *m_pSprite4;
CCSprite *m_pSprite5;
class SpriteBatchNodeReorderSameIndex : public SpriteTestDemo
SpriteBatchNodeReorderSameIndex();
virtual std::string title();
virtual std::string subtitle();
void reorderSprite(float dt);
CCSpriteBatchNode *m_pBatchN
CCSprite *m_pSprite1;
CCSprite *m_pSprite2;
CCSprite *m_pSprite3;
CCSprite *m_pSprite4;
CCSprite *m_pSprite5;
class SpriteBatchNodeReorderOneChild : public SpriteTestDemo
SpriteBatchNodeReorderOneChild();
void reorderSprite(float dt);
virtual std::string title();
CCSpriteBatchNode *m_pBatchN
CCSprite *m_pReorderS
class SpriteBatchNodeSkewNegativeScaleChildren : public SpriteTestDemo
SpriteBatchNodeSkewNegativeScaleChildren();
~SpriteBatchNodeSkewNegativeScaleChildren();
virtual std::string title();
virtual std::string subtitle();
class SpriteBatchNodeRotationalSkewNegativeScaleChildren : public SpriteTestDemo
SpriteBatchNodeRotationalSkewNegativeScaleChildren();
~SpriteBatchNodeRotationalSkewNegativeScaleChildren();
virtual std::string title();
class SpriteSkewNegativeScaleChildren : public SpriteTestDemo
SpriteSkewNegativeScaleChildren();
~SpriteSkewNegativeScaleChildren();
virtual std::string title();
virtual std::string subtitle();
class SpriteRotationalSkewNegativeScaleChildren : public SpriteTestDemo
SpriteRotationalSkewNegativeScaleChildren();
~SpriteRotationalSkewNegativeScaleChildren();
virtual std::string title();
class SpriteDoubleResolution : public SpriteTestDemo
SpriteDoubleResolution();
virtual std::string title();
virtual std::string subtitle();
class AnimationCacheFile : public SpriteTestDemo
AnimationCacheFile();
virtual std::string title();
virtual std::string subtitle();
class SpriteBatchBug1217 : public SpriteTestDemo
SpriteBatchBug1217();
virtual std::string title();
virtual std::string subtitle();
class SpriteTestScene : public TestScene
virtual void runThisTest();
#include "SpriteTest.h"
#include "../testResource.h"
//?(R)“?√?ae?–?tag
kTagTileMap = 1,
kTagSpriteBatchNode = 1,
kTagNode = 2,
kTagAnimation1 = 1,
kTagSpriteLeft,
kTagSpriteRight,
kTagSprite1,
kTagSprite2,
kTagSprite3,
kTagSprite4,
kTagSprite5,
kTagSprite6,
kTagSprite7,
kTagSprite8,
IDC_NEXT = 100,
IDC_RESTART
//±? aeu±<<∞demo,≥? ?÷uOE(TM)-1
static int sceneIdx = -1;
//…?√~>>?∏^∫? ??¨next?¨back?¨restart
CCLayer* nextSpriteTestAction();
CCLayer* backSpriteTestAction();
CCLayer* restartSpriteTestAction();
//?(R)“?∫? ?÷∏’???–??¨NEWSPRITETESTFUNC?¨≤OE ??–±?OE(TM)?’?¨∑u??÷uOE(TM)CCLayer*
typedef CCLayer* (*NEWSPRITETESTFUNC)();
//∫??(R)“??¨”√??…?√~??Ω(R)÷??(R)??√?u?∫? ??¨∑u??÷uOE(TM)static CCLayer*
#define SPRITETEST_CREATE_FUNC(className) \
static CCLayer* create##className() \
{ return new className(); }
// π”√∫??(R)“?…?√~∫? ??¨??∫?’π?(TM)ae?oe?u±”/…?√~????Ω(R)÷??(R)layeru?∫? ??¨
SPRITETEST_CREATE_FUNC(Sprite1);
??’π?(TM)ae? <<?∫
static CCLayer* createSprite1()
return new Sprite1();
//“‘oe?÷?∏^????
//SPRITETEST_CREATE_FUNC(Sprite1);
SPRITETEST_CREATE_FUNC(SpriteBatchNode1);
SPRITETEST_CREATE_FUNC(SpriteFrameTest);
SPRITETEST_CREATE_FUNC(SpriteFrameAliasNameTest);
SPRITETEST_CREATE_FUNC(SpriteAnchorPoint);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeAnchorPoint);
SPRITETEST_CREATE_FUNC(SpriteOffsetAnchorRotation);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeOffsetAnchorRotation);
SPRITETEST_CREATE_FUNC(SpriteOffsetAnchorScale);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeOffsetAnchorScale);
SPRITETEST_CREATE_FUNC(SpriteOffsetAnchorSkew);
SPRITETEST_CREATE_FUNC(SpriteOffsetAnchorRotationalSkew);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeOffsetAnchorSkew);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeOffsetAnchorRotationalSkew);
SPRITETEST_CREATE_FUNC(SpriteOffsetAnchorSkewScale);
SPRITETEST_CREATE_FUNC(SpriteOffsetAnchorRotationalSkewScale);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeOffsetAnchorSkewScale);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeOffsetAnchorRotationalSkewScale);
SPRITETEST_CREATE_FUNC(SpriteOffsetAnchorFlip);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeOffsetAnchorFlip);
SPRITETEST_CREATE_FUNC(SpriteAnimationSplit);
SPRITETEST_CREATE_FUNC(SpriteColorOpacity);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeColorOpacity);
SPRITETEST_CREATE_FUNC(SpriteZOrder);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeZOrder);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeReorder);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeReorderIssue744);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeReorderIssue766);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeReorderIssue767);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeReorderSameIndex);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeReorderOneChild);
SPRITETEST_CREATE_FUNC(NodeSort);
SPRITETEST_CREATE_FUNC(SpriteZVertex);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeZVertex);
SPRITETEST_CREATE_FUNC(Sprite6);
SPRITETEST_CREATE_FUNC(SpriteFlip);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeFlip);
SPRITETEST_CREATE_FUNC(SpriteAliased);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeAliased);
SPRITETEST_CREATE_FUNC(SpriteNewTexture);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeNewTexture);
SPRITETEST_CREATE_FUNC(SpriteHybrid);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeChildren);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeChildrenZ);
SPRITETEST_CREATE_FUNC(SpriteChildrenVisibility);
SPRITETEST_CREATE_FUNC(SpriteChildrenVisibilityIssue665);
SPRITETEST_CREATE_FUNC(SpriteChildrenAnchorPoint);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeChildrenAnchorPoint);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeChildrenScale);
SPRITETEST_CREATE_FUNC(SpriteChildrenChildren);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeChildrenChildren);
SPRITETEST_CREATE_FUNC(SpriteSkewNegativeScaleChildren);
SPRITETEST_CREATE_FUNC(SpriteRotationalSkewNegativeScaleChildren);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeSkewNegativeScaleChildren);
SPRITETEST_CREATE_FUNC(SpriteBatchNodeRotationalSkewNegativeScaleChildren);
SPRITETEST_CREATE_FUNC(SpriteNilTexture);
SPRITETEST_CREATE_FUNC(SpriteSubclass);
SPRITETEST_CREATE_FUNC(SpriteDoubleResolution);
SPRITETEST_CREATE_FUNC(SpriteBatchBug1217);
SPRITETEST_CREATE_FUNC(AnimationCache);
SPRITETEST_CREATE_FUNC(AnimationCacheFile);
//?(R)“?∫? ?÷∏’???–?u?÷u?¨÷uOE(TM)∫? ?√?≥?
static NEWSPRITETESTFUNC createFunctions[] =
createSprite1,
createSpriteBatchNode1,
createSpriteFrameTest,
createSpriteFrameAliasNameTest,
createSpriteAnchorPoint,
createSpriteBatchNodeAnchorPoint,
createSpriteOffsetAnchorRotation,
createSpriteBatchNodeOffsetAnchorRotation,
createSpriteOffsetAnchorScale,
createSpriteBatchNodeOffsetAnchorScale,
createSpriteOffsetAnchorSkew,
createSpriteOffsetAnchorRotationalSkew,
createSpriteBatchNodeOffsetAnchorSkew,
createSpriteBatchNodeOffsetAnchorRotationalSkew,
createSpriteOffsetAnchorSkewScale,
createSpriteOffsetAnchorRotationalSkewScale,
createSpriteBatchNodeOffsetAnchorSkewScale,
createSpriteBatchNodeOffsetAnchorRotationalSkewScale,
createSpriteOffsetAnchorFlip,
createSpriteBatchNodeOffsetAnchorFlip,
createSpriteAnimationSplit,
createSpriteColorOpacity,
createSpriteBatchNodeColorOpacity,
createSpriteZOrder,
createSpriteBatchNodeZOrder,
createSpriteBatchNodeReorder,
createSpriteBatchNodeReorderIssue744,
createSpriteBatchNodeReorderIssue766,
createSpriteBatchNodeReorderIssue767,
createSpriteBatchNodeReorderSameIndex,
createSpriteBatchNodeReorderOneChild,
createNodeSort,
createSpriteZVertex,
createSpriteBatchNodeZVertex,
createSprite6,
createSpriteFlip,
createSpriteBatchNodeFlip,
createSpriteAliased,
createSpriteBatchNodeAliased,
createSpriteNewTexture,
createSpriteBatchNodeNewTexture,
createSpriteHybrid,
createSpriteBatchNodeChildren,
createSpriteBatchNodeChildrenZ,
createSpriteChildrenVisibility,
createSpriteChildrenVisibilityIssue665,
createSpriteChildrenAnchorPoint,
createSpriteBatchNodeChildrenAnchorPoint,
createSpriteBatchNodeChildrenScale,
createSpriteChildrenChildren,
createSpriteBatchNodeChildrenChildren,
createSpriteSkewNegativeScaleChildren,
createSpriteRotationalSkewNegativeScaleChildren,
createSpriteBatchNodeSkewNegativeScaleChildren,
createSpriteBatchNodeRotationalSkewNegativeScaleChildren,
createSpriteNilTexture,
createSpriteSubclass,
createSpriteDoubleResolution,
createSpriteBatchBug1217,
createAnimationCache,
createAnimationCacheFile,
#define MAX_LAYER
(sizeof(createFunctions) / sizeof(createFunctions[0]))
CCLayer* nextSpriteTestAction()
sceneIdx++;
sceneIdx = sceneIdx % MAX_LAYER;
CCLayer* pLayer = (createFunctions[sceneIdx])();
pLayer-&autorelease();
CCLayer* backSpriteTestAction()
sceneIdx--;
int total = MAX_LAYER;
if( sceneIdx & 0 )
sceneIdx +=
CCLayer* pLayer = (createFunctions[sceneIdx])();
pLayer-&autorelease();
CCLayer* restartSpriteTestAction()
CCLayer* pLayer = (createFunctions[sceneIdx])();
pLayer-&autorelease();
//------------------------------------------------------------------
// SpriteTestDemo
//------------------------------------------------------------------
SpriteTestDemo::SpriteTestDemo(void)
SpriteTestDemo::~SpriteTestDemo(void)
std::string SpriteTestDemo::title()
return "No title";
std::string SpriteTestDemo::subtitle()
return "";
void SpriteTestDemo::onEnter()
CCLayer::onEnter();
CCSize s = CCDirector::sharedDirector()-&getWinSize();
CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 28);
addChild(label, 1);
label-&setPosition( ccp(s.width/2, s.height-50) );
std::string strSubtitle = subtitle();
if( ! strSubtitle.empty() )
CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16);
addChild(l, 1);
l-&setPosition( ccp(s.width/2, s.height-80) );
CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", this, menu_selector(SpriteTestDemo::backCallback) );
CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png","Images/r2.png", this, menu_selector(SpriteTestDemo::restartCallback) );
CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", this, menu_selector(SpriteTestDemo::nextCallback) );
CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);
//Ω?menu∑≈÷√‘/00u,,?¨OE“?Ω ±∏,≥?”√Ω?item∑≈÷√‘/menu÷–?¨>>?∫?‘/∑≈÷√u?OE?÷√?¨?????¨”–±?“(TM)∏˙demo÷–?≥“?“?oe?
menu-&setPosition(CCPointZero);
item1-&setPosition(ccp(VisibleRect::center().x - item2-&getContentSize().width*2, VisibleRect::bottom().y+item2-&getContentSize().height/2));
/*∑≈÷√OE?÷√?¨ <<openglu?Ω?√?÷–u?OE?÷√?¨≤? <<Scene÷–u???–°?¨Ω(R)“? π”√VisibleRect?¨??±?OE?÷√‘/≤??¨??–°u?…?±∏…oe?·???“*/
/*?<÷AE”OEoe∑“?π≤?Ω∏^Ω?√??¨“?∏^ <<…?±?u?ae??‘??–°?¨“?∏^ <<openglu?Ω?√??¨u±openglΩ?√?∫?…?±?Ω?√?”…”/∑÷±?? u?÷???∏fl≤?“?—? ±∫??¨ae?–?“(TM)
≈‰???¨∑≈????’fl??–°openglu???∏fl?¨’,—?“????¨??????∏fl≤?±‰?¨u? <<opengl??∏fl±‰???¨“‘<<∞≤…”√??????∏fl…?÷√u???±?ae?≤??·∏˙?≈opengl??±?u?±‰??“???±‰???¨??“‘?u?¨“??(R)“(TM)≤…”√openglΩ?√?u???∏fl??…?÷√??±?*/
item2-&setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2-&getContentSize().height/2));
item3-&setPosition(ccp(VisibleRect::center().x + item2-&getContentSize().width*2, VisibleRect::bottom().y+item2-&getContentSize().height/2));
addChild(menu, 1);
void SpriteTestDemo::restartCallback(CCObject* pSender)
//??∫? ?u~”√>>?ae÷∫? ??? uoe÷?¨÷?∏?≤o∑≈
CCScene* s = new SpriteTestScene();
s-&addChild(restartSpriteTestAction());
CCDirector::sharedDirector()-&replaceScene(s);
s-&release();
void SpriteTestDemo::nextCallback(CCObject* pSender)
CCScene* s = new SpriteTestScene();
s-&addChild( nextSpriteTestAction() );
CCDirector::sharedDirector()-&replaceScene(s);
s-&release();
void SpriteTestDemo::backCallback(CCObject* pSender)
CCScene* s = new SpriteTestScene();
s-&addChild( backSpriteTestAction() );
CCDirector::sharedDirector()-&replaceScene(s);
s-&release();
//------------------------------------------------------------------
// Sprite1
//------------------------------------------------------------------
Sprite1::Sprite1()
//Ω?’,∏^layer…?÷√OE(TM)?…“‘?o√?
setTouchEnabled( true );
CCSize s = CCDirector::sharedDirector()-&getWinSize();
/*??>>°÷––?u,,?¨?‰ u’,∏^>>?π?’?∏^Scene‘/
≈‰????u?π?≥?÷–>>?π?…?÷√π?scaleu?÷u?¨‘/≤??¨u?…?≈‰?? Ωoe??¨?<<√?’,∏^??±??·?“u?u?°?°?*/
addNewSpriteWithCoords( ccp(s.width/2, s.height/2) );
void Sprite1::addNewSpriteWithCoords(CCPoint p)
//??>>°???˙ ?
int idx = (int)(CCRANDOM_0_1() * 1400.0f / 100.0f);
int x = (idx%5) * 85;
int y = (idx/5) * 121;
//??>>°ae???
CCSprite* sprite = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(x,y,85,121) );
addChild( sprite );
sprite-&setPosition( ccp( p.x, p.y) );
CCActionInterval*
float random = CCRANDOM_0_1();
//∏?ae>???˙ ?u?÷uu?∑?OEss?¨??Ω(R)≤??¨u?action
if( random & 0.20 )
action = CCScaleBy::create(3, 2);
else if(random & 0.40)
action = CCRotateBy::create(3, 360);
else if( random & 0.60)
action = CCBlink::create(1, 3);
else if( random & 0.8 )
action = CCTintBy::create(2, 0, -255, -255);
action = CCFadeOut::create(2);
CCActionInterval* action_back = action-&reverse();
CCActionInterval* seq = (CCActionInterval*)(CCSequence::create( action, action_back, NULL ));
sprite-&runAction( CCRepeatForever::create(seq) );
void Sprite1::ccTouchesEnded(CCSet* touches, CCEvent* event)
//??u,,?o√??¨?(R)“?√?∏^?o√?u,,±‰??u?u,?˙?~?¨set&CCObject*&::iterator??–?
//?(R)“?u,?˙?~u?÷∏oe?u?touch?‘oe??¨?‰ u??”?∏√∏???≥? ???OE(TM)NULL??
for( it = touches-&begin(); it != touches-&end(); it++)
touch = (CCTouch*)(*it);
if(!touch)
//??>>°???o√?u,,u?OE?÷√??±??¨’,∏^??±? <<OPGL÷–u???±?
CCPoint location = touch-&getLocation();
//‘/’,∏^??±?u,,???”“?∏^sprite
addNewSpriteWithCoords( location );
std::string Sprite1::title()
return "Sprite (tap screen)";
//------------------------------------------------------------------
// SpriteBatchNode1
//------------------------------------------------------------------
SpriteBatchNode1::SpriteBatchNode1()
setTouchEnabled( true );
/*≥? ???“?∏^CCSpriteBatchNode?¨≤?Ω??,???”‘/layer…oe?¨order=0?¨tag=kTagSpriteBatchNode?¨50?˙±?≥? ???’,∏^∏^???¨u?OE???‘/CCSpriteBatchNode???’?‰u???–°?¨*/
CCSpriteBatchNode* BatchNode = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 50);
addChild(BatchNode, 0, kTagSpriteBatchNode);
CCSize s = CCDirector::sharedDirector()-&getWinSize();
//‘/?∞?/÷––?u,,??±??¨???”newSprite
addNewSpriteWithCoords( ccp(s.width/2, s.height/2) );
void SpriteBatchNode1::addNewSpriteWithCoords(CCPoint p)
//??>>°’,∏^CCSpriteBatckNode?¨CCSpriteBatchNode
CCSpriteBatchNode* BatchNode = (CCSpriteBatchNode*) getChildByTag( kTagSpriteBatchNode );
int idx = CCRANDOM_0_1() * 1400 / 100;
int x = (idx%5) * 85;
int y = (idx/5) * 121;
/*??Ω(R)sprite?¨?”≥? ???π?u?OE?????÷–??>>°OE????¨±>>??÷±Ω”?”???¨create?¨’,÷÷∑Ω∑(R)?¨‘/??Ω(R)??∏^???¨ ±?¨±>>??create???>>???¨OE“√<>≥? ???OE????¨Ω(R)??OE???u?π>°OE?????Ω(R)?¨?¨ ±Ω???”–”√uΩu????¨?(R)π?OE?????∞,?~?¨Ω???√<<∫oe≥…‘/“?∏^???¨…oe?¨≤?…˙≥…?¨plistOE????¨ π”√√??÷±? ae??Ω(R)sprite?¨∑Ω±,,π<??∫?–‘?<?·…?*/
CCSprite* sprite = CCSprite::createWithTexture(BatchNode-&getTexture(), CCRectMake(x,y,85,121));
//÷±Ω”Ω?sprite???”‘/node…oe?¨÷AE<∏∏?”Ω/u,,u?π?oeu÷±Ω”ae??…“‘oe‘ ae??//
BatchNode-&addChild(sprite);
//…?÷√OE?÷√??±??¨’,∏^OE?÷√?¨Ω? <<spriteu?‘/BatchNode…oeu?OE?÷√
sprite-&setPosition( ccp( p.x, p.y) );
CCActionInterval*
float random = CCRANDOM_0_1();
if( random & 0.20 )
action = CCScaleBy::create(3, 2);
else if(random & 0.40)
action = CCRotateBy::create(3, 360);
else if( random & 0.60)
action = CCBlink::create(1, 3);
else if( random & 0.8 )
action = CCTintBy::create(2, 0, -255, -255);
action = CCFadeOut::create(2);
CCActionInterval* action_back = action-&reverse();
CCActionInterval* seq = (CCActionInterval*)(CCSequence::create(action, action_back, NULL));
sprite-&runAction( CCRepeatForever::create(seq));
void SpriteBatchNode1::ccTouchesEnded(CCSet* touches, CCEvent* event)
for( it = touches-&begin(); it != touches-&end(); it++)
touch = (CCTouch*)(*it);
if(!touch)
CCPoint location = touch-&getLocation();
addNewSpriteWithCoords( location );
std::string SpriteBatchNode1::title()
return "SpriteBatchNode (tap screen)";
//------------------------------------------------------------------
// SpriteColorOpacity
//------------------------------------------------------------------
SpriteColorOpacity::SpriteColorOpacity()
CCSprite* sprite1 = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*0, 121*1, 85, 121));
CCSprite* sprite2 = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*1, 121*1, 85, 121));
CCSprite* sprite3 = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*2, 121*1, 85, 121));
CCSprite* sprite4 = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*3, 121*1, 85, 121));
CCSprite* sprite5 = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*0, 121*1, 85, 121));
CCSprite* sprite6 = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*1, 121*1, 85, 121));
CCSprite* sprite7 = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*2, 121*1, 85, 121));
CCSprite* sprite8 = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*3, 121*1, 85, 121));
CCSize s = CCDirector::sharedDirector()-&getWinSize();
sprite1-&setPosition( ccp( (s.width/5)*1, (s.height/3)*1) );
sprite2-&setPosition( ccp( (s.width/5)*2, (s.height/3)*1) );
sprite3-&setPosition( ccp( (s.width/5)*3, (s.height/3)*1) );
sprite4-&setPosition( ccp( (s.width/5)*4, (s.height/3)*1) );
sprite5-&setPosition( ccp( (s.width/5)*1, (s.height/3)*2) );
sprite6-&setPosition( ccp( (s.width/5)*2, (s.height/3)*2) );
sprite7-&setPosition( ccp( (s.width/5)*3, (s.height/3)*2) );
sprite8-&setPosition( ccp( (s.width/5)*4, (s.height/3)*2) );
CCActionInterval* action = CCFadeIn::create(2);
CCActionInterval* action_back = action-&reverse();
CCAction* fade = CCRepeatForever::create( (CCActionInterval*)(CCSequence::create( action, action_back, NULL)));
CCActionInterval* tintred = CCTintBy::create(2, 0, -255, -255);
CCActionInterval* tintred_back = tintred-&reverse();
CCAction* red = CCRepeatForever::create( (CCActionInterval*)(CCSequence::create( tintred, tintred_back, NULL)) );
CCActionInterval* tintgreen = CCTintBy::create(2, -255, 0, -255);
CCActionInterval* tintgreen_back = tintgreen-&reverse();
CCAction* green = CCRepeatForever::create( (CCActionInterval*)(CCSequence::create( tintgreen, tintgreen_back, NULL)));
CCActionInterval* tintblue = CCTintBy::create(2, -255, -255, 0);
CCActionInterval* tintblue_back = tintblue-&reverse();
CCAction* blue = CCRepeatForever::create( (CCActionInterval*)(CCSequence::create( tintblue, tintblue_back, NULL)) );
sprite5-&runAction(red);
sprite6-&runAction(green);
sprite7-&runAction(blue);
sprite8-&runAction(fade);
// late add: test dirtyColor and dirtyPosition
addChild(sprite1, 0, kTagSprite1);
addChild(sprite2, 0, kTagSprite2);
addChild(sprite3, 0, kTagSprite3);
addChild(sprite4, 0, kTagSprite4);
addChild(sprite5, 0, kTagSprite5);
addChild(sprite6, 0, kTagSprite6);
addChild(sprite7, 0, kTagSprite7);
addChild(sprite8, 0, kTagSprite8);
schedule( schedule_selector(SpriteColorOpacity::removeAndAddSprite), 2 );
// this function test if remove and add works as expected:
color array and vertex array should be reindexed
void SpriteColorOpacity::removeAndAddSprite(float dt)
CCSprite* sprite = (CCSprite*)(getChildByTag(kTagSprite5));
sprite-&retain();
removeChild(sprite, false);
addChild(sprite, 0, kTagSprite5);
sprite-&release();
std::string SpriteColorOpacity::title()
return "Sprite: Color & Opacity";
//------------------------------------------------------------------
// SpriteBatchNodeColorOpacity
//------------------------------------------------------------------
SpriteBatchNodeColorOpacity::SpriteBatchNodeColorOpacity()
// small capacity. Testing resizing.
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
/*??Ω(R)CCSpriteBatchNode Ω/u,,?¨≥? ???OE????????’?‰OE(TM)1?¨?· ae?u≤?“(TM)Ω??’?‰…?÷√OE(TM)1?¨’,—??· πu√?¨?’?‰u???–°???¨resize?¨resizeu??˙?EUR”–u,,∏fl?¨∏˙vctor“?—?*/
CCSpriteBatchNode* batch = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
addChild(batch, 0, kTagSpriteBatchNode);
CCSprite* sprite1 = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*0, 121*1, 85, 121));
CCSprite* sprite2 = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*1, 121*1, 85, 121));
CCSprite* sprite3 = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*2, 121*1, 85, 121));
CCSprite* sprite4 = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*3, 121*1, 85, 121));
CCSprite* sprite5 = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*0, 121*1, 85, 121));
CCSprite* sprite6 = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*1, 121*1, 85, 121));
CCSprite* sprite7 = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*2, 121*1, 85, 121));
CCSprite* sprite8 = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*3, 121*1, 85, 121));
CCSize s = CCDirector::sharedDirector()-&getWinSize();
sprite1-&setPosition( ccp( (s.width/5)*1, (s.height/3)*1) );
sprite2-&setPosition( ccp( (s.width/5)*2, (s.height/3)*1) );
sprite3-&setPosition( ccp( (s.width/5)*3, (s.height/3)*1) );
sprite4-&setPosition( ccp( (s.width/5)*4, (s.height/3)*1) );
sprite5-&setPosition( ccp( (s.width/5)*1, (s.height/3)*2) );
sprite6-&setPosition( ccp( (s.width/5)*2, (s.height/3)*2) );
sprite7-&setPosition( ccp( (s.width/5)*3, (s.height/3)*2) );
sprite8-&setPosition( ccp( (s.width/5)*4, (s.height/3)*2) );
CCActionInterval* action = CCFadeIn::create(2);
CCActionInterval* action_back = action-&reverse();
CCAction* fade = CCRepeatForever::create( (CCActionInterval*)(CCSequence::create( action, action_back,NULL)));
CCActionInterval* tintred = CCTintBy::create(2, 0, -255, -255);
CCActionInterval* tintred_back = tintred-&reverse();
CCAction* red = CCRepeatForever::create( (CCActionInterval*)(CCSequence::create( tintred, tintred_back,NULL)));
CCActionInterval* tintgreen = CCTintBy::create(2, -255, 0, -255);
CCActionInterval* tintgreen_back = tintgreen-&reverse();
CCAction* green = CCRepeatForever::create( (CCActionInterval*)(CCSequence::create( tintgreen, tintgreen_back,NULL)));
CCActionInterval* tintblue = CCTintBy::create(2, -255, -255, 0);
CCActionInterval* tintblue_back = tintblue-&reverse();
CCAction* blue = CCRepeatForever::create( (CCActionInterval*)(CCSequence::create( tintblue, tintblue_back,NULL)));
sprite5-&runAction(red);
sprite6-&runAction(green);
sprite7-&runAction(blue);
sprite8-&runAction(fade);
// late add: test dirtyColor and dirtyPosition
//Ω???Ω(R)u???”–sprite???”‘/batch…oe?¨
batch-&addChild(sprite1, 0, kTagSprite1);
batch-&addChild(sprite2, 0, kTagSprite2);
batch-&addChild(sprite3, 0, kTagSprite3);
batch-&addChild(sprite4, 0, kTagSprite4);
batch-&addChild(sprite5, 0, kTagSprite5);
batch-&addChild(sprite6, 0, kTagSprite6);
batch-&addChild(sprite7, 0, kTagSprite7);
batch-&addChild(sprite8, 0, kTagSprite8);
schedule( schedule_selector(SpriteBatchNodeColorOpacity::removeAndAddSprite), 2);
// this function test if remove and add works as expected:
color array and vertex array should be reindexed
void SpriteBatchNodeColorOpacity::removeAndAddSprite(float dt)
{//??>>°CCSpriteBatchNode
CCSpriteBatchNode* batch= (CCSpriteBatchNode*)(getChildByTag( kTagSpriteBatchNode ));
//?”CCSpriteBatchNode…oe??>>° sprite
CCSprite* sprite = (CCSprite*)(batch-&getChildByTag(kTagSprite5));
sprite-&retain();
batch-&removeChild(sprite, false);
batch-&addChild(sprite, 0, kTagSprite5);
sprite-&release();
std::string SpriteBatchNodeColorOpacity::title()
return "SpriteBatchNode: Color & Opacity";
//------------------------------------------------------------------
// SpriteZOrder
//------------------------------------------------------------------
SpriteZOrder::SpriteZOrder()
m_dir = 1;
CCSize s = CCDirector::sharedDirector()-&getWinSize();
float step = s.width/11;
for(int i=0;i&5;i++)
CCSprite* sprite = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*0, 121*1, 85, 121));
sprite-&setPosition( ccp( (i+1)*step, s.height/2) );
addChild(sprite, i);
for(int i=5;i&10;i++)
CCSprite* sprite = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*1, 121*0, 85, 121));
sprite-&setPosition( ccp( (i+1)*step, s.height/2) );
addChild(sprite, 14-i);
CCSprite* sprite = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*3, 121*0, 85, 121));
addChild(sprite, -1, kTagSprite1);
sprite-&setPosition( ccp(s.width/2, s.height/2 - 20) );
sprite-&setScaleX( 6 );
sprite-&setColor(ccRED);
schedule( schedule_selector(SpriteZOrder::reorderSprite), 1);
void SpriteZOrder::reorderSprite(float dt)
CCSprite* sprite = (CCSprite*)(getChildByTag(kTagSprite1));
int z = sprite-&getZOrder();
if( z & -1 )
m_dir = 1;
if( z & 10 )
m_dir = -1;
z += m_dir * 3;
reorderChild(sprite, z);
std::string SpriteZOrder::title()
return "Sprite: Z order";
//------------------------------------------------------------------
// SpriteBatchNodeZOrder
//------------------------------------------------------------------
SpriteBatchNodeZOrder::SpriteBatchNodeZOrder()
m_dir = 1;
// small capacity. Testing resizing.
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
CCSpriteBatchNode* batch = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
addChild(batch, 0, kTagSpriteBatchNode);
CCSize s = CCDirector::sharedDirector()-&getWinSize();
float step = s.width/11;
for(int i=0;i&5;i++)
CCSprite* sprite = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*0, 121*1, 85, 121));
sprite-&setPosition( ccp( (i+1)*step, s.height/2) );
batch-&addChild(sprite, i);
for(int i=5;i&10;i++)
CCSprite* sprite = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*1, 121*0, 85, 121));
sprite-&setPosition( ccp( (i+1)*step, s.height/2) );
batch-&addChild(sprite, 14-i);
CCSprite* sprite = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*3, 121*0, 85, 121));
batch-&addChild(sprite, -1, kTagSprite1);
sprite-&setPosition( ccp(s.width/2, s.height/2 - 20) );
sprite-&setScaleX( 6 );
sprite-&setColor(ccRED);
schedule( schedule_selector(SpriteBatchNodeZOrder::reorderSprite), 1);
void SpriteBatchNodeZOrder::reorderSprite(float dt)
CCSpriteBatchNode* batch= (CCSpriteBatchNode*)(getChildByTag( kTagSpriteBatchNode ));
CCSprite* sprite = (CCSprite*)(batch-&getChildByTag(kTagSprite1));
int z = sprite-&getZOrder();
if( z & -1 )
m_dir = 1;
if( z & 10 )
m_dir = -1;
z += m_dir * 3;
batch-&reorderChild(sprite, z);
std::string SpriteBatchNodeZOrder::title()
return "SpriteBatchNode: Z order";
//------------------------------------------------------------------
// SpriteBatchNodeReorder
//------------------------------------------------------------------
SpriteBatchNodeReorder::SpriteBatchNodeReorder()
CCArray* a = CCArray::createWithCapacity(10);
CCSpriteBatchNode* asmtest = CCSpriteBatchNode::create("animations/ghosts.png");
for(int i=0; i&10; i++)
CCSprite* s1 = CCSprite::createWithTexture(asmtest-&getTexture(), CCRectMake(0, 0, 50, 50));
a-&addObject(s1);
asmtest-&addChild(s1, 10);
for(int i=0; i&10; i++)
asmtest-&reorderChild( (CCNode*)(a-&objectAtIndex(i)), 9 );
int prev = -1;
CCArray* children = asmtest-&getChildren();
CCObject* pObject = NULL;
CCARRAY_FOREACH(children, pObject)
child = (CCSprite*)pO
if(! child )
int currentIndex = child-&getAtlasIndex();
CCAssert( prev == currentIndex-1, "Child order failed");
////----UXLOG("children %x - atlasIndex:%d", child, currentIndex);
prev = currentI
prev = -1;
CCArray* sChildren = asmtest-&getDescendants();
CCARRAY_FOREACH(sChildren, pObject)
child = (CCSprite*)pO
if(! child )
int currentIndex = child-&getAtlasIndex();
CCAssert( prev == currentIndex-1, "Child order failed");
////----UXLOG("descendant %x - atlasIndex:%d", child, currentIndex);
prev = currentI
std::string SpriteBatchNodeReorder::title()
return "SpriteBatchNode: reorder #1";
std::string SpriteBatchNodeReorder::subtitle()
return "Should not crash";
//------------------------------------------------------------------
// SpriteBatchNodeReorderIssue744
//------------------------------------------------------------------
SpriteBatchNodeReorderIssue744::SpriteBatchNodeReorderIssue744()
CCSize s = CCDirector::sharedDirector()-&getWinSize();
// Testing issue #744
// /p/cocos2d-iphone/issues/detail?id=744
CCSpriteBatchNode* batch = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 15);
addChild(batch, 0, kTagSpriteBatchNode);
CCSprite* sprite = CCSprite::createWithTexture(batch-&getTexture(),CCRectMake(0, 0, 85, 121));
sprite-&setPosition( ccp(s.width/2, s.height/2) );
batch-&addChild(sprite, 3);
batch-&reorderChild(sprite, 1);
std::string SpriteBatchNodeReorderIssue744::title()
return "SpriteBatchNode: reorder issue #744";
std::string SpriteBatchNodeReorderIssue744::subtitle()
return "Should not crash";
//------------------------------------------------------------------
// SpriteBatchNodeReorderIssue766
//------------------------------------------------------------------
CCSprite* SpriteBatchNodeReorderIssue766::makeSpriteZ(int aZ)
CCSprite *sprite = CCSprite::createWithTexture(batchNode-&getTexture(), CCRectMake(128,0,64,64));
batchNode-&addChild(sprite, aZ+1, 0);
//children
CCSprite *spriteShadow = CCSprite::createWithTexture(batchNode-&getTexture(), CCRectMake(0,0,64,64));
spriteShadow-&setOpacity(128);
sprite-&addChild(spriteShadow, aZ, 3);
CCSprite *spriteTop = CCSprite::createWithTexture(batchNode-&getTexture(), CCRectMake(64,0,64,64));
sprite-&addChild(spriteTop, aZ+2, 3);
void SpriteBatchNodeReorderIssue766::reorderSprite(float dt)
unschedule(schedule_selector(SpriteBatchNodeReorderIssue766::reorderSprite));
batchNode-&reorderChild(sprite1, 4);
// on "init" you need to initialize your instance
SpriteBatchNodeReorderIssue766::SpriteBatchNodeReorderIssue766()
batchNode = CCSpriteBatchNode::create("Images/piece.png", 15);
addChild(batchNode, 1, 0);
sprite1 = makeSpriteZ(2);
sprite1-&setPosition(ccp(200,160));
sprite2 = makeSpriteZ(3);
sprite2-&setPosition(ccp(264,160));
sprite3 = makeSpriteZ(4);
sprite3-&setPosition(ccp(328,160));
schedule(schedule_selector(SpriteBatchNodeReorderIssue766::reorderSprite), 2);
std::string SpriteBatchNodeReorderIssue766::title()
return "SpriteBatchNode: reorder issue #766";
std::string SpriteBatchNodeReorderIssue766::subtitle()
return "In 2 seconds 1 sprite will be reordered";
//------------------------------------------------------------------
// SpriteBatchNodeReorderIssue767
//------------------------------------------------------------------
SpriteBatchNodeReorderIssue767::SpriteBatchNodeReorderIssue767()
CCSize s = CCDirector::sharedDirector()-&getWinSize();
//’,∏^???” <>?OE???cache?¨OE????∫???~?¨
CCSpriteFrameCache::sharedSpriteFrameCache()-&addSpriteFramesWithFile("animations/ghosts.plist", "animations/ghosts.png");
CCNode *aP
CCSprite *l1, *l2a, *l2b, *l3a1, *l3a2, *l3b1, *l3b2;
// SpriteBatchNode: 3 levels of children
//??Ω(R)???¨√?≥???Ω(R)CCSpriteBatchNode?¨CCSpriteBatchNodeuΩoe÷‘/?¨??ae? <<“?∏^aefl”–?¨“?∏^OE???u?sprieu???∫oe
aParent = CCSpriteBatchNode::create("animations/ghosts.png");
addChild(aParent, 0, kTagSprite1);
//??Ω(R)sprite?¨∏?ae>plist????u?frameNameu?√??÷÷u
l1 = CCSprite::createWithSpriteFrameName("father.gif");
l1-&setPosition(ccp( s.width/2, s.height/2));
aParent-&addChild(l1, 0, kTagSprite2);
CCSize l1Size = l1-&getContentSize();
// child left
l2a = CCSprite::createWithSpriteFrameName("sister1.gif");
l2a-&setPosition(ccp( -25 + l1Size.width/2, 0 + l1Size.height/2));
l1-&addChild(l2a, -1, kTagSpriteLeft);
CCSize l2aSize = l2a-&getContentSize();
// child right
l2b = CCSprite::createWithSpriteFrameName("sister2.gif");
l2b-&setPosition(ccp( +25 + l1Size.width/2, 0 + l1Size.height/2));
l1-&addChild(l2b, 1, kTagSpriteRight);
CCSize l2bSize = l2a-&getContentSize();
// child left bottom
l3a1 = CCSprite::createWithSpriteFrameName("child1.gif");
l3a1-&setScale(0.65f);
l3a1-&setPosition(ccp(0+l2aSize.width/2,-50+l2aSize.height/2));
l2a-&addChild(l3a1, -1);
// child left top
l3a2 = CCSprite::createWithSpriteFrameName("child1.gif");
l3a2-&setScale(0.65f);
l3a2-&setPosition(ccp(0+l2aSize.width/2,+50+l2aSize.height/2));
l2a-&addChild(l3a2, 1);
// child right bottom
l3b1 = CCSprite::createWithSpriteFrameName("child1.gif");
l3b1-&setScale(0.65f);
l3b1-&setPosition(ccp(0+l2bSize.width/2,-50+l2bSize.height/2));
l2b-&addChild(l3b1, -1);
// child right top
l3b2 = CCSprite::createWithSpriteFrameName("child1.gif");
l3b2-&setScale(0.65f);
l3b2-&setPosition(ccp(0+l2bSize.width/2,+50+l2bSize.height/2));
l2b-&addChild(l3b2, 1);
schedule(schedule_selector(SpriteBatchNodeReorderIssue767::reorderSprites), 1);
std::string SpriteBatchNodeReorderIssue767::title()
return "SpriteBatchNode: reorder issue #767";
std::string SpriteBatchNodeReorderIssue767::subtitle()
return "Should not crash";
void SpriteBatchNodeReorderIssue767::reorderSprites(float dt)
CCSpriteBatchNode* spritebatch = (CCSpriteBatchNode*)getChildByTag(kTagSprite1);
CCSprite *father = (CCSprite*)spritebatch-&getChildByTag(kTagSprite2);
CCSprite *left = (CCSprite*)father-&getChildByTag(kTagSpriteLeft);
CCSprite *right = (CCSprite*)father-&getChildByTag(kTagSpriteRight);
int newZLeft = 1;
if( left-&getZOrder() == 1 )
newZLeft = -1;
father-&reorderChild(left, newZLeft);
father-&reorderChild(right, -newZLeft);
//------------------------------------------------------------------
// SpriteZVertex
//------------------------------------------------------------------
void SpriteZVertex::onEnter()
SpriteTestDemo::onEnter();
CCDirector::sharedDirector()-&setProjection(kCCDirectorProjection3D);
void SpriteZVertex::onExit()
CCDirector::sharedDirector()-&setProjection(kCCDirectorProjection2D);
SpriteTestDemo::onExit();
SpriteZVertex::SpriteZVertex()
// This test tests z-order
// If you are going to use it is better to use a 3D projection
// WARNING:
// The developer is resposible for ordering its sprites according to its Z if the sprite has
// transparent parts.
// Configure shader to mimic glAlphaTest
//?????”?¨∏?ae>2D??oe??¨??uΩ3D–ssπ??¨”–??Ω?“?≤Ω?””?∏,,√~∞?‘≠??
CCGLProgram *alphaTestShader = CCShaderCache::sharedShaderCache()-&programForKey(kCCShader_PositionTextureColorAlphaTest);
GLint alphaValueLocation = glGetUniformLocation(alphaTestShader-&getProgram(), kCCUniformAlphaTestValue);
// set alpha test value
// NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
if (getShaderProgram())
getShaderProgram()-&setUniformLocationWith1f(alphaValueLocation, 0.0f);
m_dir = 1;
m_time = 0;
CCSize s = CCDirector::sharedDirector()-&getWinSize();
float step = s.width/12;
CCNode* node = CCNode::create();
// camera uses the center of the image as the pivoting point
node-&setContentSize( CCSizeMake(s.width,s.height) );
node-&setAnchorPoint( ccp(0.5f, 0.5f));
node-&setPosition( ccp(s.width/2, s.height/2));
addChild(node, 0);
for(int i=0;i&5;i++)
CCSprite* sprite = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*0, 121*1, 85, 121));
sprite-&setPosition( ccp((i+1)*step, s.height/2) );
sprite-&setVertexZ( 10 + i*40 );
sprite-&setShaderProgram(alphaTestShader);
node-&addChild(sprite, 0);
for(int i=5;i&11;i++)
CCSprite* sprite = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*1, 121*0, 85, 121));
sprite-&setPosition( ccp( (i+1)*step, s.height/2) );
sprite-&setVertexZ( 10 + (10-i)*40 );
sprite-&setShaderProgram(alphaTestShader);
node-&addChild(sprite, 0);
node-&runAction( CCOrbitCamera::create(10, 1, 0, 0, 360, 0, 0) );
std::string SpriteZVertex::title()
return "Sprite: openGL Z vertex";
//------------------------------------------------------------------
// SpriteBatchNodeZVertex
//------------------------------------------------------------------
void SpriteBatchNodeZVertex::onEnter()
SpriteTestDemo::onEnter();
CCDirector::sharedDirector()-&setProjection(kCCDirectorProjection3D);
void SpriteBatchNodeZVertex::onExit()
CCDirector::sharedDirector()-&setProjection(kCCDirectorProjection2D);
SpriteTestDemo::onExit();
SpriteBatchNodeZVertex::SpriteBatchNodeZVertex()
// This test tests z-order
// If you are going to use it is better to use a 3D projection
// WARNING:
// The developer is resposible for ordering its sprites according to its Z if the sprite has
// transparent parts.
// Configure shader to mimic glAlphaTest
CCGLProgram *alphaTestShader = CCShaderCache::sharedShaderCache()-&programForKey(kCCShader_PositionTextureColorAlphaTest);
GLint alphaValueLocation = glGetUniformLocation(alphaTestShader-&getProgram(), kCCUniformAlphaTestValue);
// set alpha test value
// NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
if (getShaderProgram())
getShaderProgram()-&setUniformLocationWith1f(alphaValueLocation, 0.0f);
CCSize s = CCDirector::sharedDirector()-&getWinSize();
float step = s.width/12;
// small capacity. Testing resizing.
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
CCSpriteBatchNode* batch = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
// camera uses the center of the image as the pivoting point
batch-&setContentSize( CCSizeMake(s.width,s.height));
batch-&setAnchorPoint( ccp(0.5f, 0.5f));
batch-&setPosition( ccp(s.width/2, s.height/2));
batch-&setShaderProgram(alphaTestShader);
addChild(batch, 0, kTagSpriteBatchNode);
for(int i=0;i&5;i++)
CCSprite* sprite = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*0, 121*1, 85, 121));
sprite-&setPosition( ccp( (i+1)*step, s.height/2) );
sprite-&setVertexZ(
10 + i*40 );
batch-&addChild(sprite, 0);
for(int i=5;i&11;i++) {
CCSprite* sprite = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*1, 121*0, 85, 121));
sprite-&setPosition( ccp( (i+1)*step, s.height/2) );
sprite-&setVertexZ(
10 + (10-i)*40 );
batch-&addChild(sprite, 0);
batch-&runAction(CCOrbitCamera::create(10, 1, 0, 0, 360, 0, 0) );
std::string SpriteBatchNodeZVertex::title()
return "SpriteBatchNode: openGL Z vertex";
//------------------------------------------------------------------
// SpriteAnchorPoint
//------------------------------------------------------------------
SpriteAnchorPoint::SpriteAnchorPoint()
/*√(TM)u,,≤, ‘?¨’,∏^∫<??uo???¨ae? <<sprite∑≈÷√ ±∫?u?????u,,?¨0-1?¨≥?”√u?“?π≤ <>?∏^?¨(0,0),(0.5,0.5),(1,1)?¨
??>>?∏^????u,,∑÷±? <<?¨??oe?Ω<<?¨÷––?u??¨”“…oeΩ<<?¨∑≈÷√ ±∫??¨?(R)0?¨0?(C) ±?¨±ae…?u???oe?Ω<<”?∏∏Ω/u,,u???oe?Ω<<÷?u??¨(0.5,0.5) <<÷∏?¨±ae…?u?÷––?u,,”?∏∏Ω/u,,u???oe?Ω<<÷?u??¨(1,1)±ae…?u?”“…oeΩ<<”?∏∏Ω/u,,u???oe?Ω<<÷?u?*/
CCSize s = CCDirector::sharedDirector()-&getWinSize();
CCActionInterval* rotate = CCRotateBy::create(10, 360);
CCAction* action = CCRepeatForever::create(rotate);
for(int i=0;i&3;i++)
CCSprite* sprite = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*i, 121*1, 85, 121) );
sprite-&setPosition( ccp( s.width/4*(i+1), s.height/2) );
CCSprite *point = CCSprite::create("Images/r1.png");
point-&setScale( 0.25f );
point-&setPosition( sprite-&getPosition() );
addChild(point, 10);
sprite-&setAnchorPoint( CCPointZero );
sprite-&setAnchorPoint( ccp(0.5f, 0.5f) );
sprite-&setAnchorPoint( ccp(1,1) );
point-&setPosition( sprite-&getPosition() );
CCAction* copy = (CCAction*)(action-&copy()-&autorelease());
sprite-&runAction(copy);
addChild(sprite, i);
std::string SpriteAnchorPoint::title()
return "Sprite: anchor point";
//------------------------------------------------------------------
// SpriteBatchNodeAnchorPoint
//------------------------------------------------------------------
SpriteBatchNodeAnchorPoint::SpriteBatchNodeAnchorPoint()
// small capacity. Testing resizing.
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
CCSpriteBatchNode* batch = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
addChild(batch, 0, kTagSpriteBatchNode);
CCSize s = CCDirector::sharedDirector()-&getWinSize();
CCActionInterval* rotate = CCRotateBy::create(10, 360);
CCAction* action = CCRepeatForever::create(rotate);
for(int i=0;i&3;i++)
CCSprite* sprite = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*i, 121*1, 85, 121));
sprite-&setPosition( ccp( s.width/4*(i+1), s.height/2) );
CCSprite *point = CCSprite::create("Images/r1.png");
point-&setScale( 0.25f );
point-&setPosition( sprite-&getPosition() );
addChild(point, 1);
sprite-&setAnchorPoint( CCPointZero );
sprite-&setAnchorPoint( ccp(0.5f, 0.5f) );
sprite-&setAnchorPoint( ccp(1,1) );
point-&setPosition( sprite-&getPosition() );
CCAction* copy = (CCAction*)(action-&copy()-&autorelease());
sprite-&runAction(copy);
batch-&addChild(sprite, i);
std::string SpriteBatchNodeAnchorPoint::title()
return "SpriteBatchNode: anchor point";
//------------------------------------------------------------------
// Sprite6
//------------------------------------------------------------------
Sprite6::Sprite6()
// small capacity. Testing resizing
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
CCSpriteBatchNode* batch = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
addChild(batch, 0, kTagSpriteBatchNode);
batch-&ignoreAnchorPointForPosition( true );
CCSize s = CCDirector::sharedDirector()-&getWinSize();
batch-&setAnchorPoint( ccp(0.5f, 0.5f) );
batch-&setContentSize( CCSizeMake(s.width, s.height) );
// SpriteBatchNode actions
CCActionInterval* rotate = CCRotateBy::create(5, 360);
//?≥ ±’?“?÷±?(TM)??
CCAction* action = CCRepeatForever::create(rotate);
// SpriteBatchNode actions
//?? ±’?“?÷±?(TM)
CCActionInterval* rotate_back = rotate-&reverse();
CCActionInterval* rotate_seq = (CCActionInterval*)(CCSequence::create(rotate, rotate_back, NULL));
CCAction* rotate_forever = CCRepeatForever::create(rotate_seq);
CCActionInterval* scale = CCScaleBy::create(5, 1.5f);
CCActionInterval* scale_back = scale-&reverse();
CCActionInterval* scale_seq = (CCActionInterval*)(CCSequence::create( scale, scale_back, NULL));
CCAction* scale_forever = CCRepeatForever::create(scale_seq);
float step = s.width/4;
for(int i=0;i&3;i++)
CCSprite* sprite = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*i, 121*1, 85, 121));
sprite-&setPosition( ccp( (i+1)*step, s.height/2) );
/*’,???¨sprite±ae…?“?÷±‘??(TM)?¨?≥ ±’?u??(TM)?¨u±∏∏Ω/u,,?? ±’??(TM)?? ±?¨ ?Ω∏^actionu??”u?–ssπ?ae? <<÷–∫????¨√?”–‘??(TM)?¨u±∏∏Ω/u,, <> <<2±?u??”*/
sprite-&runAction( (CCAction*)(action-&copy()-&autorelease()) );
batch-&addChild(sprite, i);
batch-&runAction( scale_forever);
batch-&runAction( rotate_forever);
std::string Sprite6::title()
return "SpriteBatchNode transformation";
//------------------------------------------------------------------
// SpriteFlip
//------------------------------------------------------------------
SpriteFlip::SpriteFlip()
CCSize s = CCDirector::sharedDirector()-&getWinSize();
CCSprite* sprite1 = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*1, 121*1, 85, 121));
sprite1-&setPosition( ccp( s.width/2 - 100, s.height/2 ) );
addChild(sprite1, 0, kTagSprite1);
CCSprite* sprite2 = CCSprite::create("Images/grossini_dance_atlas.png", CCRectMake(85*1, 121*1, 85, 121));
sprite2-&setPosition( ccp( s.width/2 + 100, s.height/2 ) );
addChild(sprite2, 0, kTagSprite2);
schedule( schedule_selector(SpriteFlip::flipSprites), 1);
void SpriteFlip::flipSprites(float dt)
CCSprite* sprite1 = (CCSprite*)(getChildByTag(kTagSprite1));
CCSprite* sprite2 = (CCSprite*)(getChildByTag(kTagSprite2));
//…oeoe??‘u~
bool x = sprite1-&isFlipX();
//??”“?‘u~?¨ae? <<∞?y = position.y??”“u??‘u~“?oe?
bool y = sprite2-&isFlipY();
CCLOG("Pre: %f", sprite1-&getContentSize().height);
sprite1-&setFlipX(!x);
sprite2-&setFlipY(!y);
CCLOG("Post: %f", sprite1-&getContentSize().height);
std::string SpriteFlip::title()
return "Sprite Flip X & Y";
//------------------------------------------------------------------
// SpriteBatchNodeFlip
//------------------------------------------------------------------
SpriteBatchNodeFlip::SpriteBatchNodeFlip()
CCSpriteBatchNode* batch = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 10);
addChild(batch, 0, kTagSpriteBatchNode);
CCSize s = CCDirector::sharedDirector()-&getWinSize();
CCSprite* sprite1 = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*1, 121*1, 85, 121));
sprite1-&setPosition( ccp( s.width/2 - 100, s.height/2 ) );
batch-&addChild(sprite1, 0, kTagSprite1);
CCSprite* sprite2 = CCSprite::createWithTexture(batch-&getTexture(), CCRectMake(85*1, 121*1, 85, 121));
sprite2-&setPosition( ccp( s.width/2 + 100, s.height/2 ) );
batch-&addChild(sprite2, 0, kTagSprite2);
schedule( schedule_selector(SpriteBatchNodeFlip::flipSprites), 1);
void SpriteBatchNodeFlip::flipSprites(float dt)
CCSpriteBatchNode* batch= (CCSpriteBatchNode*)(getChildByTag( kTagSpriteBatchNode ));
CCSprite* sprite1 = (CCSprite*)(batch-&getChildByTag(kTagSprite1));
CCSprite* sprite2 = (CCSprite*)(batch-&getChildByTag(kTagSprite2));
bool x = sprite1-&isFlipX();
bool y = sprite2-&isFlipY();
CCLOG("Pre: %f", sprite1-&getContentSize().height);
sprite1-&setFlipX(!x);
sprite2-&setFlipY(!y);
CCLOG("Post: %f", sprite1-&getContentSize().height);
std::string SpriteBatchNodeFlip::title()
return "SpriteBatchNode Flip X & Y";
//------------------------------------------------------------------
// SpriteAliased
//------------------------------------------------------------------
SpriteAliased::SpriteAliased()
//??Ω(R)?Ω∏^“?—?u?ae????¨”√“?’≈?
&&&&推荐文章:
【上篇】【下篇】

我要回帖

更多关于 cocos2d js demo 的文章

 

随机推荐