axmol/tests/cpp-tests/Classes/SpriteTest/SpriteTest.cpp

5778 lines
183 KiB
C++
Raw Normal View History

/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2022-10-01 16:24:52 +08:00
https://axmolengine.github.io/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "SpriteTest.h"
#include <cmath>
#include <algorithm>
#include "../testResource.h"
#include "cocostudio/CocosStudioExtension.h"
USING_NS_AX;
2021-12-28 16:06:23 +08:00
enum
{
2021-12-28 16:06:23 +08:00
kTagTileMap = 1,
kTagSpriteBatchNode = 1,
2021-12-28 16:06:23 +08:00
kTagNode = 2,
kTagAnimation1 = 1,
kTagSpriteLeft,
kTagSpriteRight,
};
2021-12-28 16:06:23 +08:00
enum
{
kTagSprite1,
kTagSprite2,
kTagSprite3,
kTagSprite4,
kTagSprite5,
kTagSprite6,
kTagSprite7,
kTagSprite8,
};
SpriteTests::SpriteTests()
{
2015-09-29 22:50:14 +08:00
ADD_TEST_CASE(Sprite1);
ADD_TEST_CASE(SpriteBatchNode1);
ADD_TEST_CASE(SpriteAnchorPoint);
ADD_TEST_CASE(SpriteBatchNodeAnchorPoint);
ADD_TEST_CASE(SpriteAnchorPointFromFile);
2015-09-29 22:50:14 +08:00
ADD_TEST_CASE(SpriteOffsetAnchorRotation);
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorRotation);
ADD_TEST_CASE(SpriteOffsetAnchorScale);
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorScale);
ADD_TEST_CASE(SpriteOffsetAnchorSkew);
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorSkew);
ADD_TEST_CASE(SpriteOffsetAnchorRotationalSkew);
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorRotationalSkew);
ADD_TEST_CASE(SpriteOffsetAnchorSkewScale);
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorSkewScale);
ADD_TEST_CASE(SpriteOffsetAnchorRotationalSkewScale);
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorRotationalSkewScale);
ADD_TEST_CASE(SpriteSkewNegativeScaleChildren);
ADD_TEST_CASE(SpriteBatchNodeSkewNegativeScaleChildren);
ADD_TEST_CASE(SpriteRotationalSkewNegativeScaleChildren);
ADD_TEST_CASE(SpriteBatchNodeRotationalSkewNegativeScaleChildren);
ADD_TEST_CASE(SpriteOffsetAnchorFlip);
ADD_TEST_CASE(SpriteBatchNodeOffsetAnchorFlip);
ADD_TEST_CASE(SpriteChildrenChildren);
ADD_TEST_CASE(SpriteBatchNodeChildrenChildren);
ADD_TEST_CASE(SpriteChildrenAnchorPoint);
ADD_TEST_CASE(SpriteBatchNodeChildrenAnchorPoint);
ADD_TEST_CASE(SpriteColorOpacity);
2022-05-26 01:14:11 +08:00
ADD_TEST_CASE(SpriteColorOpacityHSVHSL);
2015-09-29 22:50:14 +08:00
ADD_TEST_CASE(SpriteBatchNodeColorOpacity);
ADD_TEST_CASE(SpriteZOrder);
ADD_TEST_CASE(SpriteBatchNodeZOrder);
2021-12-28 16:06:23 +08:00
// ADD_TEST_CASE(SpriteZVertex); // TODO shouldn't call OpenGL API directly
// ADD_TEST_CASE(SpriteBatchNodeZVertex);
2015-09-29 22:50:14 +08:00
ADD_TEST_CASE(SpriteAliased);
ADD_TEST_CASE(SpriteBatchNodeAliased);
ADD_TEST_CASE(SpriteNewTexture);
ADD_TEST_CASE(SpriteBatchNodeNewTexture);
ADD_TEST_CASE(SpriteFlip);
ADD_TEST_CASE(SpriteBatchNodeFlip);
ADD_TEST_CASE(SpriteAnimationSplit);
ADD_TEST_CASE(SpriteFrameTest);
ADD_TEST_CASE(SpriteFrameAliasNameTest);
ADD_TEST_CASE(SpriteFramesFromFileContent);
ADD_TEST_CASE(SpritePolygonFromFileContent);
2015-09-29 22:50:14 +08:00
ADD_TEST_CASE(SpriteBatchNodeReorder);
ADD_TEST_CASE(SpriteBatchNodeReorderIssue744);
ADD_TEST_CASE(SpriteBatchNodeReorderIssue766);
ADD_TEST_CASE(SpriteBatchNodeReorderIssue767);
ADD_TEST_CASE(SpriteBatchNodeReorderSameIndex);
ADD_TEST_CASE(SpriteBatchNodeReorderOneChild);
ADD_TEST_CASE(NodeSort);
ADD_TEST_CASE(Sprite6);
ADD_TEST_CASE(SpriteHybrid);
ADD_TEST_CASE(SpriteBatchNodeChildren);
ADD_TEST_CASE(SpriteBatchNodeChildrenZ);
ADD_TEST_CASE(SpriteChildrenVisibility);
ADD_TEST_CASE(SpriteChildrenVisibilityIssue665);
ADD_TEST_CASE(SpriteBatchNodeChildrenScale);
ADD_TEST_CASE(SpriteNilTexture);
ADD_TEST_CASE(SpriteSubclass);
ADD_TEST_CASE(SpriteBatchBug1217);
ADD_TEST_CASE(AnimationCacheTest);
ADD_TEST_CASE(AnimationCacheFile);
ADD_TEST_CASE(SpriteCullTest1);
ADD_TEST_CASE(SpriteCullTest2);
ADD_TEST_CASE(Sprite3DRotationTest);
ADD_TEST_CASE(SpriteGetSpriteFrameTest);
ADD_TEST_CASE(SpriteSlice9Test1);
ADD_TEST_CASE(SpriteSlice9Test2);
ADD_TEST_CASE(SpriteSlice9Test3);
ADD_TEST_CASE(SpriteSlice9Test4);
ADD_TEST_CASE(SpriteSlice9Test5);
ADD_TEST_CASE(SpriteSlice9Test6);
ADD_TEST_CASE(SpriteSlice9Test7);
ADD_TEST_CASE(SpriteSlice9Test8);
ADD_TEST_CASE(SpriteSlice9Test9);
ADD_TEST_CASE(SpriteSlice9Test10);
ADD_TEST_CASE(Issue17119);
};
//------------------------------------------------------------------
//
// Sprite1
//
//------------------------------------------------------------------
Sprite1::Sprite1()
{
2021-12-28 16:06:23 +08:00
auto listener = EventListenerTouchAllAtOnce::create();
2022-07-15 19:17:01 +08:00
listener->onTouchesEnded = AX_CALLBACK_2(Sprite1::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
addNewSpriteWithCoords(Vec2(s.width / 2, s.height / 2));
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
void Sprite1::addNewSpriteWithCoords(Vec2 p)
{
2022-07-16 10:43:05 +08:00
int idx = (int)(AXRANDOM_0_1() * 1400.0f / 100.0f);
2021-12-28 16:06:23 +08:00
int x = (idx % 5) * 85;
int y = (idx / 5) * 121;
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(x, y, 85, 121));
addChild(sprite);
sprite->setPosition(Vec2(p.x, p.y));
ActionInterval* action;
2022-07-16 10:43:05 +08:00
float random = AXRANDOM_0_1();
2021-12-28 16:06:23 +08:00
if (random < 0.20)
action = ScaleBy::create(3, 2);
2021-12-28 16:06:23 +08:00
else if (random < 0.40)
action = RotateBy::create(3, 360);
2021-12-28 16:06:23 +08:00
else if (random < 0.60)
action = Blink::create(1, 3);
2021-12-28 16:06:23 +08:00
else if (random < 0.8)
action = TintBy::create(2, 0, -255, -255);
2021-12-28 16:06:23 +08:00
else
action = FadeOut::create(2);
auto action_back = action->reverse();
2021-12-28 16:06:23 +08:00
auto seq = Sequence::create(action, action_back, nullptr);
sprite->runAction(RepeatForever::create(seq));
}
void Sprite1::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
for (auto& touch : touches)
{
auto location = touch->getLocation();
2021-12-28 16:06:23 +08:00
addNewSpriteWithCoords(location);
}
}
std::string Sprite1::title() const
{
return "Testing Sprite";
}
std::string Sprite1::subtitle() const
{
return "Tap screen to add more sprites";
}
//------------------------------------------------------------------
//
// SpriteBatchNode1
//
//------------------------------------------------------------------
SpriteBatchNode1::SpriteBatchNode1()
{
2021-12-28 16:06:23 +08:00
auto listener = EventListenerTouchAllAtOnce::create();
2022-07-15 19:17:01 +08:00
listener->onTouchesEnded = AX_CALLBACK_2(SpriteBatchNode1::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
auto BatchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 50);
addChild(BatchNode, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
addNewSpriteWithCoords(Vec2(s.width / 2, s.height / 2));
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
void SpriteBatchNode1::addNewSpriteWithCoords(Vec2 p)
{
2021-12-28 16:06:23 +08:00
auto BatchNode = static_cast<SpriteBatchNode*>(getChildByTag(kTagSpriteBatchNode));
2022-07-16 10:43:05 +08:00
int idx = AXRANDOM_0_1() * 1400 / 100;
2021-12-28 16:06:23 +08:00
int x = (idx % 5) * 85;
int y = (idx / 5) * 121;
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::createWithTexture(BatchNode->getTexture(), Rect(x, y, 85, 121));
BatchNode->addChild(sprite);
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(p.x, p.y));
ActionInterval* action;
2022-07-16 10:43:05 +08:00
float random = AXRANDOM_0_1();
2021-12-28 16:06:23 +08:00
if (random < 0.20)
action = ScaleBy::create(3, 2);
2021-12-28 16:06:23 +08:00
else if (random < 0.40)
action = RotateBy::create(3, 360);
2021-12-28 16:06:23 +08:00
else if (random < 0.60)
action = Blink::create(1, 3);
2021-12-28 16:06:23 +08:00
else if (random < 0.8)
action = TintBy::create(2, 0, -255, -255);
2021-12-28 16:06:23 +08:00
else
action = FadeOut::create(2);
auto action_back = action->reverse();
2021-12-28 16:06:23 +08:00
auto seq = Sequence::create(action, action_back, nullptr);
sprite->runAction(RepeatForever::create(seq));
}
void SpriteBatchNode1::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
for (auto&& touch : touches)
{
auto location = touch->getLocation();
2021-12-28 16:06:23 +08:00
addNewSpriteWithCoords(location);
}
}
std::string SpriteBatchNode1::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNode1::subtitle() const
{
return "SpriteBatchNode: Tap screen to add more sprites";
}
//------------------------------------------------------------------
//
// SpriteColorOpacity
//
//------------------------------------------------------------------
SpriteColorOpacity::SpriteColorOpacity()
{
2021-12-28 16:06:23 +08:00
auto sprite1 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 0, 121 * 1, 85, 121));
auto sprite2 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 1, 121 * 1, 85, 121));
auto sprite3 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 2, 121 * 1, 85, 121));
auto sprite4 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 3, 121 * 1, 85, 121));
auto sprite5 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 0, 121 * 1, 85, 121));
auto sprite6 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 1, 121 * 1, 85, 121));
auto sprite7 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 2, 121 * 1, 85, 121));
auto sprite8 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 3, 121 * 1, 85, 121));
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2((s.width / 5) * 1, (s.height / 3) * 1));
sprite2->setPosition(Vec2((s.width / 5) * 2, (s.height / 3) * 1));
sprite3->setPosition(Vec2((s.width / 5) * 3, (s.height / 3) * 1));
sprite4->setPosition(Vec2((s.width / 5) * 4, (s.height / 3) * 1));
sprite5->setPosition(Vec2((s.width / 5) * 1, (s.height / 3) * 2));
sprite6->setPosition(Vec2((s.width / 5) * 2, (s.height / 3) * 2));
sprite7->setPosition(Vec2((s.width / 5) * 3, (s.height / 3) * 2));
sprite8->setPosition(Vec2((s.width / 5) * 4, (s.height / 3) * 2));
auto action = FadeIn::create(2);
auto action_back = action->reverse();
2021-12-28 16:06:23 +08:00
auto fade = RepeatForever::create(Sequence::create(action, action_back, nullptr));
auto tintred = TintBy::create(2, 0, -255, -255);
auto tintred_back = tintred->reverse();
2021-12-28 16:06:23 +08:00
auto red = RepeatForever::create(Sequence::create(tintred, tintred_back, nullptr));
auto tintgreen = TintBy::create(2, -255, 0, -255);
auto tintgreen_back = tintgreen->reverse();
2021-12-28 16:06:23 +08:00
auto green = RepeatForever::create(Sequence::create(tintgreen, tintgreen_back, nullptr));
auto tintblue = TintBy::create(2, -255, -255, 0);
auto tintblue_back = tintblue->reverse();
2021-12-28 16:06:23 +08:00
auto blue = RepeatForever::create(Sequence::create(tintblue, tintblue_back, nullptr));
sprite5->runAction(red);
sprite6->runAction(green);
sprite7->runAction(blue);
sprite8->runAction(fade);
2021-12-28 16:06:23 +08:00
// 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);
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteColorOpacity::removeAndAddSprite, this), 2, "remove_add_key");
}
// this function test if remove and add works as expected:
// color array and vertex array should be reindexed
void SpriteColorOpacity::removeAndAddSprite(float dt)
{
2021-12-28 16:06:23 +08:00
auto sprite = static_cast<Sprite*>(getChildByTag(kTagSprite5));
sprite->retain();
2021-12-28 16:06:23 +08:00
removeChild(sprite, false);
addChild(sprite, 0, kTagSprite5);
2021-12-28 16:06:23 +08:00
sprite->release();
}
std::string SpriteColorOpacity::title() const
{
return "Testing Sprite";
}
std::string SpriteColorOpacity::subtitle() const
{
return "Color & Opacity";
}
2022-05-26 01:14:11 +08:00
//------------------------------------------------------------------
//
// SpriteColorOpacityHSVHSL
//
//------------------------------------------------------------------
SpriteColorOpacityHSVHSL::SpriteColorOpacityHSVHSL()
{
auto sprite1 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 0, 121 * 1, 85, 121));
auto sprite2 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 1, 121 * 1, 85, 121));
auto sprite3 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 2, 121 * 1, 85, 121));
auto sprite4 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 3, 121 * 1, 85, 121));
auto sprite5 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 0, 121 * 1, 85, 121));
auto sprite6 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 1, 121 * 1, 85, 121));
auto sprite7 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 2, 121 * 1, 85, 121));
auto sprite8 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 3, 121 * 1, 85, 121));
auto s = Director::getInstance()->getWinSize();
sprite1->setPosition(Vec2((s.width / 5) * 1, (s.height / 3) * 1));
sprite2->setPosition(Vec2((s.width / 5) * 2, (s.height / 3) * 1));
sprite3->setPosition(Vec2((s.width / 5) * 3, (s.height / 3) * 1));
sprite4->setPosition(Vec2((s.width / 5) * 4, (s.height / 3) * 1));
sprite5->setPosition(Vec2((s.width / 5) * 1, (s.height / 3) * 2));
sprite6->setPosition(Vec2((s.width / 5) * 2, (s.height / 3) * 2));
sprite7->setPosition(Vec2((s.width / 5) * 3, (s.height / 3) * 2));
sprite8->setPosition(Vec2((s.width / 5) * 4, (s.height / 3) * 2));
auto action = FadeIn::create(2);
auto action_back = action->reverse();
auto fade = RepeatForever::create(Sequence::create(action, action_back, nullptr));
auto col = HSV(0, 1, 1, 1).toColor3B();
auto tintred = TintBy::create(2, col.r, col.g, col.b);
auto tintred_back = tintred->reverse();
auto red = RepeatForever::create(Sequence::create(tintred, tintred_back, nullptr));
col = HSV(120, 1, 1, 1).toColor3B();
auto tintgreen = TintBy::create(2, col.r, col.g, col.b);
auto tintgreen_back = tintgreen->reverse();
auto green = RepeatForever::create(Sequence::create(tintgreen, tintgreen_back, nullptr));
col = HSV(240, 1, 1, 1).toColor3B();
auto tintblue = TintBy::create(2, col.r, col.g, col.b);
auto tintblue_back = tintblue->reverse();
auto blue = RepeatForever::create(Sequence::create(tintblue, tintblue_back, nullptr));
sprite1->runAction(red);
sprite2->runAction(green);
sprite3->runAction(blue);
sprite4->runAction(fade);
action = FadeIn::create(2);
action_back = action->reverse();
fade = RepeatForever::create(Sequence::create(action, action_back, nullptr));
col = HSL(0, 1, .7, 1).toColor3B();
tintred = TintBy::create(2, col.r, col.g, col.b);
tintred_back = tintred->reverse();
red = RepeatForever::create(Sequence::create(tintred, tintred_back, nullptr));
col = HSL(120, 1, .7, 1).toColor3B();
tintgreen = TintBy::create(2, col.r, col.g, col.b);
tintgreen_back = tintgreen->reverse();
green = RepeatForever::create(Sequence::create(tintgreen, tintgreen_back, nullptr));
col = HSL(240, 1, .7, 1).toColor3B();
tintblue = TintBy::create(2, col.r, col.g, col.b);
tintblue_back = tintblue->reverse();
blue = RepeatForever::create(Sequence::create(tintblue, tintblue_back, nullptr));
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);
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteColorOpacityHSVHSL::removeAndAddSprite, this), 2, "remove_add_key");
2022-05-26 01:14:11 +08:00
}
// this function test if remove and add works as expected:
// color array and vertex array should be reindexed
void SpriteColorOpacityHSVHSL::removeAndAddSprite(float dt)
{
auto sprite = static_cast<Sprite*>(getChildByTag(kTagSprite5));
sprite->retain();
removeChild(sprite, false);
addChild(sprite, 0, kTagSprite5);
sprite->release();
}
std::string SpriteColorOpacityHSVHSL::title() const
{
return "Testing Sprite";
}
std::string SpriteColorOpacityHSVHSL::subtitle() const
{
return "Color & Opacity using HSV/HSL";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeColorOpacity
//
//------------------------------------------------------------------
SpriteBatchNodeColorOpacity::SpriteBatchNodeColorOpacity()
{
// small capacity. Testing resizing.
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
2021-12-28 16:06:23 +08:00
addChild(batch, 0, kTagSpriteBatchNode);
auto sprite1 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 0, 121 * 1, 85, 121));
auto sprite2 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 1, 121 * 1, 85, 121));
auto sprite3 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 2, 121 * 1, 85, 121));
auto sprite4 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 3, 121 * 1, 85, 121));
auto sprite5 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 0, 121 * 1, 85, 121));
auto sprite6 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 1, 121 * 1, 85, 121));
auto sprite7 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 2, 121 * 1, 85, 121));
auto sprite8 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 3, 121 * 1, 85, 121));
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2((s.width / 5) * 1, (s.height / 3) * 1));
sprite2->setPosition(Vec2((s.width / 5) * 2, (s.height / 3) * 1));
sprite3->setPosition(Vec2((s.width / 5) * 3, (s.height / 3) * 1));
sprite4->setPosition(Vec2((s.width / 5) * 4, (s.height / 3) * 1));
sprite5->setPosition(Vec2((s.width / 5) * 1, (s.height / 3) * 2));
sprite6->setPosition(Vec2((s.width / 5) * 2, (s.height / 3) * 2));
sprite7->setPosition(Vec2((s.width / 5) * 3, (s.height / 3) * 2));
sprite8->setPosition(Vec2((s.width / 5) * 4, (s.height / 3) * 2));
auto action = FadeIn::create(2);
auto action_back = action->reverse();
2021-12-28 16:06:23 +08:00
auto fade = RepeatForever::create(Sequence::create(action, action_back, nullptr));
2021-12-28 16:06:23 +08:00
auto tintred = TintBy::create(2, 0, -255, -255);
auto tintred_back = tintred->reverse();
2021-12-28 16:06:23 +08:00
auto red = RepeatForever::create(Sequence::create(tintred, tintred_back, nullptr));
2021-12-28 16:06:23 +08:00
auto tintgreen = TintBy::create(2, -255, 0, -255);
auto tintgreen_back = tintgreen->reverse();
2021-12-28 16:06:23 +08:00
auto green = RepeatForever::create(Sequence::create(tintgreen, tintgreen_back, nullptr));
2021-12-28 16:06:23 +08:00
auto tintblue = TintBy::create(2, -255, -255, 0);
auto tintblue_back = tintblue->reverse();
2021-12-28 16:06:23 +08:00
auto blue = RepeatForever::create(Sequence::create(tintblue, tintblue_back, nullptr));
sprite5->runAction(red);
sprite6->runAction(green);
sprite7->runAction(blue);
sprite8->runAction(fade);
2021-12-28 16:06:23 +08:00
// late add: test dirtyColor and dirtyPosition
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);
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteBatchNodeColorOpacity::removeAndAddSprite, this), 2, "remove_add_key");
}
// this function test if remove and add works as expected:
// color array and vertex array should be reindexed
void SpriteBatchNodeColorOpacity::removeAndAddSprite(float dt)
{
2021-12-28 16:06:23 +08:00
auto batch = static_cast<SpriteBatchNode*>(getChildByTag(kTagSpriteBatchNode));
auto sprite = static_cast<Sprite*>(batch->getChildByTag(kTagSprite5));
sprite->retain();
batch->removeChild(sprite, false);
batch->addChild(sprite, 0, kTagSprite5);
2021-12-28 16:06:23 +08:00
sprite->release();
}
std::string SpriteBatchNodeColorOpacity::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeColorOpacity::subtitle() const
{
return "Color & Opacity";
}
//------------------------------------------------------------------
//
// SpriteZOrder
//
//------------------------------------------------------------------
SpriteZOrder::SpriteZOrder()
{
_dir = 1;
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
float step = s.width / 11;
for (int i = 0; i < 5; i++)
{
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 0, 121 * 1, 85, 121));
sprite->setPosition(Vec2((i + 1) * step, s.height / 2));
addChild(sprite, i);
}
2021-12-28 16:06:23 +08:00
for (int i = 5; i < 10; i++)
{
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 1, 121 * 0, 85, 121));
sprite->setPosition(Vec2((i + 1) * step, s.height / 2));
addChild(sprite, 14 - i);
}
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 3, 121 * 0, 85, 121));
addChild(sprite, -1, kTagSprite1);
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 2, s.height / 2 - 20));
sprite->setScaleX(6);
sprite->setColor(Color3B::RED);
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteZOrder::reorderSprite, this), 1, "reorder_key");
}
void SpriteZOrder::reorderSprite(float dt)
{
2021-12-28 16:06:23 +08:00
auto sprite = static_cast<Sprite*>(getChildByTag(kTagSprite1));
int z = sprite->getLocalZOrder();
2021-12-28 16:06:23 +08:00
if (z < -1)
_dir = 1;
2021-12-28 16:06:23 +08:00
if (z > 10)
_dir = -1;
2021-12-28 16:06:23 +08:00
z += _dir * 3;
2021-12-28 16:06:23 +08:00
reorderChild(sprite, z);
}
std::string SpriteZOrder::title() const
{
return "Testing Sprite";
}
std::string SpriteZOrder::subtitle() const
{
return "Z order";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeZOrder
//
//------------------------------------------------------------------
SpriteBatchNodeZOrder::SpriteBatchNodeZOrder()
{
_dir = 1;
2021-12-28 16:06:23 +08:00
// small capacity. Testing resizing.
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
2021-12-28 16:06:23 +08:00
addChild(batch, 0, kTagSpriteBatchNode);
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
float step = s.width / 11;
for (int i = 0; i < 5; i++)
{
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 0, 121 * 1, 85, 121));
sprite->setPosition(Vec2((i + 1) * step, s.height / 2));
batch->addChild(sprite, i);
}
2021-12-28 16:06:23 +08:00
for (int i = 5; i < 10; i++)
{
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 1, 121 * 0, 85, 121));
sprite->setPosition(Vec2((i + 1) * step, s.height / 2));
batch->addChild(sprite, 14 - i);
}
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 3, 121 * 0, 85, 121));
batch->addChild(sprite, -1, kTagSprite1);
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 2, s.height / 2 - 20));
sprite->setScaleX(6);
sprite->setColor(Color3B::RED);
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteBatchNodeZOrder::reorderSprite, this), 1, "reorder_key");
}
void SpriteBatchNodeZOrder::reorderSprite(float dt)
{
2021-12-28 16:06:23 +08:00
auto batch = static_cast<SpriteBatchNode*>(getChildByTag(kTagSpriteBatchNode));
auto sprite = static_cast<Sprite*>(batch->getChildByTag(kTagSprite1));
2021-12-28 16:06:23 +08:00
int z = sprite->getLocalZOrder();
2021-12-28 16:06:23 +08:00
if (z < -1)
_dir = 1;
2021-12-28 16:06:23 +08:00
if (z > 10)
_dir = -1;
2021-12-28 16:06:23 +08:00
z += _dir * 3;
batch->reorderChild(sprite, z);
}
std::string SpriteBatchNodeZOrder::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeZOrder::subtitle() const
{
return "Z order";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeReorder
//
//------------------------------------------------------------------
SpriteBatchNodeReorder::SpriteBatchNodeReorder()
{
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
Vector<Sprite*> a;
auto asmtest = SpriteBatchNode::create("animations/ghosts.png");
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 10; i++)
{
auto s1 = Sprite::createWithTexture(asmtest->getTexture(), Rect(0.0f, 0.0f, 50.0f, 50.0f));
metal support for cocos2d-x (#19305) * remove deprecated files * remove some deprecated codes * remove more deprecated codes * remove ui deprecated codes * remove more deprecated codes * remove deprecated codes in ccmenuitem * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes in ui * remove more deprecated codes * remove more deprecated codes * remove more deprecated codes * remove vr related codes and ignore some modules * remove allocator * remove some config * 【Feature】add back-end project file * [Feature] add back-end file * add pipeline descriptor and shader cache * [Feature] support sprite for backend * [Feature] remove unneeded code * [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture * [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture * [Feature] remove macro define to .cpp file * [Feature] add log info * [Feature] add PipelineDescriptor for TriangleCommand * [Feature] add PipelineDescriptor object as member of TriangleCommand * [Feature] add getPipelineDescriptor method * add renderbackend * complete pipeline descriptor * [Feature] add viewport in RenderCommand * set viewport when rendrering * [Feature] occur error when using RendererBackend, to be fixed. * a workaround to fix black screen on macOS 10.14 (#19090) * add rendererbackend init function * fix typo * [Feature] modify testFile * [BugFix] modify shader path * [Feature] set default viewport * fix projection * [Feature] modify log info * [BugFix] change viewport data type to int * [BugFix] add BindGroup to PipelienDescriptor * [BugFix] change a_position to vec3 in sprite.vert * [BugFix] set vertexLayout according to V3F_C4B_T2F structure * [Feature] revert a_position to vec4 * [Feature] renderer should not use gl codes directly * [Feature] it's better not use default value parameter * fix depth test setting * rendererbackend -> renderer * clear color and depth at begin * add metal backend * metal support normalized attribute * simplify codes * update external * add render pass desctriptor in pipeline descriptor * fix warnings * fix crash and memeory leak * refactor Texture2D * put pipeline descriptor into render command * simplify codes * [Feature] update Sprite * fix crash when closing app * [Feature] update SpriteBatchNode and TextureAtlas * support render texture(not finish) * [Feature] remove unused code * make tests work on mac * fix download-deps path error * make tests work on iOS * [Feature] support ttf under normal label effect * refactor triangle command processing * let renderer handle more common commands * refactor backend * make render texture work * [Feature] refactor backend for GL * [Feature]Renaming to make it easy to understand * [Feature] change warp mode to CLAMP_TO_EDGE * fix ghost * simplify visit render queue logic * support progress timer without rial mode * support partcile system * Feature/update label (#149) * [BugFix] fix compile error * [Feature] support outline effect in ios * [Feature] add shader file * [BugFix] fix begin and end RenderPass * [Feature] update CustomCommand * [Feature] revert project.pbxproj * [Feature] simplify codes * [BugFix] pack AI88 to RGBA8888 only when outline enable * [Feature] support shadow effect in Label * [Feature] support BMFont * [Feature] support glow effect * [Feature] simplify shader files * LabelAtlas work * handle blend function correctly * support tile map * don't share buffer in metal * alloc buffer size as needed * support more tilemap * Merge branch 'minggo/metal-support' into feature/updateLabel * minggo/metal-support: support tile map handle blend function correctly LabelAtlas work Feature/update label (#149) support partcile system # Conflicts: # cocos/2d/CCLabel.cpp # cocos/2d/CCSprite.cpp # cocos/2d/CCSpriteBatchNode.cpp # cocos/renderer/CCQuadCommand.cpp # cocos/renderer/CCQuadCommand.h * render texture work without saving file * use global viewport * grid3d works * remove grabber * tiled3d works * [BugFix] fix label bug * [Feature] add updateSubData for buffer * [Feature] remove setVertexCount * support depth test * add callback command * [Feature] add UITest * [Feature] update UITest * [Feature] remove unneeded codes * fix custom command issue * fix layer color blend issue * [BugFix] fix iOS compile error * [Feature] remove unneeded codes * [Feature] fix updateVertexBuffer * layerradial works * add draw test back * fix batch issue * fix compiling error * [BugFix] support ETC1 * [BugFix] get the correct pipelineDescriptor * [BugFix] skip draw when backendTexture nullptr * clipping node support * [Feature] add shader files * fix stencil issue in metal * [Feature] update UILayoutTest * [BugFix] skip drawing when vertexCount is zero * refactor renderer * add set global z order for stencil manager commands * fix warnings caused by type * remove viewport in render command * [Feature] fix warnings caused by type * [BugFix] clear vertexCount and indexCount for CustomComand when needed * [Feature] update clear for CustomCommand * ios use metal * fix viewport issue * fix LayerColorGradient crash * [cmake] transport to android and windows (#160) * save point 1 * compile on windows * run on android * revert useless change * android set CC_ENABLE_CACHE_TEXTURE_DATA to 1 * add initGlew * fix android crash * add TODO new-renderer * review update * revert onGLFWWindowPosCallback * fix android compiling error * Impl progress radial (#162) * progresstimer add radial impl * default drawType to element * dec invoke times of createVertexBuffer (#163) * support depth/stencil format for gl backend * simplify progress timer codes * support motionstreak, effect is wrong * fix motionstreak issue * [Feature] update Scissor Test (#161) * [Feature] update Scissor Test * [Feature] update ScissorTest * [Feature] rename function * [Feature] get constant reference if needed * [Feature] show render status (#164) * improve performance * fix depth state * fill error that triangle vertex/index number bigger than buffer * fix compiline error in release mode * fix buffer conflict between CPU and GPU on iOS/macOS * Renderer refactor (#165) * use one vertes/index buffer with opengl * fix error on windows * custom command support index format config * CCLayer: compact vertex data structure * update comment * fix doc * support fast tilemap * pass index format instead * fix some wrong effect * fix render texture error * fix texture per-element size * fix texture format error * BlendFunc type refactor, GLenum -> backend::BlendFactor (#167) * BlendFunc use backend::BlendFactor as inner field * update comments * use int to replace GLenum * update xcode project fiel * rename to GLBlendConst * add ccConstants.h * update xcode project file * update copyright * remove primitive command * remove CCPrimitive.cpp/.h * remove deprecated files * remove unneeded files * remove multiple view support * remove multiple view support * remove the usage of frame buffer in camera * director don't use frame buffer * remove FrameBuffer * remove BatchCommand * add some api reference * add physics2d back * fix crash when close app on mac * improve render texture * fix rendertexture issue * fix rendertexture issue * simplify codes * CMake support for mac & ios (#169) * update cmake * fix compile error * update 3rd libs version * remove CCThread.h/.cpp * remove ccthread * use audio engine to implement simple audio engine * remove unneeded codes * remove deprecated codes * remove winrt macro * remove CC_USE_WIC * set partcile blend function in more elegant way * remove unneeded codes * remove unneeded codes * cmake works on windows * update project setting * improve performance * GLFloat -> float * sync v3 cmake improvements into metal-support (#172) * pick: modern cmake, compile definitions improvement (#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (#19230) * pick: [lua android] use luajit & template cmake update (#19239) * increase cmake stability , remove tests/CMakeLists.txt (#19261) * cmake win32 Precompiled header (#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (#19291) Related #19289 * little build fix, tests cpp-tests works on mac * sync v3 build related codes into metal-support (#173) * strict initialization for std::array * remove proj.win32 project configs * modern cmake, cmake_cleanup_remove_unused_variables (#19146) * Switch travis CI to xenial (#19207) * Switch travis CI to xenial * Remove language: android * Set language: cpp * Fix java problem * Update sdkmanager * Fix sdkmanger * next sdkmanager fix * Remove xenial from android * revert to sdk-tools-{system}-3859397 * Remove linux cmake install * Update before-install.sh * Update .travis.yml * Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212) * Simplify install-deps-linux.sh * Cleanup * pick: install ninja * update cocos2d-console submodule * for metal-support alpha release, we only test cpp * add HelloCpp into project(Cocos2d-x) for tmp test * update extenal metal-support-4 * update uniform setting * [Feature] update BindGroup * [Feature] empty-test * [Feature] cpp-test * [Feature] fix GL compiler error * [Feature] fix GL crash * [Feature] empty-test * [Feature] cpp-tests * [feature] improve frameRate * [feature] fix opengl compile error * [feature] fix opengl compile error * [BugFix] fix compute maxLocation error * [Feature] update setting unifrom * [Feature] fix namespace * [Feature] remove unneeded code * [Bugfix] fix project file * [Feature] update review * [texture2d] impl texture format support (#175) * texture update * update * update texture * commit * compile on windows * ddd * rename * rename methods * no crash * save gl * save * save * rename * move out pixel format convert functions * metal crash * update * update android * support gles compressed texture format * support more compress format * add more conversion methods * ss * save * update conversion methods * add PVRTC format support * reformat * add marco linux * fix GL marcro * pvrtc supported only by ios 8.0+ * remove unused cmake * revert change * refactor Texture2D::initWithData * fix conversion log * refactor Texture2D::initWithData * remove some OpenGL constants for PVRTC * add todo * fix typo * AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174) * review cpp-tests, and fix part issues on start auto test * sync png format fix: Node:Particle3D abnormal texture effects #19204 * fix cpp-tests SpritePolygon crash, wrong png format (#19170) * fix wrong png convert format from sRGB to Gray * erase plist index if all frames was erased * test_A8.png have I8 format, fix it * [CCSpriteCache] allow re-add plist & add testcase (#19175) * allow re-add plist & add testcase * remove comments/rename method/update testcase * fix isSpriteFramesWithFileLoaded & add testcase * remove used variable * remove unused variable * fix double free issues when js/lua-tests exit on iOS (#19236) * disable part cases, AutoTest works without crash on mac * update cocos2dx files json, to test cocos new next * fix spritecache plist parsing issue (#19269) * [linux] Fix FileUtils::getContents with folder (#19157) * fix FileUtils::getContents on linux/mac * use stat.st_mode * simplify * [CCFileUtils] win32 getFileSize (#19176) * win32 getFileSize * fix stat * [cpp test-Android]20:FileUtils/2 change title (#19197) * sync #19200 * sync #19231 * [android lua] improve performance of lua loader (#19234) * [lua] improve performance of lua loader * remove cache fix * Revert "fix spritecache plist parsing issue (#19269)" This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf. * remove win32 project files ref in template.json * add metal framework lnk ref into cpp template * test on iOS, and disable part cases * alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227) * changes AudioCache to use alBufferData instead of alBufferDataStatic (also makes test 19 faster to trigger openal bugs faster) The original problem: CrashIfClientProvidedBogusAudioBufferList https://github.com/cocos2d/cocos2d-x/issues/18948 is not happening anymore, but there's still a not very frequent issue that makes OpenAL crash with a call stack like this. AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList It happes more frequently when the device is "cold", which means after half an hour of not using the device (locked). I could not find the actual source code for iOS OpenAL, so I used the macOS versions: https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html They seem to use CAGuard.h to make sure the dead buffer list has no threading issues. I'm worried because the CAGuard code I found has macos and win32 define but no iOS, so I'm not sure. I guess the iOS version is different and has the guard. I could not find a place in the code that's unprotected by the locks except the InitializeBufferMap() which should not be called more than once from cocos, and there's a workaround in AudioEngine-impl for it. I reduced the occurence of the CleanUpDeadBufferList crash by moving the guard in ~AudioCache to cover the alDeleteBuffers call. * remove hack method "setTimeout" on audio * AutoTest works on iOS * support set ios deployment target for root project * enable all texture2d cases, since Jiang have fixed * add CCTextureUtils to xcode project file (#176) * add leak cases for SpriteFrameCache (#177) * re-add SpriteFrameCache cases * update template file json * Update SpriteFrameCacheTest.cpp * fix compiling error
2019-01-18 15:08:25 +08:00
a.pushBack(s1);
asmtest->addChild(s1, 10);
}
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 10; i++)
{
2021-12-28 16:06:23 +08:00
if (i != 5)
{
2021-12-28 16:06:23 +08:00
asmtest->reorderChild(static_cast<Node*>(a.at(i)), 9);
}
}
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
ssize_t AX_UNUSED prev = -1;
2021-12-28 16:06:23 +08:00
auto& children = asmtest->getChildren();
2021-12-28 16:06:23 +08:00
for (const auto& obj : children)
{
auto child = static_cast<Sprite*>(obj);
ssize_t currentIndex = child->getAtlasIndex();
2022-07-16 10:43:05 +08:00
AXASSERT(prev == currentIndex - 1, "Child order failed");
////----AXLOG("children %x - atlasIndex:%d", child, currentIndex);
prev = currentIndex;
}
2021-12-28 16:06:23 +08:00
prev = -1;
auto& descendants = asmtest->getDescendants();
2021-12-28 16:06:23 +08:00
for (const auto& sprite : descendants)
{
ssize_t currentIndex = sprite->getAtlasIndex();
2022-07-16 10:43:05 +08:00
AXASSERT(prev == currentIndex - 1, "Child order failed");
////----AXLOG("descendant %x - atlasIndex:%d", child, currentIndex);
prev = currentIndex;
}
}
std::string SpriteBatchNodeReorder::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeReorder::subtitle() const
{
return "reorder #1. Should not crash";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeReorderIssue744
//
//------------------------------------------------------------------
SpriteBatchNodeReorderIssue744::SpriteBatchNodeReorderIssue744()
{
auto s = Director::getInstance()->getWinSize();
// Testing issue #744
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=744
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 15);
2021-12-28 16:06:23 +08:00
addChild(batch, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(0, 0, 85, 121));
sprite->setPosition(Vec2(s.width / 2, s.height / 2));
batch->addChild(sprite, 3);
batch->reorderChild(sprite, 1);
}
std::string SpriteBatchNodeReorderIssue744::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeReorderIssue744::subtitle() const
{
return "reorder issue #744. Should not crash";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeReorderIssue766
//
//------------------------------------------------------------------
Sprite* SpriteBatchNodeReorderIssue766::makeSpriteZ(int aZ)
{
2021-12-28 16:06:23 +08:00
Rect rcw(128, 0, 64, 64);
2022-07-15 19:17:01 +08:00
rcw = AX_RECT_PIXELS_TO_POINTS(rcw);
auto sprite = Sprite::createWithTexture(batchNode->getTexture(), rcw);
2022-07-15 19:17:01 +08:00
sprite->setScale(AX_CONTENT_SCALE_FACTOR());
2021-12-28 16:06:23 +08:00
batchNode->addChild(sprite, aZ + 1, 0);
2021-12-28 16:06:23 +08:00
// children
Rect rc1(0, 0, 64, 64);
2022-07-15 19:17:01 +08:00
rc1 = AX_RECT_PIXELS_TO_POINTS(rc1);
auto spriteShadow = Sprite::createWithTexture(batchNode->getTexture(), rc1);
spriteShadow->setOpacity(128);
2022-07-15 19:17:01 +08:00
sprite->setScale(AX_CONTENT_SCALE_FACTOR());
sprite->addChild(spriteShadow, aZ, 3);
2021-12-28 16:06:23 +08:00
Rect rc2(64, 0, 64, 64);
2022-07-15 19:17:01 +08:00
rc2 = AX_RECT_PIXELS_TO_POINTS(rc2);
auto spriteTop = Sprite::createWithTexture(batchNode->getTexture(), rc2);
2022-07-15 19:17:01 +08:00
sprite->setScale(AX_CONTENT_SCALE_FACTOR());
2021-12-28 16:06:23 +08:00
sprite->addChild(spriteTop, aZ + 2, 3);
return sprite;
}
void SpriteBatchNodeReorderIssue766::reorderSprite(float dt)
{
unschedule("issue_766_key");
batchNode->reorderChild(sprite1, 4);
}
// on "init" you need to initialize your instance
SpriteBatchNodeReorderIssue766::SpriteBatchNodeReorderIssue766()
{
batchNode = SpriteBatchNode::create("Images/piece.png", 15);
addChild(batchNode, 1, 0);
sprite1 = makeSpriteZ(2);
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(200.0f, 160.0f));
sprite2 = makeSpriteZ(3);
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(264.0f, 160.0f));
sprite3 = makeSpriteZ(4);
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(328.0f, 160.0f));
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteBatchNodeReorderIssue766::reorderSprite, this), 2, "issue_766_key");
}
std::string SpriteBatchNodeReorderIssue766::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeReorderIssue766::subtitle() const
{
return "reorder issue #766. In 2 seconds 1 sprite will be reordered";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeReorderIssue767
//
//------------------------------------------------------------------
SpriteBatchNodeReorderIssue767::SpriteBatchNodeReorderIssue767()
{
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/ghosts.plist", "animations/ghosts.png");
2021-12-28 16:06:23 +08:00
Node* aParent;
Sprite *l1, *l2a, *l2b, *l3a1, *l3a2, *l3b1, *l3b2;
//
// SpriteBatchNode: 3 levels of children
//
aParent = SpriteBatchNode::create("animations/ghosts.png");
addChild(aParent, 0, kTagSprite1);
// parent
l1 = Sprite::createWithSpriteFrameName("father.gif");
2021-12-28 16:06:23 +08:00
l1->setPosition(Vec2(s.width / 2, s.height / 2));
aParent->addChild(l1, 0, kTagSprite2);
auto l1Size = l1->getContentSize();
// child left
l2a = Sprite::createWithSpriteFrameName("sister1.gif");
2021-12-28 16:06:23 +08:00
l2a->setPosition(Vec2(-25 + l1Size.width / 2, 0 + l1Size.height / 2));
l1->addChild(l2a, -1, kTagSpriteLeft);
2021-12-28 16:06:23 +08:00
auto l2aSize = l2a->getContentSize();
// child right
l2b = Sprite::createWithSpriteFrameName("sister2.gif");
2021-12-28 16:06:23 +08:00
l2b->setPosition(Vec2(+25 + l1Size.width / 2, 0 + l1Size.height / 2));
l1->addChild(l2b, 1, kTagSpriteRight);
auto l2bSize = l2a->getContentSize();
// child left bottom
l3a1 = Sprite::createWithSpriteFrameName("child1.gif");
l3a1->setScale(0.65f);
2021-12-28 16:06:23 +08:00
l3a1->setPosition(Vec2(0 + l2aSize.width / 2, -50 + l2aSize.height / 2));
l2a->addChild(l3a1, -1);
// child left top
l3a2 = Sprite::createWithSpriteFrameName("child1.gif");
l3a2->setScale(0.65f);
2021-12-28 16:06:23 +08:00
l3a2->setPosition(Vec2(0 + l2aSize.width / 2, +50 + l2aSize.height / 2));
l2a->addChild(l3a2, 1);
// child right bottom
l3b1 = Sprite::createWithSpriteFrameName("child1.gif");
l3b1->setScale(0.65f);
2021-12-28 16:06:23 +08:00
l3b1->setPosition(Vec2(0 + l2bSize.width / 2, -50 + l2bSize.height / 2));
l2b->addChild(l3b1, -1);
// child right top
l3b2 = Sprite::createWithSpriteFrameName("child1.gif");
l3b2->setScale(0.65f);
2021-12-28 16:06:23 +08:00
l3b2->setPosition(Vec2(0 + l2bSize.width / 2, +50 + l2bSize.height / 2));
l2b->addChild(l3b2, 1);
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteBatchNodeReorderIssue767::reorderSprites, this), 1, "issue_767_key");
}
std::string SpriteBatchNodeReorderIssue767::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeReorderIssue767::subtitle() const
{
return "reorder issue #767. Should not crash";
}
void SpriteBatchNodeReorderIssue767::reorderSprites(float dt)
{
2021-12-28 16:06:23 +08:00
auto spritebatch = static_cast<SpriteBatchNode*>(getChildByTag(kTagSprite1));
auto father = static_cast<Sprite*>(spritebatch->getChildByTag(kTagSprite2));
auto left = static_cast<Sprite*>(father->getChildByTag(kTagSpriteLeft));
auto right = static_cast<Sprite*>(father->getChildByTag(kTagSpriteRight));
int newZLeft = 1;
2021-12-28 16:06:23 +08:00
if (left->getLocalZOrder() == 1)
newZLeft = -1;
father->reorderChild(left, newZLeft);
father->reorderChild(right, -newZLeft);
}
//------------------------------------------------------------------
//
// SpriteZVertex
//
//------------------------------------------------------------------
void SpriteZVertex::onEnter()
{
SpriteTestDemo::onEnter();
2021-12-28 16:06:23 +08:00
Director::getInstance()->setProjection(Director::Projection::_3D);
}
void SpriteZVertex::onExit()
{
Director::getInstance()->setProjection(Director::Projection::DEFAULT);
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 responsible for ordering its sprites according to its Z if the sprite has
// transparent parts.
//
//
// Configure shader to mimic glAlphaTest
//
2021-12-28 16:06:23 +08:00
// auto alphaTestShader =
// GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST); GLint
// alphaValueLocation = glGetUniformLocation(alphaTestShader->getProgram(),
// GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
//
// // set alpha test value
// // NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
// if (getGLProgram())
// {
// getGLProgram()->setUniformLocationWith1f(alphaValueLocation, 0.0f);
// }
_dir = 1;
_time = 0;
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
float step = s.width / 12;
auto node = Node::create();
// camera uses the center of the image as the pivoting point
2021-12-28 16:06:23 +08:00
node->setContentSize(Size(s.width, s.height));
node->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
node->setPosition(Vec2(s.width / 2, s.height / 2));
addChild(node, 0);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 5; i++)
{
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 0, 121 * 1, 85, 121));
sprite->setPosition(Vec2((i + 1) * step, s.height / 2));
sprite->setPositionZ(10 + i * 40);
// sprite->setGLProgram(alphaTestShader);
node->addChild(sprite, 0);
}
2021-12-28 16:06:23 +08:00
for (int i = 5; i < 11; i++)
{
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 1, 121 * 0, 85, 121));
sprite->setPosition(Vec2((i + 1) * step, s.height / 2));
sprite->setPositionZ(10 + (10 - i) * 40);
// sprite->setGLProgram(alphaTestShader);
node->addChild(sprite, 0);
}
2021-12-28 16:06:23 +08:00
node->runAction(OrbitCamera::create(10, 1, 0, 0, 360, 0, 0));
}
std::string SpriteZVertex::title() const
{
return "Testing Sprite";
}
std::string SpriteZVertex::subtitle() const
{
return "openGL Z vertex";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeZVertex
//
//------------------------------------------------------------------
void SpriteBatchNodeZVertex::onEnter()
{
SpriteTestDemo::onEnter();
Director::getInstance()->setProjection(Director::Projection::_3D);
}
void SpriteBatchNodeZVertex::onExit()
{
Director::getInstance()->setProjection(Director::Projection::DEFAULT);
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 responsible for ordering its sprites according to its Z if the sprite has
// transparent parts.
//
//
// Configure shader to mimic glAlphaTest
//
2021-12-28 16:06:23 +08:00
// auto alphaTestShader =
// GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST); GLint
// alphaValueLocation = glGetUniformLocation(alphaTestShader->getProgram(),
// GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
// set alpha test value
// NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
2021-12-28 16:06:23 +08:00
// if (getGLProgram())
// {
// getGLProgram()->setUniformLocationWith1f(alphaValueLocation, 0.0f);
// }
auto s = Director::getInstance()->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
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
// camera uses the center of the image as the pivoting point
2021-12-28 16:06:23 +08:00
batch->setContentSize(Size(s.width, s.height));
batch->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
batch->setPosition(Vec2(s.width / 2, s.height / 2));
// batch->setGLProgram(alphaTestShader);
addChild(batch, 0, kTagSpriteBatchNode);
for (int i = 0; i < 5; i++)
{
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 0, 121 * 1, 85, 121));
sprite->setPosition(Vec2((i + 1) * step, s.height / 2));
sprite->setPositionZ(10 + i * 40);
batch->addChild(sprite, 0);
}
2021-12-28 16:06:23 +08:00
for (int i = 5; i < 11; i++)
{
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 1, 121 * 0, 85, 121));
sprite->setPosition(Vec2((i + 1) * step, s.height / 2));
sprite->setPositionZ(10 + (10 - i) * 40);
batch->addChild(sprite, 0);
}
2021-12-28 16:06:23 +08:00
batch->runAction(OrbitCamera::create(10, 1, 0, 0, 360, 0, 0));
}
std::string SpriteBatchNodeZVertex::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeZVertex::subtitle() const
{
return "openGL Z vertex";
}
//------------------------------------------------------------------
//
// SpriteAnchorPoint
//
//------------------------------------------------------------------
SpriteAnchorPoint::SpriteAnchorPoint()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto rotate = RotateBy::create(10, 360);
auto action = RepeatForever::create(rotate);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * i, 121 * 1, 85, 121));
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 10);
2021-12-28 16:06:23 +08:00
switch (i)
{
2021-12-28 16:06:23 +08:00
case 0:
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
sprite->runAction(action->clone());
addChild(sprite, i);
2021-12-28 16:06:23 +08:00
}
}
std::string SpriteAnchorPoint::title() const
{
return "Testing Sprite";
}
std::string SpriteAnchorPoint::subtitle() const
{
return "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
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
2021-12-28 16:06:23 +08:00
addChild(batch, 0, kTagSpriteBatchNode);
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto rotate = RotateBy::create(10, 360);
auto action = RepeatForever::create(rotate);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85 * i, 121 * 1, 85, 121));
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 1);
2021-12-28 16:06:23 +08:00
switch (i)
{
2021-12-28 16:06:23 +08:00
case 0:
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
2021-12-28 16:06:23 +08:00
sprite->runAction(action->clone());
batch->addChild(sprite, i);
}
}
std::string SpriteBatchNodeAnchorPoint::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeAnchorPoint::subtitle() const
{
return "anchor point";
}
//------------------------------------------------------------------
//
// SpriteAnchorPointFromFile
//
//------------------------------------------------------------------
void SpriteAnchorPointFromFile::onEnter()
{
SpriteTestDemo::onEnter();
auto screen = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto rotate = RotateBy::create(10, 360);
auto action = RepeatForever::create(rotate);
char str[100] = {0};
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini_anchors.plist");
2021-12-28 16:06:23 +08:00
Sprite* sprite;
for (int i = 0; i < 10; i++)
{
2021-12-28 16:06:23 +08:00
sprintf(str, "grossini_dance_%02d.png", i + 1);
sprite = Sprite::createWithSpriteFrameName(str);
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(screen.width / 6 * (i % 5 + 1), screen.height * 2 / 3 - screen.height * (i / 5) / 3));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.1f);
point->setPosition(sprite->getPosition());
addChild(point, 10);
2021-12-28 16:06:23 +08:00
sprite->runAction(action->clone());
addChild(sprite, i);
}
2021-12-28 16:06:23 +08:00
Vector<SpriteFrame*> animFrames(5);
2021-12-28 16:06:23 +08:00
for (int i = 9; i < 14; i++)
{
2021-12-28 16:06:23 +08:00
sprintf(str, "grossini_dance_%02d.png", i + 1);
animFrames.pushBack(cache->getSpriteFrameByName(str));
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
}
void SpriteAnchorPointFromFile::onExit()
{
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("animations/grossini_anchors.plist");
SpriteTestDemo::onExit();
}
std::string SpriteAnchorPointFromFile::title() const
{
return "Testing SpriteFrame";
}
std::string SpriteAnchorPointFromFile::subtitle() const
{
return "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
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 1);
addChild(batch, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
batch->setIgnoreAnchorPointForPosition(true);
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
batch->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
batch->setContentSize(Size(s.width, s.height));
// SpriteBatchNode actions
auto rotate = RotateBy::create(5, 360);
auto action = RepeatForever::create(rotate);
// SpriteBatchNode actions
2021-12-28 16:06:23 +08:00
auto rotate_back = rotate->reverse();
auto rotate_seq = Sequence::create(rotate, rotate_back, nullptr);
auto rotate_forever = RepeatForever::create(rotate_seq);
2021-12-28 16:06:23 +08:00
auto scale = ScaleBy::create(5, 1.5f);
auto scale_back = scale->reverse();
auto scale_seq = Sequence::create(scale, scale_back, nullptr);
auto scale_forever = RepeatForever::create(scale_seq);
2021-12-28 16:06:23 +08:00
float step = s.width / 4;
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
2021-12-28 16:06:23 +08:00
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(85 * i, 121 * 1, 85, 121));
sprite->setPosition(Vec2((i + 1) * step, s.height / 2));
2021-12-28 16:06:23 +08:00
sprite->runAction(action->clone());
batch->addChild(sprite, i);
}
2021-12-28 16:06:23 +08:00
batch->runAction(scale_forever);
batch->runAction(rotate_forever);
}
std::string Sprite6::title() const
{
return "SpriteBatchNode transformation";
}
//------------------------------------------------------------------
//
// SpriteFlip
//
//------------------------------------------------------------------
SpriteFlip::SpriteFlip()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto sprite1 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 1, 121 * 1, 85, 121));
sprite1->setPosition(Vec2(s.width / 2 - 100, s.height / 2));
addChild(sprite1, 0, kTagSprite1);
2021-12-28 16:06:23 +08:00
auto sprite2 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 1, 121 * 1, 85, 121));
sprite2->setPosition(Vec2(s.width / 2 + 100, s.height / 2));
addChild(sprite2, 0, kTagSprite2);
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteFlip::flipSprites, this), 1, "sprite_flip_key");
}
void SpriteFlip::flipSprites(float dt)
{
auto sprite1 = static_cast<Sprite*>(getChildByTag(kTagSprite1));
auto sprite2 = static_cast<Sprite*>(getChildByTag(kTagSprite2));
2021-12-28 16:06:23 +08:00
bool x = sprite1->isFlippedX();
bool y = sprite2->isFlippedY();
2021-12-28 16:06:23 +08:00
2022-07-16 10:43:05 +08:00
AXLOG("Pre: %g", sprite1->getContentSize().height);
sprite1->setFlippedX(!x);
sprite2->setFlippedY(!y);
2022-07-16 10:43:05 +08:00
AXLOG("Post: %g", sprite1->getContentSize().height);
}
std::string SpriteFlip::title() const
{
return "Testing Sprite";
}
std::string SpriteFlip::subtitle() const
{
return "Flip X & Y";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeFlip
//
//------------------------------------------------------------------
SpriteBatchNodeFlip::SpriteBatchNodeFlip()
{
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 10);
addChild(batch, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto sprite1 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 1, 121 * 1, 85, 121));
sprite1->setPosition(Vec2(s.width / 2 - 100, s.height / 2));
batch->addChild(sprite1, 0, kTagSprite1);
2021-12-28 16:06:23 +08:00
auto sprite2 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 1, 121 * 1, 85, 121));
sprite2->setPosition(Vec2(s.width / 2 + 100, s.height / 2));
batch->addChild(sprite2, 0, kTagSprite2);
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteBatchNodeFlip::flipSprites, this), 1, "flip_sprites_key");
}
void SpriteBatchNodeFlip::flipSprites(float dt)
{
2021-12-28 16:06:23 +08:00
auto batch = static_cast<SpriteBatchNode*>(getChildByTag(kTagSpriteBatchNode));
auto sprite1 = static_cast<Sprite*>(batch->getChildByTag(kTagSprite1));
auto sprite2 = static_cast<Sprite*>(batch->getChildByTag(kTagSprite2));
2021-12-28 16:06:23 +08:00
bool x = sprite1->isFlippedX();
bool y = sprite2->isFlippedY();
2021-12-28 16:06:23 +08:00
2022-07-16 10:43:05 +08:00
AXLOG("Pre: %g", sprite1->getContentSize().height);
sprite1->setFlippedX(!x);
sprite2->setFlippedY(!y);
2022-07-16 10:43:05 +08:00
AXLOG("Post: %g", sprite1->getContentSize().height);
}
std::string SpriteBatchNodeFlip::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeFlip::subtitle() const
{
return "Flip X & Y";
}
//------------------------------------------------------------------
//
// SpriteAliased
//
//------------------------------------------------------------------
SpriteAliased::SpriteAliased()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto sprite1 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 1, 121 * 1, 85, 121));
sprite1->setPosition(Vec2(s.width / 2 - 100, s.height / 2));
addChild(sprite1, 0, kTagSprite1);
2021-12-28 16:06:23 +08:00
auto sprite2 = Sprite::create("Images/grossini_dance_atlas.png", Rect(85 * 1, 121 * 1, 85, 121));
sprite2->setPosition(Vec2(s.width / 2 + 100, s.height / 2));
addChild(sprite2, 0, kTagSprite2);
2021-12-28 16:06:23 +08:00
auto scale = ScaleBy::create(2, 5);
auto scale_back = scale->reverse();
2021-12-28 16:06:23 +08:00
auto seq = Sequence::create(scale, scale_back, nullptr);
auto repeat = RepeatForever::create(seq);
auto repeat2 = repeat->clone();
2021-12-28 16:06:23 +08:00
sprite1->runAction(repeat);
sprite2->runAction(repeat2);
}
void SpriteAliased::onEnter()
{
SpriteTestDemo::onEnter();
2021-12-28 16:06:23 +08:00
//
// IMPORTANT:
// This change will affect every sprite that uses the same texture
// So sprite1 and sprite2 will be affected by this change
//
2021-12-28 16:06:23 +08:00
auto sprite = static_cast<Sprite*>(getChildByTag(kTagSprite1));
sprite->getTexture()->setAliasTexParameters();
}
void SpriteAliased::onExit()
{
// restore the tex parameter to AntiAliased.
2021-12-28 16:06:23 +08:00
auto sprite = static_cast<Sprite*>(getChildByTag(kTagSprite1));
sprite->getTexture()->setAntiAliasTexParameters();
SpriteTestDemo::onExit();
}
std::string SpriteAliased::title() const
{
return "Testing Sprite";
}
std::string SpriteAliased::subtitle() const
{
return "AliasTexParameters()";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeAliased
//
//------------------------------------------------------------------
SpriteBatchNodeAliased::SpriteBatchNodeAliased()
{
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 10);
addChild(batch, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto sprite1 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 1, 121 * 1, 85, 121));
sprite1->setPosition(Vec2(s.width / 2 - 100, s.height / 2));
batch->addChild(sprite1, 0, kTagSprite1);
2021-12-28 16:06:23 +08:00
auto sprite2 = Sprite::createWithTexture(batch->getTexture(), Rect(85 * 1, 121 * 1, 85, 121));
sprite2->setPosition(Vec2(s.width / 2 + 100, s.height / 2));
batch->addChild(sprite2, 0, kTagSprite2);
2021-12-28 16:06:23 +08:00
auto scale = ScaleBy::create(2, 5);
auto scale_back = scale->reverse();
2021-12-28 16:06:23 +08:00
auto seq = Sequence::create(scale, scale_back, nullptr);
auto repeat = RepeatForever::create(seq);
auto repeat2 = repeat->clone();
2021-12-28 16:06:23 +08:00
sprite1->runAction(repeat);
sprite2->runAction(repeat2);
}
void SpriteBatchNodeAliased::onEnter()
{
SpriteTestDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto batch = static_cast<SpriteBatchNode*>(getChildByTag(kTagSpriteBatchNode));
batch->getTexture()->setAliasTexParameters();
}
void SpriteBatchNodeAliased::onExit()
{
// restore the tex parameter to AntiAliased.
2021-12-28 16:06:23 +08:00
auto batch = static_cast<SpriteBatchNode*>(getChildByTag(kTagSpriteBatchNode));
batch->getTexture()->setAntiAliasTexParameters();
SpriteTestDemo::onExit();
}
std::string SpriteBatchNodeAliased::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeAliased::subtitle() const
{
return "AliasTexParameters()";
}
//------------------------------------------------------------------
//
// SpriteNewTexture
//
//------------------------------------------------------------------
SpriteNewTexture::SpriteNewTexture()
{
2021-12-28 16:06:23 +08:00
auto listener = EventListenerTouchAllAtOnce::create();
2022-07-15 19:17:01 +08:00
listener->onTouchesEnded = AX_CALLBACK_2(SpriteNewTexture::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
2021-12-28 16:06:23 +08:00
auto node = Node::create();
addChild(node, 0, kTagSpriteBatchNode);
_texture1 = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas.png");
_texture1->retain();
_texture2 = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas-mono.png");
_texture2->retain();
2021-12-28 16:06:23 +08:00
_usingTexture1 = true;
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 30; i++)
addNewSprite();
}
SpriteNewTexture::~SpriteNewTexture()
{
_texture1->release();
_texture2->release();
}
void SpriteNewTexture::addNewSprite()
{
auto s = Director::getInstance()->getWinSize();
2022-07-16 10:43:05 +08:00
auto p = Vec2(AXRANDOM_0_1() * s.width, AXRANDOM_0_1() * s.height);
2022-07-16 10:43:05 +08:00
int idx = AXRANDOM_0_1() * 1400 / 100;
2021-12-28 16:06:23 +08:00
int x = (idx % 5) * 85;
int y = (idx / 5) * 121;
auto node = getChildByTag(kTagSpriteBatchNode);
auto sprite = Sprite::createWithTexture(_texture1, Rect(x, y, 85, 121));
node->addChild(sprite);
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(p.x, p.y));
ActionInterval* action;
2022-07-16 10:43:05 +08:00
float random = AXRANDOM_0_1();
2021-12-28 16:06:23 +08:00
if (random < 0.20)
action = ScaleBy::create(3, 2);
2021-12-28 16:06:23 +08:00
else if (random < 0.40)
action = RotateBy::create(3, 360);
2021-12-28 16:06:23 +08:00
else if (random < 0.60)
action = Blink::create(1, 3);
2021-12-28 16:06:23 +08:00
else if (random < 0.8)
action = TintBy::create(2, 0, -255, -255);
2021-12-28 16:06:23 +08:00
else
action = FadeOut::create(2);
auto action_back = action->reverse();
2021-12-28 16:06:23 +08:00
auto seq = Sequence::create(action, action_back, nullptr);
sprite->runAction(RepeatForever::create(seq));
}
void SpriteNewTexture::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
2021-12-28 16:06:23 +08:00
auto node = getChildByTag(kTagSpriteBatchNode);
auto& children = node->getChildren();
Sprite* sprite;
2021-12-28 16:06:23 +08:00
if (_usingTexture1) //--> win32 : Let's it make just simple sentence
{
2021-12-28 16:06:23 +08:00
for (const auto& obj : children)
{
sprite = static_cast<Sprite*>(obj);
sprite->setTexture(_texture2);
}
_usingTexture1 = false;
2021-12-28 16:06:23 +08:00
}
else
{
2021-12-28 16:06:23 +08:00
for (const auto& obj : children)
{
sprite = static_cast<Sprite*>(obj);
sprite->setTexture(_texture1);
}
_usingTexture1 = true;
}
}
std::string SpriteNewTexture::title() const
{
return "Testing Sprite";
}
std::string SpriteNewTexture::subtitle() const
{
return "setTexture() (tap / touch the screen)";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeNewTexture
//
//------------------------------------------------------------------
SpriteBatchNodeNewTexture::SpriteBatchNodeNewTexture()
{
2021-12-28 16:06:23 +08:00
auto listener = EventListenerTouchAllAtOnce::create();
2022-07-15 19:17:01 +08:00
listener->onTouchesEnded = AX_CALLBACK_2(SpriteBatchNodeNewTexture::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
2021-12-28 16:06:23 +08:00
auto batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 50);
addChild(batch, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
_texture1 = batch->getTexture();
_texture1->retain();
_texture2 = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas-mono.png");
_texture2->retain();
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 30; i++)
addNewSprite();
}
SpriteBatchNodeNewTexture::~SpriteBatchNodeNewTexture()
{
_texture1->release();
_texture2->release();
}
void SpriteBatchNodeNewTexture::addNewSprite()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
2022-07-16 10:43:05 +08:00
auto p = Vec2(AXRANDOM_0_1() * s.width, AXRANDOM_0_1() * s.height);
2021-12-28 16:06:23 +08:00
auto batch = static_cast<SpriteBatchNode*>(getChildByTag(kTagSpriteBatchNode));
2022-07-16 10:43:05 +08:00
int idx = AXRANDOM_0_1() * 1400 / 100;
2021-12-28 16:06:23 +08:00
int x = (idx % 5) * 85;
int y = (idx / 5) * 121;
auto sprite = Sprite::createWithTexture(batch->getTexture(), Rect(x, y, 85, 121));
batch->addChild(sprite);
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(p.x, p.y));
ActionInterval* action;
2022-07-16 10:43:05 +08:00
float random = AXRANDOM_0_1();
2021-12-28 16:06:23 +08:00
if (random < 0.20)
action = ScaleBy::create(3, 2);
2021-12-28 16:06:23 +08:00
else if (random < 0.40)
action = RotateBy::create(3, 360);
2021-12-28 16:06:23 +08:00
else if (random < 0.60)
action = Blink::create(1, 3);
2021-12-28 16:06:23 +08:00
else if (random < 0.8)
action = TintBy::create(2, 0, -255, -255);
2021-12-28 16:06:23 +08:00
else
action = FadeOut::create(2);
auto action_back = action->reverse();
2021-12-28 16:06:23 +08:00
auto seq = Sequence::create(action, action_back, nullptr);
sprite->runAction(RepeatForever::create(seq));
}
void SpriteBatchNodeNewTexture::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
2021-12-28 16:06:23 +08:00
auto batch = static_cast<SpriteBatchNode*>(getChildByTag(kTagSpriteBatchNode));
if (batch->getTexture() == _texture1)
batch->setTexture(_texture2);
else
2021-12-28 16:06:23 +08:00
batch->setTexture(_texture1);
}
std::string SpriteBatchNodeNewTexture::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeNewTexture::subtitle() const
{
return "setTexture() (tap / touch the screen)";
}
//------------------------------------------------------------------
//
// SpriteFrameTest
//
//------------------------------------------------------------------
void SpriteFrameTest::onEnter()
{
SpriteTestDemo::onEnter();
auto s = Director::getInstance()->getWinSize();
// IMPORTANT:
// The sprite frames will be cached AND RETAINED, and they won't be released unless you call
// SpriteFrameCache::getInstance()->removeUnusedSpriteFrames);
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
cache->addSpriteFramesWithFile("animations/grossini_blue.plist", "animations/grossini_blue.png");
//
// Animation using Sprite BatchNode
//
_sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
_sprite1->setPosition(Vec2(s.width / 2 - 80, s.height / 2));
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
spritebatch->addChild(_sprite1);
addChild(spritebatch);
Vector<SpriteFrame*> animFrames(15);
char str[100] = {0};
2021-12-28 16:06:23 +08:00
for (int i = 1; i < 15; i++)
{
sprintf(str, "grossini_dance_%02d.png", i);
2021-12-28 16:06:23 +08:00
auto frame = cache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
2021-12-28 16:06:23 +08:00
_sprite1->runAction(RepeatForever::create(Animate::create(animation)));
// to test issue #732, uncomment the following line
_sprite1->setFlippedX(false);
_sprite1->setFlippedY(false);
//
// Animation using standard Sprite
//
_sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
_sprite2->setPosition(Vec2(s.width / 2 + 80, s.height / 2));
addChild(_sprite2);
Vector<SpriteFrame*> moreFrames(20);
2021-12-28 16:06:23 +08:00
for (int i = 1; i < 15; i++)
{
2021-12-28 16:06:23 +08:00
sprintf(str, "grossini_dance_gray_%02d.png", i);
auto frame = cache->getSpriteFrameByName(str);
moreFrames.pushBack(frame);
}
2021-12-28 16:06:23 +08:00
for (int i = 1; i < 5; i++)
{
sprintf(str, "grossini_blue_%02d.png", i);
auto frame = cache->getSpriteFrameByName(str);
moreFrames.pushBack(frame);
}
// append frames from another batch
moreFrames.pushBack(animFrames);
auto animMixed = Animation::createWithSpriteFrames(moreFrames, 0.3f);
2021-12-28 16:06:23 +08:00
_sprite2->runAction(RepeatForever::create(Animate::create(animMixed)));
// to test issue #732, uncomment the following line
_sprite2->setFlippedX(false);
_sprite2->setFlippedY(false);
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteFrameTest::startIn05Secs, this), 0.5f, "in_05_secs_key");
_counter = 0;
}
void SpriteFrameTest::onExit()
{
SpriteTestDemo::onExit();
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
cache->removeSpriteFramesFromFile("animations/grossini_blue.plist");
}
std::string SpriteFrameTest::title() const
{
return "Sprite vs. SpriteBatchNode";
}
std::string SpriteFrameTest::subtitle() const
{
return "Animation. Testing issue #792";
}
void SpriteFrameTest::startIn05Secs(float dt)
{
unschedule("in_05_secs_key");
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteFrameTest::flipSprites, this), 1.0f, "flip_sprites_key");
}
void SpriteFrameTest::flipSprites(float dt)
{
_counter++;
bool fx = false;
bool fy = false;
2021-12-28 16:06:23 +08:00
int i = _counter % 4;
2021-12-28 16:06:23 +08:00
switch (i)
{
case 0:
fx = false;
fy = false;
break;
case 1:
fx = true;
fy = false;
break;
case 2:
fx = false;
fy = true;
break;
case 3:
fx = true;
fy = true;
break;
}
_sprite1->setFlippedX(fx);
_sprite1->setFlippedY(fy);
_sprite2->setFlippedX(fx);
_sprite2->setFlippedY(fy);
2021-12-28 16:06:23 +08:00
// NSLog(@"flipX:%d, flipY:%d", fx, fy);
}
//------------------------------------------------------------------
//
// SpriteFrameAliasNameTest
//
//------------------------------------------------------------------
void SpriteFrameAliasNameTest::onEnter()
{
SpriteTestDemo::onEnter();
auto s = Director::getInstance()->getWinSize();
// IMPORTANT:
// The sprite frames will be cached AND RETAINED, and they won't be released unless you call
// SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
//
// SpriteFrameCache is a cache of SpriteFrames
// SpriteFrames each contain a texture id and a rect (frame).
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini-aliases.plist", "animations/grossini-aliases.png");
//
// Animation using Sprite batch
//
// A SpriteBatchNode can reference one and only one texture (one .png file)
// Sprites that are contained in that texture can be instantiated as Sprites and then added to the SpriteBatchNode
// All Sprites added to a SpriteBatchNode are drawn in one OpenGL ES draw call
2021-12-28 16:06:23 +08:00
// If the Sprites are not added to a SpriteBatchNode then an OpenGL ES draw call will be needed for each one, which
// is less efficient
//
2021-12-28 16:06:23 +08:00
// When you animate a sprite, Animation changes the frame of the sprite using setDisplayFrame: (this is why the
// animation must be in the same texture) When setDisplayFrame: is used in the Animation it changes the frame to one
// specified by the SpriteFrames that were added to the animation, but texture id is still the same and so the
// sprite is still a child of the SpriteBatchNode, and therefore all the animation sprites are also drawn as part of
// the SpriteBatchNode
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setPosition(Vec2(s.width * 0.5f, s.height * 0.5f));
auto spriteBatch = SpriteBatchNode::create("animations/grossini-aliases.png");
spriteBatch->addChild(sprite);
addChild(spriteBatch);
Vector<SpriteFrame*> animFrames(15);
char str[100] = {0};
2021-12-28 16:06:23 +08:00
for (int i = 1; i < 15; i++)
{
// Obtain frames by alias name
sprintf(str, "dance_%02d", i);
auto frame = cache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
// 14 frames * 1sec = 14 seconds
sprite->runAction(RepeatForever::create(Animate::create(animation)));
cache->reloadTexture("animations/grossini-aliases.plist");
}
void SpriteFrameAliasNameTest::onExit()
{
SpriteTestDemo::onExit();
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("animations/grossini-aliases.plist");
}
std::string SpriteFrameAliasNameTest::title() const
{
return "SpriteFrame Alias Name";
}
std::string SpriteFrameAliasNameTest::subtitle() const
{
return "SpriteFrames are obtained using the alias name";
}
2014-08-01 14:39:45 +08:00
//------------------------------------------------------------------
//
// SpriteFramesFromFileContent
//
//------------------------------------------------------------------
void SpriteFramesFromFileContent::onEnter()
{
2021-12-28 16:06:23 +08:00
SpriteTestDemo::onEnter();
auto s = Director::getInstance()->getWinSize();
2014-08-01 14:39:45 +08:00
Data plist_content = FileUtils::getInstance()->getDataFromFile(sheetName() + ".plist");
Data image_content = FileUtils::getInstance()->getDataFromFile(sheetName() + ".png");
2014-08-01 14:39:45 +08:00
2021-12-28 16:06:23 +08:00
Image* image = new Image();
image->initWithImageData((const uint8_t*)image_content.getBytes(), image_content.getSize());
Texture2D* texture = new Texture2D();
texture->initWithImage(image);
texture->autorelease();
2014-08-01 14:39:45 +08:00
2022-07-15 19:17:01 +08:00
AX_SAFE_RELEASE(image);
2014-08-01 14:39:45 +08:00
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFileContent(plist_content, texture);
2014-08-01 14:39:45 +08:00
2021-12-28 16:06:23 +08:00
//
// Animation using Sprite BatchNode
//
Sprite* sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
sprite->setPosition(Vec2(s.width / 2, s.height / 2));
addChild(sprite);
Vector<SpriteFrame*> animFrames(15);
2014-08-01 14:39:45 +08:00
2021-12-28 16:06:23 +08:00
char str[100] = {0};
for (int i = 1; i < 15; i++)
{
sprintf(str, "grossini_dance_%02d.png", i);
auto frame = cache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
2014-08-01 14:39:45 +08:00
2021-12-28 16:06:23 +08:00
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
2014-08-01 14:39:45 +08:00
}
void SpriteFramesFromFileContent::onExit()
{
2021-12-28 16:06:23 +08:00
SpriteTestDemo::onExit();
2014-08-01 14:39:45 +08:00
2021-12-28 16:06:23 +08:00
std::string plist_content = FileUtils::getInstance()->getStringFromFile("animations/grossini.plist");
2014-08-01 14:39:45 +08:00
2021-12-28 16:06:23 +08:00
SpriteFrameCache::getInstance()->removeSpriteFramesFromFileContent(plist_content);
2014-08-01 14:39:45 +08:00
}
std::string SpriteFramesFromFileContent::title() const
{
2021-12-28 16:06:23 +08:00
return "SpriteFrameCache load form file content";
2014-08-01 14:39:45 +08:00
}
std::string SpriteFramesFromFileContent::subtitle() const
{
2021-12-28 16:06:23 +08:00
return "SpriteFrameCache load from plist file content";
2014-08-01 14:39:45 +08:00
}
std::string SpriteFramesFromFileContent::sheetName() const
{
return "animations/grossini";
}
//------------------------------------------------------------------
//
// SpritePolygonFromFileContent
//
//------------------------------------------------------------------
std::string SpritePolygonFromFileContent::subtitle() const
{
return "SpriteFrameCache load polygon info from plist file";
}
std::string SpritePolygonFromFileContent::sheetName() const
{
return "animations/grossini_polygon";
}
//------------------------------------------------------------------
//
// SpriteOffsetAnchorRotation
//
//------------------------------------------------------------------
void SpriteOffsetAnchorRotation::onEnter()
{
SpriteTestDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite batch
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 1);
2021-12-28 16:06:23 +08:00
switch (i)
{
2021-12-28 16:06:23 +08:00
case 0:
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
Vector<SpriteFrame*> animFrames(14);
char str[100] = {0};
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 14; i++)
{
2021-12-28 16:06:23 +08:00
sprintf(str, "grossini_dance_%02d.png", (i + 1));
auto frame = cache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(Animate::create(animation)));
sprite->runAction(RepeatForever::create(RotateBy::create(10, 360)));
addChild(sprite, 0);
2021-12-28 16:06:23 +08:00
}
}
void SpriteOffsetAnchorRotation::onExit()
{
SpriteTestDemo::onExit();
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteOffsetAnchorRotation::title() const
{
return "Testing Sprite";
}
std::string SpriteOffsetAnchorRotation::subtitle() const
{
return "offset + anchor + rotation";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeOffsetAnchorRotation
//
//------------------------------------------------------------------
SpriteBatchNodeOffsetAnchorRotation::SpriteBatchNodeOffsetAnchorRotation()
{
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
addChild(spritebatch);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite BatchNode
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 200);
2021-12-28 16:06:23 +08:00
switch (i)
{
2021-12-28 16:06:23 +08:00
case 0:
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
Vector<SpriteFrame*> animFrames(14);
char str[100] = {0};
2021-12-28 16:06:23 +08:00
for (int k = 0; k < 14; k++)
{
2021-12-28 16:06:23 +08:00
sprintf(str, "grossini_dance_%02d.png", (k + 1));
auto frame = cache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(Animate::create(animation)));
sprite->runAction(RepeatForever::create(RotateBy::create(10, 360)));
spritebatch->addChild(sprite, i);
2021-12-28 16:06:23 +08:00
}
}
void SpriteBatchNodeOffsetAnchorRotation::onExit()
{
SpriteTestDemo::onExit();
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteBatchNodeOffsetAnchorRotation::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeOffsetAnchorRotation::subtitle() const
{
return "offset + anchor + rotation";
}
//------------------------------------------------------------------
//
// SpriteOffsetAnchorScale
//
//------------------------------------------------------------------
SpriteOffsetAnchorScale::SpriteOffsetAnchorScale()
{
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite BatchNode
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 1);
2021-12-28 16:06:23 +08:00
switch (i)
{
2021-12-28 16:06:23 +08:00
case 0:
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
Vector<SpriteFrame*> animFrames(14);
char str[100] = {0};
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 14; i++)
{
2021-12-28 16:06:23 +08:00
sprintf(str, "grossini_dance_%02d.png", (i + 1));
auto frame = cache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(Animate::create(animation)));
auto scale = ScaleBy::create(2, 2);
auto scale_back = scale->reverse();
2021-12-28 16:06:23 +08:00
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
sprite->runAction(RepeatForever::create(seq_scale));
2021-12-28 16:06:23 +08:00
addChild(sprite, 0);
2021-12-28 16:06:23 +08:00
}
}
void SpriteOffsetAnchorScale::onExit()
{
SpriteTestDemo::onExit();
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteOffsetAnchorScale::title() const
{
return "Testing Sprite";
}
std::string SpriteOffsetAnchorScale::subtitle() const
{
return "offset + anchor + scale";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeOffsetAnchorScale
//
//------------------------------------------------------------------
SpriteBatchNodeOffsetAnchorScale::SpriteBatchNodeOffsetAnchorScale()
{
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
auto spritesheet = SpriteBatchNode::create("animations/grossini.png");
addChild(spritesheet);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite BatchNode
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 200);
2021-12-28 16:06:23 +08:00
switch (i)
{
case 0:
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
Vector<SpriteFrame*> animFrames(14);
char str[100] = {0};
2021-12-28 16:06:23 +08:00
for (int k = 0; k < 14; k++)
{
2021-12-28 16:06:23 +08:00
sprintf(str, "grossini_dance_%02d.png", (k + 1));
auto frame = cache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(Animate::create(animation)));
2021-12-28 16:06:23 +08:00
auto scale = ScaleBy::create(2, 2);
auto scale_back = scale->reverse();
2021-12-28 16:06:23 +08:00
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
sprite->runAction(RepeatForever::create(seq_scale));
spritesheet->addChild(sprite, i);
2021-12-28 16:06:23 +08:00
}
}
void SpriteBatchNodeOffsetAnchorScale::onExit()
{
SpriteTestDemo::onExit();
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteBatchNodeOffsetAnchorScale::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeOffsetAnchorScale::subtitle() const
{
return "offset + anchor + scale";
}
//------------------------------------------------------------------
//
// SpriteAnimationSplit
//
//------------------------------------------------------------------
SpriteAnimationSplit::SpriteAnimationSplit()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto texture = Director::getInstance()->getTextureCache()->addImage("animations/dragon_animation.png");
2021-12-28 16:06:23 +08:00
// manually add frames to the frame cache
2021-12-28 16:06:23 +08:00
auto frame0 = SpriteFrame::createWithTexture(texture, Rect(132 * 0, 132 * 0, 132, 132));
auto frame1 = SpriteFrame::createWithTexture(texture, Rect(132 * 1, 132 * 0, 132, 132));
auto frame2 = SpriteFrame::createWithTexture(texture, Rect(132 * 2, 132 * 0, 132, 132));
auto frame3 = SpriteFrame::createWithTexture(texture, Rect(132 * 3, 132 * 0, 132, 132));
auto frame4 = SpriteFrame::createWithTexture(texture, Rect(132 * 0, 132 * 1, 132, 132));
auto frame5 = SpriteFrame::createWithTexture(texture, Rect(132 * 1, 132 * 1, 132, 132));
//
// Animation using Sprite BatchNode
//
auto sprite = Sprite::createWithSpriteFrame(frame0);
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 2 - 80, s.height / 2));
addChild(sprite);
2021-12-28 16:06:23 +08:00
Vector<SpriteFrame*> animFrames(6);
animFrames.pushBack(frame0);
animFrames.pushBack(frame1);
animFrames.pushBack(frame2);
animFrames.pushBack(frame3);
animFrames.pushBack(frame4);
animFrames.pushBack(frame5);
2021-12-28 16:06:23 +08:00
auto animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
2021-12-28 16:06:23 +08:00
auto animate = Animate::create(animation);
auto seq = Sequence::create(animate, FlipX::create(true), animate->clone(), FlipX::create(false), nullptr);
sprite->runAction(RepeatForever::create(seq));
}
void SpriteAnimationSplit::onExit()
{
SpriteTestDemo::onExit();
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
}
std::string SpriteAnimationSplit::title() const
{
return "Sprite: Animation + flip";
}
//------------------------------------------------------------------
//
// SpriteHybrid
//
//------------------------------------------------------------------
SpriteHybrid::SpriteHybrid()
{
auto s = Director::getInstance()->getWinSize();
// parents
auto parent1 = Node::create();
auto parent2 = SpriteBatchNode::create("animations/grossini.png", 50);
2021-12-28 16:06:23 +08:00
addChild(parent1, 0, kTagNode);
addChild(parent2, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
// IMPORTANT:
// The sprite frames will be cached AND RETAINED, and they won't be released unless you call
// SpriteFrameCache::getInstance()->removeUnusedSpriteFrames);
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
2021-12-28 16:06:23 +08:00
// create 250 sprites
// only show 80% of them
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 250; i++)
{
2022-07-16 10:43:05 +08:00
int spriteIdx = AXRANDOM_0_1() * 14;
2021-12-28 16:06:23 +08:00
char str[25] = {0};
sprintf(str, "grossini_dance_%02d.png", (spriteIdx + 1));
auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str);
auto sprite = Sprite::createWithSpriteFrame(frame);
parent1->addChild(sprite, i, i);
2021-12-28 16:06:23 +08:00
float x = -1000;
float y = -1000;
2022-07-16 10:43:05 +08:00
if (AXRANDOM_0_1() < 0.2f)
{
2022-07-16 10:43:05 +08:00
x = AXRANDOM_0_1() * s.width;
y = AXRANDOM_0_1() * s.height;
}
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(x, y));
auto action = RotateBy::create(4, 360);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(action));
}
2021-12-28 16:06:23 +08:00
_usingSpriteBatchNode = false;
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(SpriteHybrid::reparentSprite, this), 2, "reparent_sprite_key");
}
void SpriteHybrid::reparentSprite(float dt)
{
auto p1 = getChildByTag(kTagNode);
2021-12-28 16:06:23 +08:00
auto p2 = getChildByTag(kTagSpriteBatchNode);
Vector<Node*> retArray(250);
2021-12-28 16:06:23 +08:00
if (_usingSpriteBatchNode)
std::swap(p1, p2);
2022-07-16 10:43:05 +08:00
////----AXLOG("New parent is: %x", p2);
2021-12-28 16:06:23 +08:00
auto& p1Children = p1->getChildren();
2021-12-28 16:06:23 +08:00
for (const auto& node : p1Children)
{
retArray.pushBack(node);
}
2021-12-28 16:06:23 +08:00
int i = 0;
p1->removeAllChildrenWithCleanup(false);
2021-12-28 16:06:23 +08:00
for (const auto& node : retArray)
{
p2->addChild(node, i, i);
i++;
}
2021-12-28 16:06:23 +08:00
_usingSpriteBatchNode = !_usingSpriteBatchNode;
}
void SpriteHybrid::onExit()
{
SpriteTestDemo::onExit();
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("animations/grossini.plist");
}
std::string SpriteHybrid::title() const
{
return "HybridSprite* sprite Test";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeChildren
//
//------------------------------------------------------------------
SpriteBatchNodeChildren::SpriteBatchNodeChildren()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
// parents
auto batch = SpriteBatchNode::create("animations/grossini.png", 50);
2021-12-28 16:06:23 +08:00
addChild(batch, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
2021-12-28 16:06:23 +08:00
auto sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 3, s.height / 2));
auto sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(50.0f, 50.0f));
auto sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-50.0f, -50.0f));
batch->addChild(sprite1);
sprite1->addChild(sprite2);
sprite1->addChild(sprite3);
2021-12-28 16:06:23 +08:00
// BEGIN NEW CODE
Vector<SpriteFrame*> animFrames(14);
char str[100] = {0};
2021-12-28 16:06:23 +08:00
for (int i = 1; i < 15; i++)
{
2021-12-28 16:06:23 +08:00
sprintf(str, "grossini_dance_%02d.png", i);
auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
2021-12-28 16:06:23 +08:00
auto animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
2021-12-28 16:06:23 +08:00
sprite1->runAction(RepeatForever::create(Animate::create(animation)));
// END NEW CODE
2021-12-28 16:06:23 +08:00
auto action = MoveBy::create(2, Vec2(200.0f, 0.0f));
auto action_back = action->reverse();
auto action_rot = RotateBy::create(2.0f, 360.0f);
auto action_s = ScaleBy::create(2.0f, 2.0f);
auto action_s_back = action_s->reverse();
2021-12-28 16:06:23 +08:00
auto seq2 = action_rot->reverse();
2021-12-28 16:06:23 +08:00
sprite2->runAction(RepeatForever::create(seq2));
2021-12-28 16:06:23 +08:00
sprite1->runAction(RepeatForever::create(action_rot));
sprite1->runAction(RepeatForever::create(Sequence::create(action, action_back, nullptr)));
sprite1->runAction(RepeatForever::create(Sequence::create(action_s, action_s_back, nullptr)));
}
void SpriteBatchNodeChildren::onExit()
{
SpriteTestDemo::onExit();
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
}
std::string SpriteBatchNodeChildren::title() const
{
return "SpriteBatchNode Grand Children";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeChildrenZ
//
//------------------------------------------------------------------
SpriteBatchNodeChildrenZ::SpriteBatchNodeChildrenZ()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
// parents
SpriteBatchNode* batch;
2021-12-28 16:06:23 +08:00
Sprite *sprite1, *sprite2, *sprite3;
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
2021-12-28 16:06:23 +08:00
// test 1
batch = SpriteBatchNode::create("animations/grossini.png", 50);
addChild(batch, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 3, s.height / 2));
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
batch->addChild(sprite1);
sprite1->addChild(sprite2, 2);
sprite1->addChild(sprite3, -2);
2021-12-28 16:06:23 +08:00
// test 2
batch = SpriteBatchNode::create("animations/grossini.png", 50);
addChild(batch, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(2 * s.width / 3, s.height / 2));
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
batch->addChild(sprite1);
sprite1->addChild(sprite2, -2);
sprite1->addChild(sprite3, 2);
2021-12-28 16:06:23 +08:00
// test 3
batch = SpriteBatchNode::create("animations/grossini.png", 50);
addChild(batch, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 2 - 90, s.height / 4));
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(s.width / 2 - 60, s.height / 4));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(s.width / 2 - 30, s.height / 4));
batch->addChild(sprite1, 10);
batch->addChild(sprite2, -10);
batch->addChild(sprite3, -5);
// test 4
batch = SpriteBatchNode::create("animations/grossini.png", 50);
addChild(batch, 0, kTagSpriteBatchNode);
2021-12-28 16:06:23 +08:00
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 2 + 30, s.height / 4));
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(s.width / 2 + 60, s.height / 4));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(s.width / 2 + 90, s.height / 4));
batch->addChild(sprite1, -10);
batch->addChild(sprite2, -5);
batch->addChild(sprite3, -2);
}
void SpriteBatchNodeChildrenZ::onExit()
{
SpriteTestDemo::onExit();
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
}
std::string SpriteBatchNodeChildrenZ::title() const
{
return "SpriteBatchNode Children Z";
}
//------------------------------------------------------------------
//
// SpriteChildrenVisibility
//
//------------------------------------------------------------------
SpriteChildrenVisibility::SpriteChildrenVisibility()
{
auto s = Director::getInstance()->getWinSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
2021-12-28 16:06:23 +08:00
Node* aParent;
Sprite *sprite1, *sprite2, *sprite3;
//
// SpriteBatchNode
//
// parents
aParent = SpriteBatchNode::create("animations/grossini.png", 50);
2021-12-28 16:06:23 +08:00
aParent->setPosition(Vec2(s.width / 3, s.height / 2));
addChild(aParent, 0);
2021-12-28 16:06:23 +08:00
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(0.0f, 0.0f));
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
aParent->addChild(sprite1);
sprite1->addChild(sprite2, -2);
sprite1->addChild(sprite3, 2);
2021-12-28 16:06:23 +08:00
sprite1->runAction(Blink::create(5.0f, 10.0f));
2021-12-28 16:06:23 +08:00
//
// Sprite
//
aParent = Node::create();
2021-12-28 16:06:23 +08:00
aParent->setPosition(Vec2(2 * s.width / 3, s.height / 2));
addChild(aParent, 0);
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(0.0f, 0.0f));
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
aParent->addChild(sprite1);
sprite1->addChild(sprite2, -2);
sprite1->addChild(sprite3, 2);
2021-12-28 16:06:23 +08:00
sprite1->runAction(Blink::create(5.0f, 10.0f));
}
void SpriteChildrenVisibility::onExit()
{
SpriteTestDemo::onExit();
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
}
std::string SpriteChildrenVisibility::title() const
{
return "Sprite & SpriteBatchNode Visibility";
}
//------------------------------------------------------------------
//
// SpriteChildrenVisibilityIssue665
//
//------------------------------------------------------------------
SpriteChildrenVisibilityIssue665::SpriteChildrenVisibilityIssue665()
{
auto s = Director::getInstance()->getWinSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
2021-12-28 16:06:23 +08:00
Node* aParent;
Sprite *sprite1, *sprite2, *sprite3;
//
// SpriteBatchNode
//
// parents
aParent = SpriteBatchNode::create("animations/grossini.png", 50);
2021-12-28 16:06:23 +08:00
aParent->setPosition(Vec2(s.width / 3, s.height / 2));
addChild(aParent, 0);
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(0.0f, 0.0f));
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
// test issue #665
sprite1->setVisible(false);
aParent->addChild(sprite1);
sprite1->addChild(sprite2, -2);
sprite1->addChild(sprite3, 2);
//
// Sprite
//
aParent = Node::create();
2021-12-28 16:06:23 +08:00
aParent->setPosition(Vec2(2 * s.width / 3, s.height / 2));
addChild(aParent, 0);
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(0.0f, 0.0f));
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
// test issue #665
sprite1->setVisible(false);
aParent->addChild(sprite1);
sprite1->addChild(sprite2, -2);
sprite1->addChild(sprite3, 2);
}
SpriteChildrenVisibilityIssue665::~SpriteChildrenVisibilityIssue665()
{
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
}
std::string SpriteChildrenVisibilityIssue665::title() const
{
return "Sprite & SpriteBatchNode Visibility";
}
std::string SpriteChildrenVisibilityIssue665::subtitle() const
{
return "No sprites should be visible";
}
//------------------------------------------------------------------
//
// SpriteChildrenAnchorPoint
//
//------------------------------------------------------------------
SpriteChildrenAnchorPoint::SpriteChildrenAnchorPoint()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
2021-12-28 16:06:23 +08:00
Node* aParent;
Sprite *sprite1, *sprite2, *sprite3, *sprite4, *point;
//
// SpriteBatchNode
//
// parents
2021-12-28 16:06:23 +08:00
aParent = Node::create();
addChild(aParent, 0);
2021-12-28 16:06:23 +08:00
// anchor (0,0)
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 4, s.height / 2));
sprite1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
2021-12-28 16:06:23 +08:00
sprite4->setPosition(Vec2(0.0f, 0.0f));
sprite4->setScale(0.5f);
aParent->addChild(sprite1);
sprite1->addChild(sprite2, -2);
sprite1->addChild(sprite3, -2);
sprite1->addChild(sprite4, 3);
2021-12-28 16:06:23 +08:00
point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite1->getPosition());
addChild(point, 10);
2021-12-28 16:06:23 +08:00
// anchor (0.5, 0.5)
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 2, s.height / 2));
sprite1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
2021-12-28 16:06:23 +08:00
sprite4->setPosition(Vec2(0.0f, 0.0f));
sprite4->setScale(0.5f);
aParent->addChild(sprite1);
sprite1->addChild(sprite2, -2);
sprite1->addChild(sprite3, -2);
sprite1->addChild(sprite4, 3);
2021-12-28 16:06:23 +08:00
point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite1->getPosition());
addChild(point, 10);
// anchor (1,1)
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 2 + s.width / 4, s.height / 2));
sprite1->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
2021-12-28 16:06:23 +08:00
sprite4->setPosition(Vec2(0.0f, 0.0f));
sprite4->setScale(0.5f);
aParent->addChild(sprite1);
sprite1->addChild(sprite2, -2);
sprite1->addChild(sprite3, -2);
sprite1->addChild(sprite4, 3);
2021-12-28 16:06:23 +08:00
point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite1->getPosition());
addChild(point, 10);
}
void SpriteChildrenAnchorPoint::onExit()
{
SpriteTestDemo::onExit();
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
}
std::string SpriteChildrenAnchorPoint::title() const
{
return "Testing Sprite";
}
std::string SpriteChildrenAnchorPoint::subtitle() const
{
return "children + anchor point";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeChildrenAnchorPoint
//
//------------------------------------------------------------------
SpriteBatchNodeChildrenAnchorPoint::SpriteBatchNodeChildrenAnchorPoint()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
2021-12-28 16:06:23 +08:00
Node* aParent;
Sprite *sprite1, *sprite2, *sprite3, *sprite4, *point;
//
// SpriteBatchNode
//
// parents
2021-12-28 16:06:23 +08:00
aParent = SpriteBatchNode::create("animations/grossini.png", 50);
addChild(aParent, 0);
2021-12-28 16:06:23 +08:00
// anchor (0,0)
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 4, s.height / 2));
sprite1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
2021-12-28 16:06:23 +08:00
sprite4->setPosition(Vec2(0.0f, 0.0f));
sprite4->setScale(0.5f);
aParent->addChild(sprite1);
sprite1->addChild(sprite2, -2);
sprite1->addChild(sprite3, -2);
sprite1->addChild(sprite4, 3);
2021-12-28 16:06:23 +08:00
point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite1->getPosition());
addChild(point, 10);
2021-12-28 16:06:23 +08:00
// anchor (0.5, 0.5)
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 2, s.height / 2));
sprite1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
2021-12-28 16:06:23 +08:00
sprite4->setPosition(Vec2(0.0f, 0.0f));
sprite4->setScale(0.5f);
aParent->addChild(sprite1);
sprite1->addChild(sprite2, -2);
sprite1->addChild(sprite3, -2);
sprite1->addChild(sprite4, 3);
2021-12-28 16:06:23 +08:00
point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite1->getPosition());
addChild(point, 10);
// anchor (1,1)
sprite1 = Sprite::createWithSpriteFrameName("grossini_dance_08.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 2 + s.width / 4, s.height / 2));
sprite1->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
sprite2 = Sprite::createWithSpriteFrameName("grossini_dance_02.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(20.0f, 30.0f));
sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_03.png");
2021-12-28 16:06:23 +08:00
sprite3->setPosition(Vec2(-20.0f, 30.0f));
sprite4 = Sprite::createWithSpriteFrameName("grossini_dance_04.png");
2021-12-28 16:06:23 +08:00
sprite4->setPosition(Vec2(0.0f, 0.0f));
sprite4->setScale(0.5f);
aParent->addChild(sprite1);
sprite1->addChild(sprite2, -2);
sprite1->addChild(sprite3, -2);
sprite1->addChild(sprite4, 3);
2021-12-28 16:06:23 +08:00
point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite1->getPosition());
addChild(point, 10);
}
void SpriteBatchNodeChildrenAnchorPoint::onExit()
{
SpriteTestDemo::onExit();
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
}
std::string SpriteBatchNodeChildrenAnchorPoint::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeChildrenAnchorPoint::subtitle() const
{
return "children + anchor point";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeChildrenScale
//
//------------------------------------------------------------------
SpriteBatchNodeChildrenScale::SpriteBatchNodeChildrenScale()
{
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
2021-12-28 16:06:23 +08:00
Node* aParent;
Sprite *sprite1, *sprite2;
auto rot = RotateBy::create(10, 360);
auto seq = RepeatForever::create(rot);
2021-12-28 16:06:23 +08:00
//
// Children + Scale using Sprite
// Test 1
//
aParent = Node::create();
sprite1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 4, s.height / 4));
sprite1->setScaleX(-0.5f);
sprite1->setScaleY(2.0f);
sprite1->runAction(seq);
2021-12-28 16:06:23 +08:00
sprite2 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(50, 0));
addChild(aParent);
aParent->addChild(sprite1);
sprite1->addChild(sprite2);
//
// Children + Scale using SpriteBatchNode
// Test 2
//
2021-12-28 16:06:23 +08:00
aParent = SpriteBatchNode::create("animations/grossini_family.png");
sprite1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(3 * s.width / 4, s.height / 4));
sprite1->setScaleX(-0.5f);
sprite1->setScaleY(2.0f);
sprite1->runAction(seq->clone());
sprite2 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(50, 0));
addChild(aParent);
aParent->addChild(sprite1);
sprite1->addChild(sprite2);
//
// Children + Scale using Sprite
// Test 3
//
2021-12-28 16:06:23 +08:00
aParent = Node::create();
sprite1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(s.width / 4, 2 * s.height / 3));
sprite1->setScaleX(1.5f);
sprite1->setScaleY(-0.5f);
sprite1->runAction(seq->clone());
sprite2 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(50, 0));
addChild(aParent);
aParent->addChild(sprite1);
sprite1->addChild(sprite2);
2021-12-28 16:06:23 +08:00
//
// Children + Scale using Sprite
// Test 4
//
2021-12-28 16:06:23 +08:00
aParent = SpriteBatchNode::create("animations/grossini_family.png");
sprite1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(Vec2(3 * s.width / 4, 2 * s.height / 3));
sprite1->setScaleX(1.5f);
sprite1->setScaleY(-0.5f);
sprite1->runAction(seq->clone());
sprite2 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(50, 0));
addChild(aParent);
aParent->addChild(sprite1);
sprite1->addChild(sprite2);
}
std::string SpriteBatchNodeChildrenScale::title() const
{
return "Testing Sprite / SpriteBatchNode";
}
std::string SpriteBatchNodeChildrenScale::subtitle() const
{
return "child + scale + rot";
}
//------------------------------------------------------------------
//
// SpriteChildrenChildren
//
//------------------------------------------------------------------
SpriteChildrenChildren::SpriteChildrenChildren()
{
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/ghosts.plist");
2021-12-28 16:06:23 +08:00
Node* aParent;
Sprite *l1, *l2a, *l2b, *l3a1, *l3a2, *l3b1, *l3b2;
auto rot = RotateBy::create(10, 360);
auto seq = RepeatForever::create(rot);
2021-12-28 16:06:23 +08:00
auto rot_back = rot->reverse();
auto rot_back_fe = RepeatForever::create(rot_back);
2021-12-28 16:06:23 +08:00
//
// SpriteBatchNode: 3 levels of children
//
2021-12-28 16:06:23 +08:00
aParent = Node::create();
addChild(aParent);
2021-12-28 16:06:23 +08:00
// parent
l1 = Sprite::createWithSpriteFrameName("father.gif");
2021-12-28 16:06:23 +08:00
l1->setPosition(Vec2(s.width / 2, s.height / 2));
l1->runAction(seq->clone());
aParent->addChild(l1);
auto l1Size = l1->getContentSize();
2021-12-28 16:06:23 +08:00
// child left
l2a = Sprite::createWithSpriteFrameName("sister1.gif");
2021-12-28 16:06:23 +08:00
l2a->setPosition(Vec2(-50 + l1Size.width / 2, 0 + l1Size.height / 2));
l2a->runAction(rot_back_fe->clone());
l1->addChild(l2a);
2021-12-28 16:06:23 +08:00
auto l2aSize = l2a->getContentSize();
// child right
l2b = Sprite::createWithSpriteFrameName("sister2.gif");
2021-12-28 16:06:23 +08:00
l2b->setPosition(Vec2(+50 + l1Size.width / 2, 0 + l1Size.height / 2));
l2b->runAction(rot_back_fe->clone());
l1->addChild(l2b);
2021-12-28 16:06:23 +08:00
auto l2bSize = l2a->getContentSize();
// child left bottom
l3a1 = Sprite::createWithSpriteFrameName("child1.gif");
2021-12-28 16:06:23 +08:00
l3a1->setScale(0.45f);
l3a1->setPosition(Vec2(0 + l2aSize.width / 2, -100 + l2aSize.height / 2));
l2a->addChild(l3a1);
2021-12-28 16:06:23 +08:00
// child left top
l3a2 = Sprite::createWithSpriteFrameName("child1.gif");
2021-12-28 16:06:23 +08:00
l3a2->setScale(0.45f);
l3a1->setPosition(Vec2(0 + l2aSize.width / 2, +100 + l2aSize.height / 2));
l2a->addChild(l3a2);
2021-12-28 16:06:23 +08:00
// child right bottom
l3b1 = Sprite::createWithSpriteFrameName("child1.gif");
2021-12-28 16:06:23 +08:00
l3b1->setScale(0.45f);
l3b1->setFlippedY(true);
l3b1->setPosition(Vec2(0 + l2bSize.width / 2, -100 + l2bSize.height / 2));
l2b->addChild(l3b1);
2021-12-28 16:06:23 +08:00
// child right top
l3b2 = Sprite::createWithSpriteFrameName("child1.gif");
2021-12-28 16:06:23 +08:00
l3b2->setScale(0.45f);
l3b2->setFlippedY(true);
l3b1->setPosition(Vec2(0 + l2bSize.width / 2, +100 + l2bSize.height / 2));
l2b->addChild(l3b2);
}
std::string SpriteChildrenChildren::title() const
{
return "Testing Sprite";
}
std::string SpriteChildrenChildren::subtitle() const
{
return "multiple levels of children";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeChildrenChildren
//
//------------------------------------------------------------------
SpriteBatchNodeChildrenChildren::SpriteBatchNodeChildrenChildren()
{
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/ghosts.plist");
2021-12-28 16:06:23 +08:00
SpriteBatchNode* aParent;
Sprite *l1, *l2a, *l2b, *l3a1, *l3a2, *l3b1, *l3b2;
auto rot = RotateBy::create(10, 360);
auto seq = RepeatForever::create(rot);
2021-12-28 16:06:23 +08:00
auto rot_back = rot->reverse();
auto rot_back_fe = RepeatForever::create(rot_back);
2021-12-28 16:06:23 +08:00
//
// SpriteBatchNode: 3 levels of children
//
2021-12-28 16:06:23 +08:00
aParent = SpriteBatchNode::create("animations/ghosts.png");
2021-12-28 16:06:23 +08:00
// TODO: minggo
// aParent->getTexture()->generateMipmap();
addChild(aParent);
2021-12-28 16:06:23 +08:00
// parent
l1 = Sprite::createWithSpriteFrameName("father.gif");
2021-12-28 16:06:23 +08:00
l1->setPosition(Vec2(s.width / 2, s.height / 2));
l1->runAction(seq->clone());
aParent->addChild(l1);
auto l1Size = l1->getContentSize();
// child left
l2a = Sprite::createWithSpriteFrameName("sister1.gif");
2021-12-28 16:06:23 +08:00
l2a->setPosition(Vec2(-50 + l1Size.width / 2, 0 + l1Size.height / 2));
l2a->runAction(rot_back_fe->clone());
l1->addChild(l2a);
2021-12-28 16:06:23 +08:00
auto l2aSize = l2a->getContentSize();
// child right
l2b = Sprite::createWithSpriteFrameName("sister2.gif");
2021-12-28 16:06:23 +08:00
l2b->setPosition(Vec2(+50 + l1Size.width / 2, 0 + l1Size.height / 2));
l2b->runAction(rot_back_fe->clone());
l1->addChild(l2b);
2021-12-28 16:06:23 +08:00
auto l2bSize = l2a->getContentSize();
// child left bottom
l3a1 = Sprite::createWithSpriteFrameName("child1.gif");
2021-12-28 16:06:23 +08:00
l3a1->setScale(0.45f);
l3a1->setPosition(Vec2(0 + l2aSize.width / 2, -100 + l2aSize.height / 2));
l2a->addChild(l3a1);
2021-12-28 16:06:23 +08:00
// child left top
l3a2 = Sprite::createWithSpriteFrameName("child1.gif");
2021-12-28 16:06:23 +08:00
l3a2->setScale(0.45f);
l3a1->setPosition(Vec2(0 + l2aSize.width / 2, +100 + l2aSize.height / 2));
l2a->addChild(l3a2);
2021-12-28 16:06:23 +08:00
// child right bottom
l3b1 = Sprite::createWithSpriteFrameName("child1.gif");
2021-12-28 16:06:23 +08:00
l3b1->setScale(0.45f);
l3b1->setFlippedY(true);
l3b1->setPosition(Vec2(0 + l2bSize.width / 2, -100 + l2bSize.height / 2));
l2b->addChild(l3b1);
// child right top
l3b2 = Sprite::createWithSpriteFrameName("child1.gif");
2021-12-28 16:06:23 +08:00
l3b2->setScale(0.45f);
l3b2->setFlippedY(true);
l3b1->setPosition(Vec2(0 + l2bSize.width / 2, +100 + l2bSize.height / 2));
l2b->addChild(l3b2);
}
std::string SpriteBatchNodeChildrenChildren::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeChildrenChildren::subtitle() const
{
return "multiple levels of children";
}
//------------------------------------------------------------------
//
// SpriteBatchNodeSkewNegativeScaleChildren
//
//------------------------------------------------------------------
SpriteBatchNodeSkewNegativeScaleChildren::SpriteBatchNodeSkewNegativeScaleChildren()
{
auto s = Director::getInstance()->getWinSize();
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
addChild(spritebatch);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 2; i++)
{
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
// Skew
2021-12-28 16:06:23 +08:00
auto skewX = SkewBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = SkewBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
2021-12-28 16:06:23 +08:00
if (i == 1)
{
sprite->setScale(-1.0f);
}
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
auto child1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
child1->setPosition(Vec2(sprite->getContentSize().width / 2.0f, sprite->getContentSize().height / 2.0f));
child1->setScale(0.8f);
sprite->addChild(child1);
spritebatch->addChild(sprite, i);
}
}
SpriteBatchNodeSkewNegativeScaleChildren::~SpriteBatchNodeSkewNegativeScaleChildren()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteBatchNodeSkewNegativeScaleChildren::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeSkewNegativeScaleChildren::subtitle() const
{
return "skew + negative scale with children";
}
// SpriteSkewNegativeScaleChildren
SpriteSkewNegativeScaleChildren::SpriteSkewNegativeScaleChildren()
{
auto s = Director::getInstance()->getWinSize();
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
auto parent = Node::create();
addChild(parent);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 2; i++)
{
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
// Skew
2021-12-28 16:06:23 +08:00
auto skewX = SkewBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = SkewBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
2021-12-28 16:06:23 +08:00
if (i == 1)
{
sprite->setScale(-1.0f);
}
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
auto child1 = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
child1->setPosition(Vec2(sprite->getContentSize().width / 2.0f, sprite->getContentSize().height / 2.0f));
sprite->addChild(child1);
child1->setScale(0.8f);
parent->addChild(sprite, i);
}
}
SpriteSkewNegativeScaleChildren::~SpriteSkewNegativeScaleChildren()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteSkewNegativeScaleChildren::title() const
{
return "Testing Sprite";
}
std::string SpriteSkewNegativeScaleChildren::subtitle() const
{
return "skew + negative scale with children";
}
//------------------------------------------------------------------
//
// SpriteNilTexture
//
//------------------------------------------------------------------
SpriteNilTexture::SpriteNilTexture()
{
auto s = Director::getInstance()->getWinSize();
Sprite* sprite = nullptr;
2021-12-28 16:06:23 +08:00
// TEST: If no texture is given, then Opacity + Color should work.
sprite = Sprite::create();
2021-12-28 16:06:23 +08:00
sprite->setTextureRect(Rect(0, 0, 300, 300));
sprite->setColor(Color3B::RED);
sprite->setOpacity(128);
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(3 * s.width / 4, s.height / 2));
addChild(sprite, 100);
sprite = Sprite::create();
2021-12-28 16:06:23 +08:00
sprite->setTextureRect(Rect(0.0f, 0.0f, 300.0f, 300.0f));
sprite->setColor(Color3B::BLUE);
sprite->setOpacity(128);
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(1 * s.width / 4, s.height / 2));
addChild(sprite, 100);
}
std::string SpriteNilTexture::title() const
{
return "Sprite without texture";
}
std::string SpriteNilTexture::subtitle() const
{
return "opacity and color should work";
}
class MySprite1 : public Sprite
{
public:
CREATE_FUNC(MySprite1);
MySprite1() {}
2021-12-28 15:58:56 +08:00
static MySprite1* createWithSpriteFrameName(std::string_view spriteFrameName)
{
auto sprite = MySprite1::create();
sprite->setSpriteFrame(spriteFrameName);
return sprite;
}
};
class MySprite2 : public Sprite
{
public:
CREATE_FUNC(MySprite2);
MySprite2() {}
2021-12-28 15:58:56 +08:00
static MySprite2* create(std::string_view name)
{
auto sprite = MySprite2::create();
2021-12-28 16:06:23 +08:00
sprite->setTexture(name);
return sprite;
}
};
//------------------------------------------------------------------
//
// SpriteSubclass
//
//------------------------------------------------------------------
SpriteSubclass::SpriteSubclass()
{
auto s = Director::getInstance()->getWinSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/ghosts.plist");
auto aParent = SpriteBatchNode::create("animations/ghosts.png");
// MySprite1
2021-12-28 16:06:23 +08:00
MySprite1* sprite = MySprite1::createWithSpriteFrameName("father.gif");
sprite->setPosition(Vec2(s.width / 4 * 1, s.height / 2));
aParent->addChild(sprite);
addChild(aParent);
// MySprite2
2021-12-28 16:06:23 +08:00
MySprite2* sprite2 = MySprite2::create("Images/grossini.png");
addChild(sprite2);
2021-12-28 16:06:23 +08:00
sprite2->setPosition(Vec2(s.width / 4 * 3, s.height / 2));
}
std::string SpriteSubclass::title() const
{
return "Sprite subclass";
}
std::string SpriteSubclass::subtitle() const
{
return "Testing initWithTexture:rect method";
}
//------------------------------------------------------------------
//
// AnimationCache
//
//------------------------------------------------------------------
AnimationCacheTest::AnimationCacheTest()
{
auto frameCache = SpriteFrameCache::getInstance();
frameCache->addSpriteFramesWithFile("animations/grossini.plist");
frameCache->addSpriteFramesWithFile("animations/grossini_gray.plist");
frameCache->addSpriteFramesWithFile("animations/grossini_blue.plist");
//
// create animation "dance"
//
Vector<SpriteFrame*> animFrames(15);
char str[100] = {0};
2021-12-28 16:06:23 +08:00
for (int i = 1; i < 15; i++)
{
2021-12-28 16:06:23 +08:00
sprintf(str, "grossini_dance_%02d.png", i);
auto frame = frameCache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
// Add an animation to the Cache
AnimationCache::getInstance()->addAnimation(animation, "dance");
//
// create animation "dance gray"
//
animFrames.clear();
2021-12-28 16:06:23 +08:00
for (int i = 1; i < 15; i++)
{
2021-12-28 16:06:23 +08:00
sprintf(str, "grossini_dance_gray_%02d.png", i);
auto frame = frameCache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
// Add an animation to the Cache
AnimationCache::getInstance()->addAnimation(animation, "dance_gray");
//
// create animation "dance blue"
//
animFrames.clear();
2021-12-28 16:06:23 +08:00
for (int i = 1; i < 4; i++)
{
2021-12-28 16:06:23 +08:00
sprintf(str, "grossini_blue_%02d.png", i);
auto frame = frameCache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
// Add an animation to the Cache
AnimationCache::getInstance()->addAnimation(animation, "dance_blue");
auto animCache = AnimationCache::getInstance();
auto normal = animCache->getAnimation("dance");
normal->setRestoreOriginalFrame(true);
auto dance_grey = animCache->getAnimation("dance_gray");
dance_grey->setRestoreOriginalFrame(true);
auto dance_blue = animCache->getAnimation("dance_blue");
dance_blue->setRestoreOriginalFrame(true);
auto animN = Animate::create(normal);
auto animG = Animate::create(dance_grey);
auto animB = Animate::create(dance_blue);
auto seq = Sequence::create(animN, animG, animB, nullptr);
// create an sprite without texture
auto grossini = Sprite::create();
2021-12-28 16:06:23 +08:00
auto frame = frameCache->getSpriteFrameByName("grossini_dance_01.png");
grossini->setSpriteFrame(frame);
auto winSize = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
grossini->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
addChild(grossini);
// run the animation
grossini->runAction(seq);
}
AnimationCacheTest::~AnimationCacheTest()
{
auto frameCache = SpriteFrameCache::getInstance();
frameCache->removeSpriteFramesFromFile("animations/grossini.plist");
frameCache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
frameCache->removeSpriteFramesFromFile("animations/grossini_blue.plist");
}
std::string AnimationCacheTest::title() const
{
return "AnimationCache";
}
std::string AnimationCacheTest::subtitle() const
{
return "Sprite should be animated";
}
// AnimationCacheFile
AnimationCacheFile::AnimationCacheFile()
{
auto frameCache = SpriteFrameCache::getInstance();
frameCache->addSpriteFramesWithFile("animations/grossini.plist");
frameCache->addSpriteFramesWithFile("animations/grossini_gray.plist");
frameCache->addSpriteFramesWithFile("animations/grossini_blue.plist");
// Purge previously loaded animation
AnimationCache::destroyInstance();
auto animCache = AnimationCache::getInstance();
// Add an animation to the Cache
animCache->addAnimationsWithFile("animations/animations.plist");
auto normal = animCache->getAnimation("dance_1");
normal->setRestoreOriginalFrame(true);
auto dance_grey = animCache->getAnimation("dance_2");
dance_grey->setRestoreOriginalFrame(true);
auto dance_blue = animCache->getAnimation("dance_3");
dance_blue->setRestoreOriginalFrame(true);
auto animN = Animate::create(normal);
auto animG = Animate::create(dance_grey);
auto animB = Animate::create(dance_blue);
auto seq = Sequence::create(animN, animG, animB, nullptr);
// create an sprite without texture
auto grossini = Sprite::create();
auto frame = frameCache->getSpriteFrameByName("grossini_dance_01.png");
grossini->setSpriteFrame(frame);
auto winSize = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
grossini->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
addChild(grossini);
// run the animation
grossini->runAction(seq);
}
AnimationCacheFile::~AnimationCacheFile()
{
auto frameCache = SpriteFrameCache::getInstance();
frameCache->removeSpriteFramesFromFile("animations/grossini.plist");
frameCache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
frameCache->removeSpriteFramesFromFile("animations/grossini_blue.plist");
}
std::string AnimationCacheFile::title() const
{
return "AnimationCache - Load file";
}
std::string AnimationCacheFile::subtitle() const
{
return "Sprite should be animated";
}
// SpriteBatchBug1217
SpriteBatchBug1217::SpriteBatchBug1217()
{
auto bn = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 15);
auto s1 = Sprite::createWithTexture(bn->getTexture(), Rect(0.0f, 0.0f, 57.0f, 57.0f));
auto s2 = Sprite::createWithTexture(bn->getTexture(), Rect(0.0f, 0.0f, 57.0f, 57.0f));
auto s3 = Sprite::createWithTexture(bn->getTexture(), Rect(0.0f, 0.0f, 57.0f, 57.0f));
s1->setColor(Color3B(255, 0, 0));
s2->setColor(Color3B(0, 255, 0));
s3->setColor(Color3B(0, 0, 255));
2021-12-28 16:06:23 +08:00
s1->setPosition(Vec2(20.0f, 200.0f));
s2->setPosition(Vec2(100.0f, 0.0f));
s3->setPosition(Vec2(100.0f, 0.0f));
2021-12-28 16:06:23 +08:00
bn->setPosition(Vec2(0.0f, 0.0f));
//!!!!!
s1->addChild(s2);
s2->addChild(s3);
bn->addChild(s1);
addChild(bn);
}
std::string SpriteBatchBug1217::title() const
{
return "SpriteBatch - Bug 1217";
}
std::string SpriteBatchBug1217::subtitle() const
{
return "Adding big family to spritebatch. You shall see 3 heads";
}
//
// SpriteOffsetAnchorSkew
2021-12-28 16:06:23 +08:00
//
SpriteOffsetAnchorSkew::SpriteOffsetAnchorSkew()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite batch
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 1);
switch (i)
{
case 0:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
point->setPosition(sprite->getPosition());
Vector<SpriteFrame*> animFrames(14);
char tmp[50];
for (int j = 0; j < 14; j++)
2021-12-28 16:06:23 +08:00
{
sprintf(tmp, "grossini_dance_%02d.png", j + 1);
auto frame = cache->getSpriteFrameByName(tmp);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
2021-12-28 16:06:23 +08:00
auto skewX = SkewBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = SkewBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
addChild(sprite, 0);
}
}
SpriteOffsetAnchorSkew::~SpriteOffsetAnchorSkew()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteOffsetAnchorSkew::title() const
{
return "Testing Sprite";
}
std::string SpriteOffsetAnchorSkew::subtitle() const
{
return "offset + anchor + skew";
}
//
// SpriteBatchNodeOffsetAnchorSkew
2021-12-28 16:06:23 +08:00
//
SpriteBatchNodeOffsetAnchorSkew::SpriteBatchNodeOffsetAnchorSkew()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
addChild(spritebatch);
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite batch
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 200);
switch (i)
{
case 0:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
2021-12-28 16:06:23 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
point->setPosition(sprite->getPosition());
2021-12-28 16:06:23 +08:00
Vector<SpriteFrame*> animFrames(14);
char tmp[50];
for (int j = 0; j < 14; j++)
2021-12-28 16:06:23 +08:00
{
sprintf(tmp, "grossini_dance_%02d.png", j + 1);
auto frame = cache->getSpriteFrameByName(tmp);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
2021-12-28 16:06:23 +08:00
auto skewX = SkewBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = SkewBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
spritebatch->addChild(sprite, i);
}
}
SpriteBatchNodeOffsetAnchorSkew::~SpriteBatchNodeOffsetAnchorSkew()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteBatchNodeOffsetAnchorSkew::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeOffsetAnchorSkew::subtitle() const
{
return "offset + anchor + skew";
}
//
// SpriteOffsetAnchorSkewScale
//
SpriteOffsetAnchorSkewScale::SpriteOffsetAnchorSkewScale()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite batch
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 1);
switch (i)
{
case 0:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
2021-12-28 16:06:23 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
point->setPosition(sprite->getPosition());
Vector<SpriteFrame*> animFrames(14);
char tmp[50];
for (int j = 0; j < 14; j++)
2021-12-28 16:06:23 +08:00
{
sprintf(tmp, "grossini_dance_%02d.png", j + 1);
auto frame = cache->getSpriteFrameByName(tmp);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
// Skew
2021-12-28 16:06:23 +08:00
auto skewX = SkewBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = SkewBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
// Scale
2021-12-28 16:06:23 +08:00
auto scale = ScaleBy::create(2, 2);
auto scale_back = scale->reverse();
2021-12-28 16:06:23 +08:00
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
sprite->runAction(RepeatForever::create(seq_scale));
addChild(sprite, 0);
}
}
SpriteOffsetAnchorSkewScale::~SpriteOffsetAnchorSkewScale()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteOffsetAnchorSkewScale::title() const
{
return "Testing Sprite";
}
std::string SpriteOffsetAnchorSkewScale::subtitle() const
{
return "anchor + skew + scale";
}
///
SpriteBatchNodeOffsetAnchorSkewScale::SpriteBatchNodeOffsetAnchorSkewScale()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
addChild(spritebatch);
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite batch
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 200);
switch (i)
{
case 0:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
2021-12-28 16:06:23 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
Vector<SpriteFrame*> animFrames(14);
char tmp[50];
for (int j = 0; j < 14; j++)
2021-12-28 16:06:23 +08:00
{
sprintf(tmp, "grossini_dance_%02d.png", j + 1);
auto frame = cache->getSpriteFrameByName(tmp);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
// skew
2021-12-28 16:06:23 +08:00
auto skewX = SkewBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = SkewBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
2021-12-28 16:06:23 +08:00
// scale
auto scale = ScaleBy::create(2, 2);
auto scale_back = scale->reverse();
2021-12-28 16:06:23 +08:00
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
sprite->runAction(RepeatForever::create(seq_scale));
spritebatch->addChild(sprite, i);
}
}
SpriteBatchNodeOffsetAnchorSkewScale::~SpriteBatchNodeOffsetAnchorSkewScale()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteBatchNodeOffsetAnchorSkewScale::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeOffsetAnchorSkewScale::subtitle() const
{
return "anchor + skew + scale";
}
//
// SpriteOffsetAnchorFlip
2021-12-28 16:06:23 +08:00
//
SpriteOffsetAnchorFlip::SpriteOffsetAnchorFlip()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite batch
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 1);
switch (i)
{
case 0:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
2021-12-28 16:06:23 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
point->setPosition(sprite->getPosition());
Vector<SpriteFrame*> animFrames(14);
char tmp[50];
for (int j = 0; j < 14; j++)
2021-12-28 16:06:23 +08:00
{
sprintf(tmp, "grossini_dance_%02d.png", i + 1);
auto frame = cache->getSpriteFrameByName(tmp);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
2021-12-28 16:06:23 +08:00
auto flip = FlipY::create(true);
auto flip_back = FlipY::create(false);
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(1);
auto seq = Sequence::create(delay, flip, delay->clone(), flip_back, nullptr);
sprite->runAction(RepeatForever::create(seq));
addChild(sprite, 0);
}
}
SpriteOffsetAnchorFlip::~SpriteOffsetAnchorFlip()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteOffsetAnchorFlip::title() const
{
return "Testing Sprite";
}
std::string SpriteOffsetAnchorFlip::subtitle() const
{
return "issue #1078: offset + anchor + flip";
}
//
// SpriteBatchNodeOffsetAnchorFlip
2021-12-28 16:06:23 +08:00
//
SpriteBatchNodeOffsetAnchorFlip::SpriteBatchNodeOffsetAnchorFlip()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
addChild(spritebatch);
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite batch
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 200);
switch (i)
{
case 0:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
2021-12-28 16:06:23 +08:00
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
Vector<SpriteFrame*> animFrames(14);
char tmp[50];
for (int j = 0; j < 14; j++)
2021-12-28 16:06:23 +08:00
{
sprintf(tmp, "grossini_dance_%02d.png", i + 1);
auto frame = cache->getSpriteFrameByName(tmp);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
2021-12-28 16:06:23 +08:00
auto flip = FlipY::create(true);
auto flip_back = FlipY::create(false);
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(1);
auto seq = Sequence::create(delay, flip, delay->clone(), flip_back, nullptr);
sprite->runAction(RepeatForever::create(seq));
spritebatch->addChild(sprite, i);
}
}
SpriteBatchNodeOffsetAnchorFlip::~SpriteBatchNodeOffsetAnchorFlip()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteBatchNodeOffsetAnchorFlip::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeOffsetAnchorFlip::subtitle() const
{
return "issue #1078: offset + anchor + flip";
}
/// NodeSort
NodeSort::NodeSort()
{
_node = Node::create();
addChild(_node, 0, 0);
_sprite1 = Sprite::create("Images/piece.png", Rect(128.0f, 0.0f, 64.0f, 64.0f));
_sprite1->setPosition(Vec2(100.0f, 160.0f));
_node->addChild(_sprite1, -6, 1);
_sprite2 = Sprite::create("Images/piece.png", Rect(128.0f, 0.0f, 64.0f, 64.0f));
_sprite2->setPosition(Vec2(164.0f, 160.0f));
_node->addChild(_sprite2, -6, 2);
_sprite4 = Sprite::create("Images/piece.png", Rect(128.0f, 0.0f, 64.0f, 64.0f));
_sprite4->setPosition(Vec2(292.0f, 160.0f));
_node->addChild(_sprite4, -3, 4);
_sprite3 = Sprite::create("Images/piece.png", Rect(128.0f, 0.0f, 64.0f, 64.0f));
_sprite3->setPosition(Vec2(228.0f, 160.0f));
_node->addChild(_sprite3, -4, 3);
_sprite5 = Sprite::create("Images/piece.png", Rect(128.0f, 0.0f, 64.0f, 64.0f));
_sprite5->setPosition(Vec2(356.0f, 160.0f));
_node->addChild(_sprite5, -3, 5);
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(NodeSort::reorderSprite, this), "reorder_sprite_key");
}
std::string NodeSort::title() const
{
return "node sort same index";
}
std::string NodeSort::subtitle() const
{
return "tag order in console should be 2,1,3,4,5";
}
void NodeSort::reorderSprite(float dt)
{
unschedule("reorder_sprite_key");
log("Before reorder--");
2021-12-28 16:06:23 +08:00
auto& children = _node->getChildren();
2021-12-28 16:06:23 +08:00
for (const auto& child : children)
{
log("tag %i z %i", (int)child->getTag(), (int)child->getLocalZOrder());
}
2021-12-28 16:06:23 +08:00
// z-4
_node->reorderChild(_node->getChildren().at(0), -6);
_node->sortAllChildren();
2021-12-28 16:06:23 +08:00
log("After reorder--");
2021-12-28 16:06:23 +08:00
for (const auto& child : children)
{
log("tag %i z %i", (int)child->getTag(), (int)child->getLocalZOrder());
}
}
/// SpriteBatchNodeReorderSameIndex
SpriteBatchNodeReorderSameIndex::SpriteBatchNodeReorderSameIndex()
{
_batchNode = SpriteBatchNode::create("Images/piece.png", 15);
addChild(_batchNode, 1, 0);
2021-12-28 16:06:23 +08:00
_sprite1 = Sprite::createWithTexture(_batchNode->getTexture(), Rect(128.0f, 0.0f, 64.0f, 64.0f));
_sprite1->setPosition(Vec2(100.0f, 160.0f));
_batchNode->addChild(_sprite1, 3, 1);
2021-12-28 16:06:23 +08:00
_sprite2 = Sprite::createWithTexture(_batchNode->getTexture(), Rect(128.0f, 0.0f, 64.0f, 64.0f));
_sprite2->setPosition(Vec2(164.0f, 160.0f));
_batchNode->addChild(_sprite2, 4, 2);
2021-12-28 16:06:23 +08:00
_sprite3 = Sprite::createWithTexture(_batchNode->getTexture(), Rect(128.0f, 0.0f, 64.0f, 64.0f));
_sprite3->setPosition(Vec2(228.0f, 160.0f));
_batchNode->addChild(_sprite3, 4, 3);
2021-12-28 16:06:23 +08:00
_sprite4 = Sprite::createWithTexture(_batchNode->getTexture(), Rect(128.0f, 0.0f, 64.0f, 64.0f));
_sprite4->setPosition(Vec2(292.0f, 160.0f));
_batchNode->addChild(_sprite4, 5, 4);
2021-12-28 16:06:23 +08:00
_sprite5 = Sprite::createWithTexture(_batchNode->getTexture(), Rect(128.0f, 0.0f, 64.0f, 64.0f));
_sprite5->setPosition(Vec2(356.0f, 160.0f));
_batchNode->addChild(_sprite5, 6, 5);
2022-07-15 19:17:01 +08:00
scheduleOnce(AX_CALLBACK_1(SpriteBatchNodeReorderSameIndex::reorderSprite, this), 2, "reorder_sprite_key");
}
std::string SpriteBatchNodeReorderSameIndex::title() const
{
return "SpriteBatchNodeReorder same index";
}
std::string SpriteBatchNodeReorderSameIndex::subtitle() const
{
return "tag order in console should be 2,3,4,5,1";
}
void SpriteBatchNodeReorderSameIndex::reorderSprite(float dt)
{
_batchNode->reorderChild(_sprite4, 4);
_batchNode->reorderChild(_sprite5, 4);
_batchNode->reorderChild(_sprite1, 4);
_batchNode->sortAllChildren();
2021-12-28 16:06:23 +08:00
for (const auto& sprite : _batchNode->getDescendants())
{
log("tag %i", sprite->getTag());
}
}
/// SpriteBatchNodeReorderOneChild
SpriteBatchNodeReorderOneChild::SpriteBatchNodeReorderOneChild()
{
auto s = Director::getInstance()->getWinSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/ghosts.plist");
2021-12-28 16:06:23 +08:00
SpriteBatchNode* aParent;
Sprite *l1, *l2a, *l2b, *l3a1, *l3a2, *l3b1, *l3b2;
//
// SpriteBatchNode: 3 levels of children
//
aParent = SpriteBatchNode::create("animations/ghosts.png");
_batchNode = aParent;
//[[aParent texture] generateMipmap];
addChild(aParent);
// parent
l1 = Sprite::createWithSpriteFrameName("father.gif");
2021-12-28 16:06:23 +08:00
l1->setPosition(Vec2(s.width / 2, s.height / 2));
aParent->addChild(l1);
auto l1Size = l1->getContentSize();
// child left
l2a = Sprite::createWithSpriteFrameName("sister1.gif");
2021-12-28 16:06:23 +08:00
l2a->setPosition(Vec2(-10 + l1Size.width / 2, 0 + l1Size.height / 2));
l1->addChild(l2a, 1);
auto l2aSize = l2a->getContentSize();
// child right
l2b = Sprite::createWithSpriteFrameName("sister2.gif");
2021-12-28 16:06:23 +08:00
l2b->setPosition(Vec2(+50 + l1Size.width / 2, 0 + l1Size.height / 2));
l1->addChild(l2b, 2);
auto l2bSize = l2a->getContentSize();
// child left bottom
l3a1 = Sprite::createWithSpriteFrameName("child1.gif");
l3a1->setScale(0.45f);
2021-12-28 16:06:23 +08:00
l3a1->setPosition(Vec2(0 + l2aSize.width / 2, -50 + l2aSize.height / 2));
l2a->addChild(l3a1, 1);
// child left top
l3a2 = Sprite::createWithSpriteFrameName("child1.gif");
l3a2->setScale(0.45f);
2021-12-28 16:06:23 +08:00
l3a2->setPosition(Vec2(0 + l2aSize.width / 2, +50 + l2aSize.height / 2));
l2a->addChild(l3a2, 2);
_reorderSprite = l2a;
// child right bottom
l3b1 = Sprite::createWithSpriteFrameName("child1.gif");
l3b1->setScale(0.45f);
l3b1->setFlippedY(true);
2021-12-28 16:06:23 +08:00
l3b1->setPosition(Vec2(0 + l2bSize.width / 2, -50 + l2bSize.height / 2));
l2b->addChild(l3b1);
// child right top
l3b2 = Sprite::createWithSpriteFrameName("child1.gif");
l3b2->setScale(0.45f);
l3b2->setFlippedY(true);
2021-12-28 16:06:23 +08:00
l3b2->setPosition(Vec2(0 + l2bSize.width / 2, +50 + l2bSize.height / 2));
l2b->addChild(l3b2);
2022-07-15 19:17:01 +08:00
scheduleOnce(AX_CALLBACK_1(SpriteBatchNodeReorderOneChild::reorderSprite, this), 2.0f, "reorder_sprite_key");
}
void SpriteBatchNodeReorderOneChild::reorderSprite(float dt)
{
_reorderSprite->getParent()->reorderChild(_reorderSprite, -1);
_batchNode->sortAllChildren();
2021-12-28 16:06:23 +08:00
// CCSprite* child;
// CCARRAY_FOREACH(batchNode.descendants,child) NSLog(@"tag %i",child.tag);
}
std::string SpriteBatchNodeReorderOneChild::title() const
{
return "SpriteBatchNode reorder 1 child";
}
//
// SpriteOffsetAnchorRotationalSkew
//
SpriteOffsetAnchorRotationalSkew::SpriteOffsetAnchorRotationalSkew()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite batch
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 1);
2021-12-28 16:06:23 +08:00
switch (i)
{
2021-12-28 16:06:23 +08:00
case 0:
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
2021-12-28 16:06:23 +08:00
Vector<SpriteFrame*> animFrames(14);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 14; i++)
{
char pngName[30];
2021-12-28 16:06:23 +08:00
snprintf(pngName, 30, "grossini_dance_%02d.png", (i + 1));
auto frame = cache->getSpriteFrameByName(pngName);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
2021-12-28 16:06:23 +08:00
auto skewX = RotateBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = RotateBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
2021-12-28 16:06:23 +08:00
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
2021-12-28 16:06:23 +08:00
addChild(sprite, 0);
}
}
SpriteOffsetAnchorRotationalSkew::~SpriteOffsetAnchorRotationalSkew()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteOffsetAnchorRotationalSkew::title() const
{
return "Testing Sprite";
}
std::string SpriteOffsetAnchorRotationalSkew::subtitle() const
{
return "offset + anchor + rotational skew";
}
//
// SpriteBatchNodeOffsetAnchorRotationalSkew
//
SpriteBatchNodeOffsetAnchorRotationalSkew::SpriteBatchNodeOffsetAnchorRotationalSkew()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
addChild(spritebatch);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite batch
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
addChild(point, 1);
2021-12-28 16:06:23 +08:00
switch (i)
{
2021-12-28 16:06:23 +08:00
case 0:
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
2021-12-28 16:06:23 +08:00
Vector<SpriteFrame*> animFrames(14);
2021-12-28 16:06:23 +08:00
for (int j = 0; j < 14; j++)
{
char pngName[30];
2021-12-28 16:06:23 +08:00
snprintf(pngName, 30, "grossini_dance_%02d.png", (j + 1));
auto frame = cache->getSpriteFrameByName(pngName);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
2021-12-28 16:06:23 +08:00
auto skewX = RotateBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = RotateBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
2021-12-28 16:06:23 +08:00
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
2021-12-28 16:06:23 +08:00
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
spritebatch->addChild(sprite, 0);
}
}
SpriteBatchNodeOffsetAnchorRotationalSkew::~SpriteBatchNodeOffsetAnchorRotationalSkew()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteBatchNodeOffsetAnchorRotationalSkew::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeOffsetAnchorRotationalSkew::subtitle() const
{
return "offset + anchor + rotational skew";
}
//
// SpriteOffsetAnchorRotationalSkewScale
//
SpriteOffsetAnchorRotationalSkewScale::SpriteOffsetAnchorRotationalSkewScale()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite batch
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 1);
2021-12-28 16:06:23 +08:00
switch (i)
{
2021-12-28 16:06:23 +08:00
case 0:
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
2021-12-28 16:06:23 +08:00
Vector<SpriteFrame*> animFrames(14);
2021-12-28 16:06:23 +08:00
for (int j = 0; j < 14; j++)
{
char pngName[30];
2021-12-28 16:06:23 +08:00
snprintf(pngName, 30, "grossini_dance_%02d.png", (j + 1));
auto frame = cache->getSpriteFrameByName(pngName);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
2021-12-28 16:06:23 +08:00
// Skew
2021-12-28 16:06:23 +08:00
auto skewX = RotateBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = RotateBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
2021-12-28 16:06:23 +08:00
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
2021-12-28 16:06:23 +08:00
// Scale
2021-12-28 16:06:23 +08:00
auto scale = ScaleBy::create(2, 2);
auto scale_back = scale->reverse();
2021-12-28 16:06:23 +08:00
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
sprite->runAction(RepeatForever::create(seq_scale));
2021-12-28 16:06:23 +08:00
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
addChild(sprite, 0);
}
}
SpriteOffsetAnchorRotationalSkewScale::~SpriteOffsetAnchorRotationalSkewScale()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteOffsetAnchorRotationalSkewScale::title() const
{
return "Testing Sprite";
}
std::string SpriteOffsetAnchorRotationalSkewScale::subtitle() const
{
return "anchor + rot skew + scale";
}
// SpriteBatchNodeOffsetAnchorRotationalSkewScale
SpriteBatchNodeOffsetAnchorRotationalSkewScale::SpriteBatchNodeOffsetAnchorRotationalSkewScale()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
auto spritebatch = SpriteBatchNode::create("animations/grossini.png");
addChild(spritebatch);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
//
// Animation using Sprite batch
//
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
addChild(point, 1);
2021-12-28 16:06:23 +08:00
switch (i)
{
2021-12-28 16:06:23 +08:00
case 0:
sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
break;
case 1:
sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
break;
case 2:
sprite->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
break;
}
2021-12-28 16:06:23 +08:00
point->setPosition(sprite->getPosition());
2021-12-28 16:06:23 +08:00
Vector<SpriteFrame*> animFrames(14);
2021-12-28 16:06:23 +08:00
for (int j = 0; j < 14; j++)
{
char pngName[30];
2021-12-28 16:06:23 +08:00
snprintf(pngName, 30, "grossini_dance_%02d.png", (j + 1));
auto frame = cache->getSpriteFrameByName(pngName);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
sprite->runAction(RepeatForever::create(Animate::create(animation)));
2021-12-28 16:06:23 +08:00
// Skew
2021-12-28 16:06:23 +08:00
auto skewX = RotateBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = RotateBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
2021-12-28 16:06:23 +08:00
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
2021-12-28 16:06:23 +08:00
// Scale
2021-12-28 16:06:23 +08:00
auto scale = ScaleBy::create(2, 2);
auto scale_back = scale->reverse();
2021-12-28 16:06:23 +08:00
auto seq_scale = Sequence::create(scale, scale_back, nullptr);
sprite->runAction(RepeatForever::create(seq_scale));
2021-12-28 16:06:23 +08:00
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
spritebatch->addChild(sprite, 0);
}
}
SpriteBatchNodeOffsetAnchorRotationalSkewScale::~SpriteBatchNodeOffsetAnchorRotationalSkewScale()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteBatchNodeOffsetAnchorRotationalSkewScale::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeOffsetAnchorRotationalSkewScale::subtitle() const
{
return "anchor + rot skew + scale";
}
//
// SpriteRotationalSkewNegativeScaleChildren
//
SpriteRotationalSkewNegativeScaleChildren::SpriteRotationalSkewNegativeScaleChildren()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
auto parent = Node::create();
addChild(parent);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 2; i++)
{
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
2021-12-28 16:06:23 +08:00
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
addChild(point, 1);
2021-12-28 16:06:23 +08:00
// Skew
2021-12-28 16:06:23 +08:00
auto skewX = RotateBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = RotateBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
2021-12-28 16:06:23 +08:00
if (1 == 1)
{
sprite->setScale(-1.0f);
}
2021-12-28 16:06:23 +08:00
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
2021-12-28 16:06:23 +08:00
auto child1 = Sprite::create("Images/grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
child1->setPosition(Vec2(sprite->getContentSize().width / 2.0f, sprite->getContentSize().height / 2.0f));
sprite->addChild(child1);
2021-12-28 16:06:23 +08:00
child1->setScale(0.8f);
2021-12-28 16:06:23 +08:00
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
parent->addChild(sprite, 0);
}
}
SpriteRotationalSkewNegativeScaleChildren::~SpriteRotationalSkewNegativeScaleChildren()
{
auto cache = SpriteFrameCache::getInstance();
cache->removeSpriteFramesFromFile("animations/grossini.plist");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
}
std::string SpriteRotationalSkewNegativeScaleChildren::title() const
{
return "Testing Sprite";
}
std::string SpriteRotationalSkewNegativeScaleChildren::subtitle() const
{
return "rot skew + negative scale with children";
}
//
// SpriteBatchNodeRotationalSkewNegativeScaleChildren
//
SpriteBatchNodeRotationalSkewNegativeScaleChildren::SpriteBatchNodeRotationalSkewNegativeScaleChildren()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
2021-12-28 16:06:23 +08:00
auto parent = SpriteBatchNode::create("animations/grossini.png");
addChild(parent);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 2; i++)
{
auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
addChild(point, 1);
// Skew
2021-12-28 16:06:23 +08:00
auto skewX = RotateBy::create(2, 45, 0);
auto skewX_back = skewX->reverse();
2021-12-28 16:06:23 +08:00
auto skewY = RotateBy::create(2, 0, 45);
auto skewY_back = skewY->reverse();
if (1 == 1)
{
sprite->setScale(-1.0f);
}
auto seq_skew = Sequence::create(skewX, skewX_back, skewY, skewY_back, nullptr);
sprite->runAction(RepeatForever::create(seq_skew));
auto child1 = Sprite::create("Images/grossini_dance_01.png");
2021-12-28 16:06:23 +08:00
child1->setPosition(Vec2(sprite->getContentSize().width / 2.0f, sprite->getContentSize().height / 2.0f));
sprite->addChild(child1);
child1->setScale(0.8f);
Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) - QuadCommand is just a subclass of TriangleCommand (simpler) - but statically it allocates indices internally (like any TriangleCommand) (more memory, but not that much) - adds more tests for SpritePolygon - adds test for batching Tri + Quad command - and fixes some other bugs Squashed commit of the following: commit cce893a9114da5dda91a895e4e661894f365e2c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 8 06:56:57 2016 -0800 QuadCommand: indices are static thanks @Darinex commit e5fd1c14e93d2f07b8266bfec03cf7206d348f59 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:18:42 2016 -0800 little improvements in xcode proj management commit 6cd29764e01ad300f4e89e62aa6b399f73e94f01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 19:05:52 2016 -0800 Renderer improvments: TriangleCommand and QuadCommand merged - more options for batching (faster) - less flushing in between commands (faster) - less renderer code (easier to maintain) - less VBO/VAO (less memory) - uses temporary buffer for faster rendering (more memory) and fixes some other bugs Squashed commit of the following: commit af7a209435c5f2430c31ab3ebcc7f45051eacb1a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:55:27 2016 -0800 adds test for batching quads and tris commit 25816e3eaeffd4b0cfe5fa15e97ff84e9013b8be Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 18:40:15 2016 -0800 cleanup renderer commit 7f9785056681756c865d603516c7e14c46040e82 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:34:48 2016 -0800 clean up docs commit 92a8b679dd404e4ca2839d85e2bd925195b12996 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sun Feb 7 15:18:52 2016 -0800 QuadCommand converted to Triangles command commit 7e21ec12d3781f6964b4d639cfa4bdc79eb8ae80 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 16:17:29 2016 -0800 adds missing files... new test as well commit d1bd4391785515bdc2e1bebbeb3f321f983b51f2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 14:35:41 2016 -0800 more tests for poly sprites commit 5775a25b1046671bd0f5af4c5ab52b308b34bb39 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 5 00:30:13 2016 -0800 malloc instead of std::vector commit 14a5d45cc978c55a182c03f181ca2bc603776561 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 21:40:46 2016 -0800 little optimization commit 5667cb2b62416f8a439a54c3973d5841fbe1b68b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 19:13:13 2016 -0800 quad works as expected commit 462aef05baa6586591882faa366839bead4be068 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 15:22:59 2016 -0800 works commit c789e6c42811278563c7682b5620296ae8d84aeb Merge: d6c3729 de62924 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 14:08:49 2016 -0800 Merge branch 'v3' into uniform_matrix_auto commit d6c37297954af752ebf42ec5f71e5e2fe28c9cc2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 13:54:07 2016 -0800 works ok... commit 45c288631989ea735cc31ec5aa683d9d41aacab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 4 12:58:34 2016 -0800 quad works! commit 7137cff51df09adee7129738cea2b69da090756e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 3 16:19:34 2016 -0800 more optimizations... WIP... doesn't work yet commit a8324c1a9acb6b82102e05eee6e5e5f341306c7b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 21:59:42 2016 -0800 compiles in release mode more tests... better threshold commit 884ffc756e7520fcbb9252260181538ec81b8368 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 2 17:21:32 2016 -0800 initial uniform_auto_matrix commit Changes the CC_matrix uniform in runtime depending on whether the command can be batched or not. Lot of things missing, though... like performance tests.
2016-02-09 03:25:37 +08:00
parent->addChild(sprite, 0);
}
}
2021-12-28 16:06:23 +08:00
SpriteBatchNodeRotationalSkewNegativeScaleChildren::~SpriteBatchNodeRotationalSkewNegativeScaleChildren() {}
std::string SpriteBatchNodeRotationalSkewNegativeScaleChildren::title() const
{
return "Testing SpriteBatchNode";
}
std::string SpriteBatchNodeRotationalSkewNegativeScaleChildren::subtitle() const
{
return "rot skew + negative scale with children";
}
//------------------------------------------------------------------
//
// SpriteCullTest1
//
//------------------------------------------------------------------
SpriteCullTest1::SpriteCullTest1()
{
2021-12-28 16:06:23 +08:00
Size s = Director::getInstance()->getWinSize();
auto grossini = Sprite::create("Images/grossini.png");
2021-12-28 16:06:23 +08:00
grossini->setPosition(s.width / 2, s.height / 2);
2021-12-28 16:06:23 +08:00
auto right = MoveBy::create(3, Vec2(s.width * 2, 0.0f));
auto back1 = right->reverse();
2021-12-28 16:06:23 +08:00
auto left = MoveBy::create(3, Vec2(-s.width * 2, 0.0f));
auto back2 = left->reverse();
2021-12-28 16:06:23 +08:00
auto up = MoveBy::create(3, Vec2(0.0f, s.height * 2));
auto back3 = up->reverse();
2021-12-28 16:06:23 +08:00
auto down = MoveBy::create(3, Vec2(0.0f, -s.height * 2));
auto back4 = down->reverse();
auto seq = Sequence::create(right, back1, left, back2, up, back3, down, back4, nullptr);
grossini->runAction(seq);
this->addChild(grossini);
}
std::string SpriteCullTest1::title() const
{
return "Testing Culling: No Scale, No Rotation";
}
std::string SpriteCullTest1::subtitle() const
{
return "Look at the GL calls";
}
//------------------------------------------------------------------
//
// SpriteCullTest2
//
//------------------------------------------------------------------
SpriteCullTest2::SpriteCullTest2()
{
2021-12-28 16:06:23 +08:00
Size s = Director::getInstance()->getWinSize();
auto grossini = Sprite::create("Images/grossini.png");
2021-12-28 16:06:23 +08:00
grossini->setPosition(s.width / 2, s.height / 2);
2021-12-28 16:06:23 +08:00
auto right = MoveBy::create(3, Vec2(s.width * 2, 0.0f));
auto back1 = right->reverse();
2021-12-28 16:06:23 +08:00
auto left = MoveBy::create(3, Vec2(-s.width * 2, 0.0f));
auto back2 = left->reverse();
2021-12-28 16:06:23 +08:00
auto up = MoveBy::create(3, Vec2(0.0f, s.height * 2));
auto back3 = up->reverse();
2021-12-28 16:06:23 +08:00
auto down = MoveBy::create(3, Vec2(0.0f, -s.height * 2));
auto back4 = down->reverse();
grossini->setScale(0.1f);
2021-12-28 16:06:23 +08:00
auto seq = Sequence::create(right, back1, left, back2, up, back3, down, back4, nullptr);
grossini->runAction(seq);
this->addChild(grossini);
}
std::string SpriteCullTest2::title() const
{
return "Testing Culling: Scale, No Rotation";
}
std::string SpriteCullTest2::subtitle() const
{
return "Look at the GL calls";
}
2014-07-02 03:36:53 +08:00
//------------------------------------------------------------------
//
// Sprite 3D rotation test
//
//------------------------------------------------------------------
Sprite3DRotationTest::Sprite3DRotationTest()
{
Size s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
2014-07-02 03:36:53 +08:00
auto s1 = Sprite::create("Images/grossini.png");
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width / 4, s.height / 4 * 3);
s1->setAnchorPoint(Vec2(0.0f, 0.0f));
s1->runAction(RepeatForever::create(RotateBy::create(6.0f, 360.0f)));
2014-07-02 03:36:53 +08:00
addChild(s1);
2021-12-28 16:06:23 +08:00
2014-07-02 03:36:53 +08:00
auto s2 = Sprite::create("Images/grossini.png");
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width / 4 * 3, s.height / 4 * 3);
s2->runAction(RepeatForever::create(RotateBy::create(6.0f, 360.0f)));
2014-07-02 03:36:53 +08:00
addChild(s2);
2021-12-28 16:06:23 +08:00
2014-07-02 03:36:53 +08:00
sprite1 = Sprite::create("Images/grossini.png");
2021-12-28 16:06:23 +08:00
sprite1->setPosition(s.width / 4, s.height / 4);
sprite1->setAnchorPoint(Vec2(0.0f, 0.0f));
2014-07-02 03:36:53 +08:00
addChild(sprite1);
2021-12-28 16:06:23 +08:00
2014-07-02 03:36:53 +08:00
sprite2 = Sprite::create("Images/grossini.png");
2021-12-28 16:06:23 +08:00
sprite2->setPosition(s.width / 4 * 3, s.height / 4);
2014-07-02 03:36:53 +08:00
addChild(sprite2);
2021-12-28 16:06:23 +08:00
schedule(
[&](float dt) {
rotation.y += 1;
sprite1->setRotation3D(rotation);
sprite2->setRotation3D(rotation);
},
"update_key");
2014-07-02 03:36:53 +08:00
}
//------------------------------------------------------------------
//
// Sprite::getSpriteFrame() test
//
//------------------------------------------------------------------
SpriteGetSpriteFrameTest::SpriteGetSpriteFrameTest()
{
Size s = Director::getInstance()->getVisibleSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s1 = Sprite::createWithSpriteFrameName("grossini.png");
addChild(s1);
s1->getTexture()->setAliasTexParameters();
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width / 2 - s.width / 3, s.height / 2);
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s1->setContentSize(s1->getContentSize() * 2);
s1->setSpriteFrame(s1->getSpriteFrame());
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s2 = Sprite::createWithSpriteFrameName("grossini.png");
addChild(s2);
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width * 2 / 4, s.height / 2);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s3 = Sprite::createWithSpriteFrameName("grossini.png");
addChild(s3);
2022-07-15 19:17:01 +08:00
s3->setTextureRect(AX_RECT_PIXELS_TO_POINTS(Rect(128, 0, 64, 128)));
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width / 2 + s.width / 3, s.height / 2);
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
s3->setSpriteFrame(s3->getSpriteFrame());
}
//------------------------------------------------------------------
//
// Slice9 Test #1
//
//------------------------------------------------------------------
SpriteSlice9Test1::SpriteSlice9Test1()
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
Size s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
for (int i = 2; i > 0; --i)
{
auto s1 = Sprite::create("Images/grossinis_sister1.png");
addChild(s1);
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width * 1 / 4, s.height * i / 3);
s1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
s1->setContentSize(Size(s1->getContentSize().width, 200.0f));
auto action1 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s1->runAction(action1);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s2 = Sprite::create("Images/grossinis_sister1.png");
addChild(s2);
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width * 2 / 4, s.height * i / 3);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
s2->setContentSize(Size(s2->getContentSize().width, 200.0f));
auto action2 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s2->runAction(action2);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s3 = Sprite::create("Images/grossinis_sister1.png");
addChild(s3);
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width * 3 / 4, s.height * i / 3);
s3->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
s3->setContentSize(Size(s3->getContentSize().width, 200.0f));
auto action3 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s3->runAction(action3);
2021-12-28 16:06:23 +08:00
if (i == 2)
{
s3->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
s2->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
s1->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
}
// "anchor points"
auto point = Sprite::create("Images/r1.png");
point->setScale(0.25f);
2021-12-28 16:06:23 +08:00
point->setPosition(s1->getPosition());
addChild(point, 10);
auto point2 = Sprite::create("Images/r1.png");
point2->setScale(0.25f);
point2->setPosition(s2->getPosition());
addChild(point2, 10);
auto point3 = Sprite::create("Images/r1.png");
point3->setScale(0.25f);
point3->setPosition(s3->getPosition());
addChild(point3, 10);
}
}
//------------------------------------------------------------------
//
// Slice9 Test #2
//
//------------------------------------------------------------------
SpriteSlice9Test2::SpriteSlice9Test2()
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
Size s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
for (int i = 2; i > 0; i--)
{
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s1 = Sprite::createWithSpriteFrameName("grossini.png");
addChild(s1);
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width * 1 / 4, s.height * i / 3);
s1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
s1->setContentSize(Size(80.0f, s1->getContentSize().height));
auto action1 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s1->runAction(action1);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s2 = Sprite::createWithSpriteFrameName("grossini.png");
addChild(s2);
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width * 2 / 4, s.height * i / 3);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
s2->setContentSize(Size(80.0f, s2->getContentSize().height));
auto action2 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s2->runAction(action2);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s3 = Sprite::createWithSpriteFrameName("grossini.png");
addChild(s3);
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width * 3 / 4, s.height * i / 3);
s3->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
s3->setContentSize(Size(80.0f, s3->getContentSize().height));
auto action3 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s3->runAction(action3);
2021-12-28 16:06:23 +08:00
if (i == 2)
{
s3->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
s2->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
s1->setCenterRectNormalized(Rect(0.4f, 0.4f, 0.2f, 0.2f));
}
// "anchor points"
auto point = Sprite::create("Images/r1.png");
point->setScale(0.25f);
2021-12-28 16:06:23 +08:00
point->setPosition(s1->getPosition());
addChild(point, 10);
auto point2 = Sprite::create("Images/r1.png");
point2->setScale(0.25f);
point2->setPosition(s2->getPosition());
addChild(point2, 10);
auto point3 = Sprite::create("Images/r1.png");
point3->setScale(0.25f);
point3->setPosition(s3->getPosition());
addChild(point3, 10);
}
}
//------------------------------------------------------------------
//
// Slice9 Test #3
//
//------------------------------------------------------------------
SpriteSlice9Test3::SpriteSlice9Test3()
{
Size s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
for (int i = 2; i > 0; --i)
{
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s1 = Sprite::create("ccb/scale-9-demo.png");
addChild(s1);
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width * 1 / 4, s.height * i / 3);
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
s1->setContentSize(s1->getContentSize());
auto action1 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s1->runAction(action1);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s2 = Sprite::create("ccb/scale-9-demo.png");
addChild(s2);
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width * 2 / 4, s.height * i / 3);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
s2->setContentSize(s2->getContentSize() * 2);
auto action2 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s2->runAction(action2);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s3 = Sprite::create("ccb/scale-9-demo.png");
addChild(s3);
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width * 3 / 4, s.height * i / 3);
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
s3->setContentSize(s3->getContentSize() * 3);
auto action3 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s3->runAction(action3);
// enable slice 9, only in the first row
2021-12-28 16:06:23 +08:00
if (i == 2)
{
s1->setCenterRectNormalized(Rect(0.4, 0.4, 0.2, 0.2));
s2->setCenterRectNormalized(Rect(0.4, 0.4, 0.2, 0.2));
s3->setCenterRectNormalized(Rect(0.4, 0.4, 0.2, 0.2));
}
// "anchor points"
auto point = Sprite::create("Images/r1.png");
point->setScale(0.25f);
2021-12-28 16:06:23 +08:00
point->setPosition(s1->getPosition());
addChild(point, 10);
auto point2 = Sprite::create("Images/r1.png");
point2->setScale(0.25f);
point2->setPosition(s2->getPosition());
addChild(point2, 10);
auto point3 = Sprite::create("Images/r1.png");
point3->setScale(0.25f);
point3->setPosition(s3->getPosition());
addChild(point3, 10);
}
}
//------------------------------------------------------------------
//
// Slice9 Test #4
//
//------------------------------------------------------------------
SpriteSlice9Test4::SpriteSlice9Test4()
{
Size s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
for (int i = 2; i > 0; --i)
{
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s1 = Sprite::create("ccs-res/cocosui/button.png");
addChild(s1);
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width * 1 / 4, s.height * i / 3);
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
s1->setContentSize(s1->getContentSize() * 2);
auto action1 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s1->runAction(action1);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s2 = Sprite::create("ccs-res/cocosui/button.png");
addChild(s2);
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width * 2 / 4, s.height * i / 3);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
s2->setContentSize(s2->getContentSize() * 3);
auto action2 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s2->runAction(action2);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s3 = Sprite::create("ccs-res/cocosui/button.png");
addChild(s3);
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width * 3 / 4, s.height * i / 3);
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
s3->setContentSize(s3->getContentSize() * 4);
auto action3 = RepeatForever::create(RotateBy::create(5.0f, 360.0f));
s3->runAction(action3);
// enable slice 9, only in the first row
2021-12-28 16:06:23 +08:00
if (i == 2)
{
2022-07-15 19:17:01 +08:00
s1->setCenterRect(AX_RECT_PIXELS_TO_POINTS(Rect(6, 14, 2, 4)));
s2->setCenterRect(AX_RECT_PIXELS_TO_POINTS(Rect(6, 14, 2, 4)));
s3->setCenterRect(AX_RECT_PIXELS_TO_POINTS(Rect(6, 14, 2, 4)));
}
// "anchor points"
auto point = Sprite::create("Images/r1.png");
point->setScale(0.1f);
2021-12-28 16:06:23 +08:00
point->setPosition(s1->getPosition());
addChild(point, 10);
auto point2 = Sprite::create("Images/r1.png");
point2->setScale(0.1f);
point2->setPosition(s2->getPosition());
addChild(point2, 10);
auto point3 = Sprite::create("Images/r1.png");
point3->setScale(0.1f);
point3->setPosition(s3->getPosition());
addChild(point3, 10);
}
}
//------------------------------------------------------------------
//
// Slice9 Test #5
//
//------------------------------------------------------------------
SpriteSlice9Test5::SpriteSlice9Test5()
{
Size s = Director::getInstance()->getVisibleSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s1 = Sprite::create("Images/grossinis_heads.png");
addChild(s1);
s1->getTexture()->setAliasTexParameters();
2022-07-15 19:17:01 +08:00
s1->setTextureRect(AX_RECT_PIXELS_TO_POINTS(Rect(0, 0, 64, 128)));
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width / 2 - s.width / 3, s.height / 2);
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s1->setContentSize(Size(s.width / 3, s.height));
s1->setCenterRectNormalized(Rect(0, 0, 1, 1));
_sprites[0] = s1;
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s2 = Sprite::create("Images/grossinis_heads.png");
addChild(s2);
2022-07-15 19:17:01 +08:00
s2->setTextureRect(AX_RECT_PIXELS_TO_POINTS(Rect(64, 0, 64, 128)));
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width * 2 / 4, s.height / 2);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s2->setContentSize(Size(s.width / 3, s.height));
s2->setCenterRectNormalized(Rect(0, 0, 1, 1));
_sprites[1] = s2;
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s3 = Sprite::create("Images/grossinis_heads.png");
addChild(s3);
2022-07-15 19:17:01 +08:00
s3->setTextureRect(AX_RECT_PIXELS_TO_POINTS(Rect(128, 0, 64, 128)));
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width / 2 + s.width / 3, s.height / 2);
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s3->setContentSize(Size(s.width / 3, s.height));
s3->setCenterRectNormalized(Rect(0, 0, 1, 1));
_sprites[2] = s3;
scheduleUpdate();
_elapsed = 0;
}
void SpriteSlice9Test5::update(float dt)
{
_elapsed += dt;
float angle = _elapsed;
// cap the value between 0 and 0.8
2021-12-28 16:06:23 +08:00
float x = ((cos(angle) + sin(angle * 3)) + 2) / 5.0f;
float y1 = (sin(angle) + 1) / 2.5;
2021-12-28 16:06:23 +08:00
float y2 = (sin(angle + M_PI_2) + 1) / 2.5;
float y = y1;
for (int i = 0; i < 3; ++i)
{
if (i == 1)
{
x = 0.8 - x;
y = y2;
2021-12-28 16:06:23 +08:00
}
else if (i == 2)
{
y = 0.8 - y;
}
2021-12-28 16:06:23 +08:00
Rect rect(x, y, 0.2, 0.2);
_sprites[i]->setCenterRectNormalized(rect);
}
}
//------------------------------------------------------------------
//
// Slice9 Test #6
//
//------------------------------------------------------------------
SpriteSlice9Test6::SpriteSlice9Test6()
{
Size s = Director::getInstance()->getVisibleSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s1 = Sprite::create("Images/grossinis_heads.png");
addChild(s1);
s1->getTexture()->setAliasTexParameters();
2022-07-15 19:17:01 +08:00
s1->setTextureRect(AX_RECT_PIXELS_TO_POINTS(Rect(0, 0, 64, 128)));
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width / 2 - s.width / 3, s.height / 2);
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s1->setContentSize(Size(s.width / 3, s.height));
s1->setCenterRectNormalized(Rect(0, 0, 1, 1));
_sprites[0] = s1;
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s2 = Sprite::create("Images/grossinis_heads.png");
addChild(s2);
2022-07-15 19:17:01 +08:00
s2->setTextureRect(AX_RECT_PIXELS_TO_POINTS(Rect(64, 0, 64, 128)));
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width * 2 / 4, s.height / 2);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s2->setContentSize(Size(s.width / 3, s.height));
s2->setCenterRectNormalized(Rect(0, 0, 1, 1));
_sprites[1] = s2;
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s3 = Sprite::create("Images/grossinis_heads.png");
addChild(s3);
2022-07-15 19:17:01 +08:00
s3->setTextureRect(AX_RECT_PIXELS_TO_POINTS(Rect(128, 0, 64, 128)));
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width / 2 + s.width / 3, s.height / 2);
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s3->setContentSize(Size(s.width / 3, s.height));
s3->setCenterRectNormalized(Rect(0, 0, 1, 1));
_sprites[2] = s3;
2014-07-02 03:36:53 +08:00
scheduleUpdate();
2014-07-02 03:36:53 +08:00
_elapsed = 0;
}
void SpriteSlice9Test6::update(float dt)
{
_elapsed += dt;
float angle = _elapsed;
// cap the value between 0 and 1
2021-12-28 16:06:23 +08:00
float x = ((cos(angle * 2) - sin(angle / 2)) + 2) / 4;
float y1 = (sin(angle) + 1) / 2;
2021-12-28 16:06:23 +08:00
float y2 = (sin(angle + M_PI_2) + 1) / 2;
float y = y1;
for (int i = 0; i < 3; ++i)
{
if (i == 1)
{
x = 1 - x;
y = y2;
2021-12-28 16:06:23 +08:00
}
else if (i == 2)
{
y = 1 - y;
}
2021-12-28 16:06:23 +08:00
Rect rect((1 - x) / 2, (1 - y) / 2, x, y);
_sprites[i]->setCenterRectNormalized(rect);
}
}
//------------------------------------------------------------------
//
// Slice9 Test #7
//
//------------------------------------------------------------------
SpriteSlice9Test7::SpriteSlice9Test7()
{
Size s = Director::getInstance()->getVisibleSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s1 = Sprite::create("Images/grossinis_heads.png");
addChild(s1);
s1->getTexture()->setAliasTexParameters();
2022-07-15 19:17:01 +08:00
s1->setTextureRect(AX_RECT_PIXELS_TO_POINTS(Rect(0, 0, 64, 128)));
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width / 2 - s.width / 3, s.height / 2);
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s1->setContentSize(Size(s.width / 3, s.height));
s1->setCenterRectNormalized(Rect(0, 0, 0.5, 0.5));
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s2 = Sprite::create("Images/grossinis_heads.png");
addChild(s2);
2022-07-15 19:17:01 +08:00
s2->setTextureRect(AX_RECT_PIXELS_TO_POINTS(Rect(64, 0, 64, 128)));
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width * 2 / 4, s.height / 2);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s2->setContentSize(Size(s.width / 3, s.height));
s2->setCenterRectNormalized(Rect(0.25, 0.25, 0.5, 0.5));
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s3 = Sprite::create("Images/grossinis_heads.png");
addChild(s3);
2022-07-15 19:17:01 +08:00
s3->setTextureRect(AX_RECT_PIXELS_TO_POINTS(Rect(128, 0, 64, 128)));
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width / 2 + s.width / 3, s.height / 2);
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s3->setContentSize(Size(s.width / 3, s.height));
s3->setCenterRectNormalized(Rect(0.5, 0.5, 0.5, 0.5));
}
//------------------------------------------------------------------
//
// Slice9 Test #8
//
//------------------------------------------------------------------
SpriteSlice9Test8::SpriteSlice9Test8()
{
Size s = Director::getInstance()->getVisibleSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
//
// flip BEFORE contentSize
//
auto s1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
addChild(s1);
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width / 2 - s.width / 3, s.height * 2 / 3);
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s1->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 1 / 3.f, 1 / 3.f));
s1->setFlippedX(true);
2021-12-28 16:06:23 +08:00
s1->setContentSize(s1->getContentSize() * 2);
auto s2 = Sprite::createWithSpriteFrameName("grossini.png");
addChild(s2);
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width * 2 / 4, s.height * 2 / 3);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s2->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 1 / 3.f, 1 / 3.f));
s2->setFlippedX(true);
s2->setFlippedY(true);
2021-12-28 16:06:23 +08:00
s2->setContentSize(s2->getContentSize() * 2);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s3 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
addChild(s3);
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width / 2 + s.width / 3, s.height * 2 / 3);
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s3->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 1 / 3.f, 1 / 3.f));
s3->setFlippedY(true);
2021-12-28 16:06:23 +08:00
s3->setContentSize(s3->getContentSize() * 2);
//
// flip AFTER contentSize
//
auto s4 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
addChild(s4);
2021-12-28 16:06:23 +08:00
s4->setPosition(s.width / 2 - s.width / 3, s.height * 1 / 3);
s4->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s4->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 1 / 3.f, 1 / 3.f));
s4->setFlippedX(true);
2021-12-28 16:06:23 +08:00
s4->setContentSize(s4->getContentSize() * 2);
auto s5 = Sprite::createWithSpriteFrameName("grossini.png");
addChild(s5);
2021-12-28 16:06:23 +08:00
s5->setPosition(s.width * 2 / 4, s.height * 1 / 3);
s5->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s5->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 1 / 3.f, 1 / 3.f));
s5->setFlippedX(true);
s5->setFlippedY(true);
2021-12-28 16:06:23 +08:00
s5->setContentSize(s5->getContentSize() * 2);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s6 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
addChild(s6);
2021-12-28 16:06:23 +08:00
s6->setPosition(s.width / 2 + s.width / 3, s.height * 1 / 3);
s6->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s6->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 1 / 3.f, 1 / 3.f));
s6->setFlippedY(true);
2021-12-28 16:06:23 +08:00
s6->setContentSize(s6->getContentSize() * 2);
}
//------------------------------------------------------------------
//
// Slice9 Test #9
//
//------------------------------------------------------------------
SpriteSlice9Test9::SpriteSlice9Test9()
{
Size s = Director::getInstance()->getVisibleSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini_family.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("animations/grossini.plist");
// flipped BEFORE content size
auto s1 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
addChild(s1);
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width / 2 - s.width / 3, s.height * 2 / 3);
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s1->setCenterRectNormalized(Rect(2 / 3.f, 2 / 3.f, 1 / 3.f, 1 / 3.f));
s1->setFlippedX(true);
2021-12-28 16:06:23 +08:00
s1->setContentSize(s1->getContentSize() * 2);
auto s2 = Sprite::createWithSpriteFrameName("grossini.png");
addChild(s2);
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width * 2 / 4, s.height * 2 / 3);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s2->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 2 / 3.f, 2 / 3.f));
s2->setFlippedX(true);
s2->setFlippedY(true);
2021-12-28 16:06:23 +08:00
s2->setContentSize(s2->getContentSize() * 2);
auto s3 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
addChild(s3);
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width / 2 + s.width / 3, s.height * 2 / 3);
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
s3->setCenterRectNormalized(Rect(0.1f, 0.1f, 0.8f, 0.8f));
s3->setFlippedY(true);
2021-12-28 16:06:23 +08:00
s3->setContentSize(s3->getContentSize() * 2);
// flipped AFTER content size
auto s4 = Sprite::createWithSpriteFrameName("grossinis_sister1.png");
addChild(s4);
2021-12-28 16:06:23 +08:00
s4->setPosition(s.width / 2 - s.width / 3, s.height * 1 / 3);
s4->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s4->setCenterRectNormalized(Rect(2 / 3.f, 2 / 3.f, 1 / 3.f, 1 / 3.f));
s4->setContentSize(s4->getContentSize() * 2);
s4->setFlippedX(true);
auto s5 = Sprite::createWithSpriteFrameName("grossini.png");
addChild(s5);
2021-12-28 16:06:23 +08:00
s5->setPosition(s.width * 2 / 4, s.height * 1 / 3);
s5->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s5->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 2 / 3.f, 2 / 3.f));
s5->setContentSize(s5->getContentSize() * 2);
s5->setFlippedX(true);
s5->setFlippedY(true);
auto s6 = Sprite::createWithSpriteFrameName("grossinis_sister2.png");
addChild(s6);
2021-12-28 16:06:23 +08:00
s6->setPosition(s.width / 2 + s.width / 3, s.height * 1 / 3);
s6->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
s6->setCenterRectNormalized(Rect(0.1f, 0.1f, 0.8f, 0.8f));
2021-12-28 16:06:23 +08:00
s6->setContentSize(s6->getContentSize() * 2);
s6->setFlippedY(true);
}
//------------------------------------------------------------------
//
// Slice9 Test #10
//
//------------------------------------------------------------------
SpriteSlice9Test10::SpriteSlice9Test10()
{
Size s = Director::getInstance()->getVisibleSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/blocks9ss.plist");
auto s1 = Sprite::createWithSpriteFrameName("blocks9ss/blocks9r.png");
addChild(s1);
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width / 2 - s.width / 3, s.height / 2);
s1->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s1->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 1 / 3.f, 1 / 3.f));
s1->setContentSize(s1->getContentSize() * 1.5);
s1->setFlippedX(true);
auto s2 = Sprite::createWithSpriteFrameName("blocks9ss/blocks9r.png");
addChild(s2);
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width * 2 / 4, s.height / 2);
s2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s2->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 1 / 3.f, 1 / 3.f));
s2->setContentSize(s2->getContentSize() * 1.5);
2021-12-28 16:06:23 +08:00
// Create reference sprite that's rotating based on there anchor point
auto s3 = Sprite::createWithSpriteFrameName("blocks9ss/blocks9r.png");
addChild(s3);
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width / 2 + s.width / 3, s.height / 2);
s3->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
2021-12-28 16:06:23 +08:00
s3->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 1 / 3.f, 1 / 3.f));
s3->setContentSize(s3->getContentSize() * 1.5);
s3->setFlippedY(true);
}
//------------------------------------------------------------------
//
// Issue 17119
//
//------------------------------------------------------------------
2021-12-28 16:06:23 +08:00
Issue17119::Issue17119() : _accum(0)
{
Size s = Director::getInstance()->getVisibleSize();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/issue_17119.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/blocks9ss.plist");
auto s1 = Sprite::createWithSpriteFrameName("issue_17119/firstPic.png");
addChild(s1);
2021-12-28 16:06:23 +08:00
s1->setPosition(s.width / 2 - s.width / 3, s.height / 2);
s1->setScale(0.25f);
auto p1 = Sprite::create("Images/r1.png");
p1->setScale(0.25f);
p1->setPosition(s1->getPosition());
addChild(p1, 10);
auto s2 = Sprite::createWithSpriteFrameName("blocks9ss/blocks9r.png");
addChild(s2);
2021-12-28 16:06:23 +08:00
s2->setPosition(s.width / 2, s.height / 2);
s2->setCenterRectNormalized(Rect(1 / 3.f, 1 / 3.f, 1 / 3.f, 1 / 3.f));
s2->setContentSize(s2->getContentSize() * 1.5);
auto p2 = Sprite::create("Images/r1.png");
p2->setScale(0.25f);
p2->setPosition(s2->getPosition());
addChild(p2, 10);
auto s3 = Sprite::create("Images/grossini.png");
addChild(s3);
2021-12-28 16:06:23 +08:00
s3->setPosition(s.width / 2 + s.width / 3, s.height / 2 + s.height / 3);
s3->setContentSize(s3->getContentSize() * 1.5);
auto p3 = Sprite::create("Images/r1.png");
p3->setScale(0.25f);
p3->setPosition(s3->getPosition());
addChild(p3, 10);
auto s4 = Sprite::create("Images/grossini.png");
addChild(s4);
2021-12-28 16:06:23 +08:00
s4->setPosition(s.width / 2 + s.width / 3, s.height / 2 - s.height / 3);
s4->setContentSize(s2->getContentSize() * 1.5);
s4->setStretchEnabled(false);
auto p4 = Sprite::create("Images/r1.png");
p4->setScale(0.25f);
p4->setPosition(s3->getPosition());
addChild(p4, 10);
_s1 = s1;
_s2 = s2;
_s3 = s3;
_s4 = s4;
scheduleUpdate();
}
void Issue17119::update(float dt)
{
_accum += dt;
2021-12-28 16:06:23 +08:00
if (_accum > 0.5)
{
_accum = 0;
auto flipped = _s1->isFlippedX();
_s1->setFlippedX(!flipped);
_s2->setFlippedX(!flipped);
_s3->setFlippedX(!flipped);
_s4->setFlippedX(!flipped);
}
}