PuzzleSDK
IntervalTest.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 "IntervalTest.h"
26#include "../testResource.h"
27
29
30#define SID_STEP1 100
31#define SID_STEP2 101
32#define SID_STEP3 102
33
34#define IDC_PAUSE 200
35
36IntervalTests::IntervalTests()
37{
39}
40
42{
43 _time0 = _time1 = _time2 = _time3 = _time4 = 0.0f;
44
45 auto s = Director::getInstance()->getWinSize();
46 // sun
47 auto sun = ParticleSun::create();
48 sun->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
49 sun->setPosition(VisibleRect::rightTop().x-32,VisibleRect::rightTop().y-32);
50
51 sun->setTotalParticles(130);
52 sun->setLife(0.6f);
53 this->addChild(sun);
54
55 // timers
56 _label0 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
57 _label1 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
58 _label2 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
59 _label3 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
60 _label4 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
61
62 scheduleUpdate();
63 schedule([&](float dt){
64 _time1 +=dt;
65
66 char str[10] = {0};
67 sprintf(str, "%2.1f", _time1);
68 _label1->setString( str );
69 }, "step_1");
70
71 schedule([&](float dt){
72 _time2 +=dt;
73
74 char str[10] = {0};
75 sprintf(str, "%2.1f", _time2);
76 _label2->setString( str );
77 }, 0.5, "step_2");
78
79 schedule([&](float dt){
80 _time3 +=dt;
81
82 char str[10] = {0};
83 sprintf(str, "%2.1f", _time3);
84 _label3->setString( str );
85 }, 1, "step_3");
86
87 schedule([&](float dt){
88 _time4 +=dt;
89
90 char str[10] = {0};
91 sprintf(str, "%2.1f", _time4);
92 _label4->setString( str );
93 }, 2, "step_4");
94
95 _label0->setPosition(s.width*1/6, s.height/2);
96 _label1->setPosition(s.width*2/6, s.height/2);
97 _label2->setPosition(s.width*3/6, s.height/2);
98 _label3->setPosition(s.width*4/6, s.height/2);
99 _label4->setPosition(s.width*5/6, s.height/2);
100
101 addChild(_label0);
102 addChild(_label1);
103 addChild(_label2);
104 addChild(_label3);
105 addChild(_label4);
106
107 // Sprite
108 auto sprite = Sprite::create(s_pathGrossini);
109 sprite->setPosition(VisibleRect::left().x + 40, VisibleRect::bottom().y + 50);
110
111 auto jump = JumpBy::create(3, Vec2(s.width-80,0.0f), 50, 4);
112
113 addChild(sprite);
114 sprite->runAction( RepeatForever::create(Sequence::create(jump, jump->reverse(), nullptr) ));
115 // pause button
116 auto item1 = MenuItemFont::create("Pause", [&](Ref* sender) {
117 if(Director::getInstance()->isPaused())
118 Director::getInstance()->resume();
119 else
120 Director::getInstance()->pause();
121 });
122 auto menu = Menu::create(item1, nullptr);
123 menu->setPosition(s.width/2, s.height-50);
124
125 addChild( menu );
126}
127
129{
130 if(Director::getInstance()->isPaused())
131 {
132 Director::getInstance()->resume();
133 }
134}
135
137{
138 _time0 +=dt;
139 char time[10] = {0};
140 sprintf(time, "%2.1f", _time0);
141 _label0->setString(time);
142}
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
USING_NS_CC
cocos2d::Label * _label4
Definition: IntervalTest.h:48
cocos2d::Label * _label0
Definition: IntervalTest.h:44
cocos2d::Label * _label1
Definition: IntervalTest.h:45
virtual void update(float dt) override
cocos2d::Label * _label2
Definition: IntervalTest.h:46
cocos2d::Label * _label3
Definition: IntervalTest.h:47
virtual ~IntervalTest()
static cocos2d::Vec2 bottom()
Definition: VisibleRect.cpp:63
static cocos2d::Vec2 rightTop()
Definition: VisibleRect.cpp:81
static cocos2d::Vec2 left()
Definition: VisibleRect.cpp:45
static const char s_pathGrossini[]
Definition: testResource.h:28