PuzzleSDK
ActionsProgressTest.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2012 cocos2d-x.org
3 Copyright (c) 2013-2016 Chukong Technologies Inc.
4 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
5
6 http://www.cocos2d-x.org
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 ****************************************************************************/
26
27#include "ActionsProgressTest.h"
28#include "../testResource.h"
29
31
32ActionsProgressTests::ActionsProgressTests()
33{
41}
42
43//------------------------------------------------------------------
44//
45// SpriteDemo
46//
47//------------------------------------------------------------------
49{
50}
51
53{
54}
55
56std::string SpriteDemo::title() const
57{
58 return "ActionsProgressTest";
59}
60
62{
64
65 auto background = LayerColor::create(Color4B(255,0,0,255));
66 addChild(background, -10);
67}
68
69//------------------------------------------------------------------
70//
71// SpriteProgressToRadial
72//
73//------------------------------------------------------------------
75{
77
78 auto s = Director::getInstance()->getWinSize();
79
80 auto to1 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));
81 auto to2 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));
82
83 auto left = ProgressTimer::create(Sprite::create(s_pathSister1));
84 left->setType( ProgressTimer::Type::RADIAL );
85 addChild(left);
86 left->setPosition(100, s.height/2);
87 left->runAction( RepeatForever::create(to1));
88
89 auto right = ProgressTimer::create(Sprite::create(s_pathBlock));
90 right->setType(ProgressTimer::Type::RADIAL);
91 // Makes the ridial CCW
92 right->setReverseDirection(true);
93 addChild(right);
94 right->setPosition(s.width-100, s.height/2);
95 right->runAction( RepeatForever::create(to2));
96}
97
99{
100 return "ProgressTo Radial";
101}
102
103//------------------------------------------------------------------
104//
105// SpriteProgressToHorizontal
106//
107//------------------------------------------------------------------
108
110{
112
113 auto s = Director::getInstance()->getWinSize();
114
115 auto to1 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));
116 auto to2 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));
117
118 auto left = ProgressTimer::create(Sprite::create(s_pathSister1));
119 left->setType(ProgressTimer::Type::BAR);
120 // Setup for a bar starting from the left since the midpoint is 0 for the x
121 left->setMidpoint(Vec2(0.0f,0.0f));
122 // Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change
123 left->setBarChangeRate(Vec2(1.0f, 0.0f));
124 addChild(left);
125 left->setPosition(100, s.height/2);
126 left->runAction( RepeatForever::create(to1));
127
128 auto right = ProgressTimer::create(Sprite::create(s_pathSister2));
129 right->setType(ProgressTimer::Type::BAR);
130 // Setup for a bar starting from the left since the midpoint is 1 for the x
131 right->setMidpoint(Vec2(1.0f, 0.0f));
132 // Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change
133 right->setBarChangeRate(Vec2(1.0f, 0.0f));
134 addChild(right);
135 right->setPosition(s.width-100, s.height/2);
136 right->runAction( RepeatForever::create(to2));
137}
138
140{
141 return "ProgressTo Horizontal";
142}
143
144//------------------------------------------------------------------
145//
146// SpriteProgressToVertical
147//
148//------------------------------------------------------------------
150{
152
153 auto s = Director::getInstance()->getWinSize();
154
155 auto to1 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));
156 auto to2 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));
157
158 auto left = ProgressTimer::create(Sprite::create(s_pathSister1));
159 left->setType(ProgressTimer::Type::BAR);
160
161 // Setup for a bar starting from the bottom since the midpoint is 0 for the y
162 left->setMidpoint(Vec2(0.0f,0.0f));
163 // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
164 left->setBarChangeRate(Vec2(0.0f, 1.0f));
165 addChild(left);
166 left->setPosition(100, s.height/2);
167 left->runAction( RepeatForever::create(to1));
168
169 auto right = ProgressTimer::create(Sprite::create(s_pathSister2));
170 right->setType(ProgressTimer::Type::BAR);
171 // Setup for a bar starting from the bottom since the midpoint is 0 for the y
172 right->setMidpoint(Vec2(0, 1));
173 // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
174 right->setBarChangeRate(Vec2(0, 1));
175 addChild(right);
176 right->setPosition(s.width-100, s.height/2);
177 right->runAction( RepeatForever::create(to2));
178}
179
181{
182 return "ProgressTo Vertical";
183}
184
185//------------------------------------------------------------------
186//
187// SpriteProgressToRadialMidpointChanged
188//
189//------------------------------------------------------------------
191{
193
194 auto s = Director::getInstance()->getWinSize();
195
196 auto action = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));
197
201 auto left = ProgressTimer::create(Sprite::create(s_pathBlock));
202 left->setType(ProgressTimer::Type::RADIAL);
203 addChild(left);
204 left->setMidpoint(Vec2(0.25f, 0.75f));
205 left->setPosition(100, s.height/2);
206 left->runAction(RepeatForever::create(action->clone()));
207
211 auto right = ProgressTimer::create(Sprite::create(s_pathBlock));
212 right->setType(ProgressTimer::Type::RADIAL);
213 right->setMidpoint(Vec2(0.75f, 0.25f));
214
219 addChild(right);
220 right->setPosition(s.width-100, s.height/2);
221 right->runAction(RepeatForever::create(action->clone()));
222}
223
225{
226 return "Radial w/ Different Midpoints";
227}
228
229//------------------------------------------------------------------
230//
231// SpriteProgressBarVarious
232//
233//------------------------------------------------------------------
235{
237
238 auto s = Director::getInstance()->getWinSize();
239
240 auto to = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0));
241
242 auto left = ProgressTimer::create(Sprite::create(s_pathSister1));
243 left->setType(ProgressTimer::Type::BAR);
244
245 // Setup for a bar starting from the bottom since the midpoint is 0 for the y
246 left->setMidpoint(Vec2(0.5f, 0.5f));
247 // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
248 left->setBarChangeRate(Vec2(1.0f, 0.0f));
249 addChild(left);
250 left->setPosition(100, s.height/2);
251 left->runAction(RepeatForever::create(to->clone()));
252
253 auto middle = ProgressTimer::create(Sprite::create(s_pathSister2));
254 middle->setType(ProgressTimer::Type::BAR);
255 // Setup for a bar starting from the bottom since the midpoint is 0 for the y
256 middle->setMidpoint(Vec2(0.5f, 0.5f));
257 // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
258 middle->setBarChangeRate(Vec2(1,1));
259 addChild(middle);
260 middle->setPosition(s.width/2, s.height/2);
261 middle->runAction(RepeatForever::create(to->clone()));
262
263 auto right = ProgressTimer::create(Sprite::create(s_pathSister2));
264 right->setType(ProgressTimer::Type::BAR);
265 // Setup for a bar starting from the bottom since the midpoint is 0 for the y
266 right->setMidpoint(Vec2(0.5f, 0.5f));
267 // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
268 right->setBarChangeRate(Vec2(0, 1));
269 addChild(right);
270 right->setPosition(s.width-100, s.height/2);
271 right->runAction(RepeatForever::create(to->clone()));
272}
273
275{
276 return "ProgressTo Bar Mid";
277}
278
279//------------------------------------------------------------------
280//
281// SpriteProgressBarTintAndFade
282//
283//------------------------------------------------------------------
285{
287
288 auto s = Director::getInstance()->getWinSize();
289
290 auto to = Sequence::createWithTwoActions(ProgressTo::create(6, 100), ProgressTo::create(0, 0));
291 auto tint = Sequence::create(TintTo::create(1, 255, 0, 0),
292 TintTo::create(1, 0, 255, 0),
293 TintTo::create(1, 0, 0, 255),
294 nullptr);
295 auto fade = Sequence::create(FadeTo::create(1.0f, 0),
296 FadeTo::create(1.0f, 255),
297 nullptr);
298
299 auto left = ProgressTimer::create(Sprite::create(s_pathSister1));
300 left->setType(ProgressTimer::Type::BAR);
301
302 // Setup for a bar starting from the bottom since the midpoint is 0 for the y
303 left->setMidpoint(Vec2(0.5f, 0.5f));
304 // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
305 left->setBarChangeRate(Vec2(1.0f, 0.0f));
306 addChild(left);
307 left->setPosition(100, s.height/2);
308 left->runAction(RepeatForever::create(to->clone()));
309 left->runAction(RepeatForever::create(tint->clone()));
310
311 left->addChild(Label::createWithTTF("Tint", "fonts/Marker Felt.ttf", 20.0f));
312
313 auto middle = ProgressTimer::create(Sprite::create(s_pathSister2));
314 middle->setType(ProgressTimer::Type::BAR);
315 // Setup for a bar starting from the bottom since the midpoint is 0 for the y
316 middle->setMidpoint(Vec2(0.5f, 0.5f));
317 // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
318 middle->setBarChangeRate(Vec2(1, 1));
319 addChild(middle);
320 middle->setPosition(s.width/2, s.height/2);
321 middle->runAction(RepeatForever::create(to->clone()));
322 middle->runAction(RepeatForever::create(fade->clone()));
323
324 middle->addChild(Label::createWithTTF("Fade", "fonts/Marker Felt.ttf", 20.0f));
325
326 auto right = ProgressTimer::create(Sprite::create(s_pathSister2));
327 right->setType(ProgressTimer::Type::BAR);
328 // Setup for a bar starting from the bottom since the midpoint is 0 for the y
329 right->setMidpoint(Vec2(0.5f, 0.5f));
330 // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
331 right->setBarChangeRate(Vec2(0, 1));
332 addChild(right);
333 right->setPosition(s.width-100, s.height/2);
334 right->runAction(RepeatForever::create(to->clone()));
335 right->runAction(RepeatForever::create(tint->clone()));
336 right->runAction(RepeatForever::create(fade->clone()));
337
338 right->addChild(Label::createWithTTF("Tint and Fade", "fonts/Marker Felt.ttf", 20.0f));
339}
340
342{
343 return "ProgressTo Bar Mid";
344}
345
346//------------------------------------------------------------------
347//
348// SpriteProgressWithSpriteFrame
349//
350//------------------------------------------------------------------
352{
354
355 auto s = Director::getInstance()->getWinSize();
356
357 auto to = Sequence::createWithTwoActions(ProgressTo::create(6, 100), ProgressTo::create(0, 0));
358
359 SpriteFrameCache::getInstance()->addSpriteFramesWithFile("zwoptex/grossini.plist");
360
361 auto left = ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_01.png"));
362 left->setType(ProgressTimer::Type::BAR);
363 // Setup for a bar starting from the bottom since the midpoint is 0 for the y
364 left->setMidpoint(Vec2(0.5f, 0.5f));
365 // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
366 left->setBarChangeRate(Vec2(1.0f, 0.0f));
367 addChild(left);
368 left->setPosition(100, s.height/2);
369 left->runAction(RepeatForever::create(to->clone()));
370
371 auto middle = ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_02.png"));
372 middle->setType(ProgressTimer::Type::BAR);
373 // Setup for a bar starting from the bottom since the midpoint is 0 for the y
374 middle->setMidpoint(Vec2(0.5f, 0.5f));
375 // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
376 middle->setBarChangeRate(Vec2(1, 1));
377 addChild(middle);
378 middle->setPosition(s.width/2, s.height/2);
379 middle->runAction(RepeatForever::create(to->clone()));
380
381 auto right = ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_03.png"));
382 right->setType(ProgressTimer::Type::RADIAL);
383 // Setup for a bar starting from the bottom since the midpoint is 0 for the y
384 right->setMidpoint(Vec2(0.5f, 0.5f));
385 // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
386 right->setBarChangeRate(Vec2(0, 1));
387 addChild(right);
388 right->setPosition(s.width-100, s.height/2);
389 right->runAction(RepeatForever::create(to->clone()));
390}
391
393{
394 return "Progress With Sprite Frame";
395}
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
virtual void onEnter() override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void onEnter() override
Definition: BaseTest.cpp:430
static const char s_pathSister1[]
Definition: testResource.h:29
static const char s_pathSister2[]
Definition: testResource.h:30
static const char s_pathBlock[]
Definition: testResource.h:37