26#include "../testResource.h"
36ParallaxTests::ParallaxTests()
52 auto cocosImage = Sprite::create(
s_Power);
54 cocosImage->setScale( 2.5f );
56 cocosImage->setAnchorPoint( Vec2(0,0) );
61 tilemap->releaseMap();
64 tilemap->setAnchorPoint( Vec2(0, 0) );
67 tilemap->getTexture()->setAntiAliasTexParameters();
71 auto background = Sprite::create(
s_back);
73 background->setScale( 1.5f );
75 background->setAnchorPoint( Vec2(0,0) );
79 auto voidNode = ParallaxNode::create();
84 voidNode->addChild(background, -1, Vec2(0.4f,0.5f), Vec2::ZERO);
87 voidNode->addChild(tilemap, 1, Vec2(2.2f,1.0f), Vec2(0,-200) );
90 voidNode->addChild(cocosImage, 2, Vec2(3.0f,2.5f), Vec2(200,800) );
96 auto goUp = MoveBy::create(4, Vec2(0,-500) );
97 auto goDown = goUp->reverse();
98 auto go = MoveBy::create(8, Vec2(-1000,0) );
99 auto goBack = go->reverse();
100 auto seq = Sequence::create(goUp, go, goDown, goBack,
nullptr);
101 voidNode->runAction( (RepeatForever::create(seq) ));
103 addChild( voidNode );
108 return "Parallax: parent and 3 children";
119 auto listener = EventListenerTouchAllAtOnce::create();
121 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
124 auto cocosImage = Sprite::create(
s_Power);
126 cocosImage->setScale( 2.5f );
128 cocosImage->setAnchorPoint( Vec2(0,0) );
133 tilemap->releaseMap();
136 tilemap->setAnchorPoint( Vec2(0, 0) );
139 tilemap->getTexture()->setAntiAliasTexParameters();
143 auto background = Sprite::create(
s_back);
145 background->setScale( 1.5f );
147 background->setAnchorPoint( Vec2(0,0) );
151 auto voidNode = ParallaxNode::create();
156 voidNode->addChild(background, -1, Vec2(0.4f,0.5f), Vec2::ZERO);
159 voidNode->addChild(tilemap, 1, Vec2(1.0f,1.0f), Vec2(0,-200) );
162 voidNode->addChild( cocosImage, 2, Vec2(3.0f,2.5f), Vec2(200,1000) );
168 auto diff = touches[0]->getDelta();
170 auto node = getChildByTag(
kTagNode);
171 auto currentPos = node->getPosition();
172 node->setPosition(currentPos + diff);
177 return "Parallax: drag screen";
199 this->scheduleUpdate();
207 this->unscheduleUpdate();
216 auto child = Sprite::create(
"Images/Icon.png");
217 Size viewSize = Director::getInstance()->getVisibleSize();
218 Vec2 offset = Vec2(viewSize.width / 2, viewSize.height/2);
219 _paraNode->addChild(child, 1, Vec2( 1, 0 ), offset );
231 log(
"--child count-- %zd",
_childList.size());
234 Sprite* obstacle =
dynamic_cast<Sprite*
>( obj );
235 log(
"child position : (%.2f, %.2f)", obstacle->getPositionX(), obstacle->getPositionY());
237 log(
"-------------------");
257 return "Look at the output in console";
#define ADD_TEST_CASE(__className__)
cocos2d::Vector< cocos2d::Sprite * > _childList
virtual std::string subtitle() const override
virtual std::string title() const override
cocos2d::Vec2 _wholeMoveSize
cocos2d::ParallaxNode * _paraNode
virtual void update(float dt) override
virtual std::string title() const override
virtual std::string title() const override
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
static const char s_TilesPng[]
static const char s_LevelMapTga[]
static const char s_back[]
static const char s_Power[]