PuzzleSDK
ZwoptexTest.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3
4 http://www.cocos2d-x.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 ****************************************************************************/
24
25#include "ZwoptexTest.h"
26#include "../testResource.h"
27
29
30ZwoptexTests::ZwoptexTests()
31{
33}
34
35//------------------------------------------------------------------
36//
37// ZwoptexGenericTest
38//
39//------------------------------------------------------------------
41{
43
44 auto s = Director::getInstance()->getWinSize();
45
46 SpriteFrameCache::getInstance()->addSpriteFramesWithFile("zwoptex/grossini.plist");
47 SpriteFrameCache::getInstance()->addSpriteFramesWithFile("zwoptex/grossini-generic.plist");
48
49 auto layer1 = LayerColor::create(Color4B(255, 0, 0, 255), 85, 121);
50 layer1->setPosition(Vec2(s.width/2-80 - (85.0f * 0.5f), s.height/2 - (121.0f * 0.5f)));
51 addChild(layer1);
52
53 sprite1 = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini_dance_01.png"));
54 sprite1->setPosition(Vec2( s.width/2-80, s.height/2));
55 addChild(sprite1);
56
57 sprite1->setFlippedX(false);
58 sprite1->setFlippedY(false);
59
60 auto layer2 = LayerColor::create(Color4B(255, 0, 0, 255), 85, 121);
61 layer2->setPosition(Vec2(s.width/2+80 - (85.0f * 0.5f), s.height/2 - (121.0f * 0.5f)));
62 addChild(layer2);
63
64 sprite2 = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini_dance_generic_01.png"));
65 sprite2->setPosition(Vec2( s.width/2 + 80, s.height/2));
66 addChild(sprite2);
67
68 sprite2->setFlippedX(false);
69 sprite2->setFlippedY(false);
70
71 schedule(CC_SCHEDULE_SELECTOR(ZwoptexGenericTest::startIn05Secs), 1.0f);
72
73 sprite1->retain();
74 sprite2->retain();
75
76 counter = 0;
77}
78
80{
81 unschedule(CC_SCHEDULE_SELECTOR(ZwoptexGenericTest::startIn05Secs));
82 schedule(CC_SCHEDULE_SELECTOR(ZwoptexGenericTest::flipSprites), 0.5f);
83}
84
85static int spriteFrameIndex = 0;
87{
88 counter++;
89
90 bool fx = false;
91 bool fy = false;
92 int i = counter % 4;
93
94 switch ( i )
95 {
96 case 0:
97 fx = false;
98 fy = false;
99 break;
100 case 1:
101 fx = true;
102 fy = false;
103 break;
104 case 2:
105 fx = false;
106 fy = true;
107 break;
108 case 3:
109 fx = true;
110 fy = true;
111 break;
112 }
113
114 sprite1->setFlippedX(fx);
115 sprite2->setFlippedX(fx);
116 sprite1->setFlippedY(fy);
117 sprite2->setFlippedY(fy);
118
119 if(++spriteFrameIndex > 14)
120 {
122 }
123
124 char str1[32] = {0};
125 char str2[32] = {0};
126 sprintf(str1, "grossini_dance_%02d.png", spriteFrameIndex);
127 sprintf(str2, "grossini_dance_generic_%02d.png", spriteFrameIndex);
128 sprite1->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str1));
129 sprite2->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str2));
130}
131
133{
134 sprite1->release();
135 sprite2->release();
136 auto cache = SpriteFrameCache::getInstance();
137 cache->removeSpriteFramesFromFile("zwoptex/grossini.plist");
138 cache->removeSpriteFramesFromFile("zwoptex/grossini-generic.plist");
139}
140
141std::string ZwoptexGenericTest::title() const
142{
143 return "Zwoptex Tests";
144}
145
147{
148 return "Coordinate Formats, Rotation, Trimming, flipX/Y";
149}
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
USING_NS_CC
Definition: ZwoptexTest.cpp:28
static int spriteFrameIndex
Definition: ZwoptexTest.cpp:85
virtual void onEnter() override
Definition: BaseTest.cpp:430
void flipSprites(float dt)
Definition: ZwoptexTest.cpp:86
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void onEnter() override
Definition: ZwoptexTest.cpp:40
virtual ~ZwoptexGenericTest()
cocos2d::Sprite * sprite2
Definition: ZwoptexTest.h:53
cocos2d::Sprite * sprite1
Definition: ZwoptexTest.h:52
void startIn05Secs(float dt)
Definition: ZwoptexTest.cpp:79