PuzzleSDK
RotateWorldTest.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 "RotateWorldTest.h"
26#include "../testResource.h"
27
29
30RotateWorldTests::RotateWorldTests()
31{
33}
34
35//------------------------------------------------------------------
36//
37// TestLayer
38//
39//------------------------------------------------------------------
41{
42 Layer::onEnter();
43
44 float x,y;
45
46 auto size = Director::getInstance()->getWinSize();
47 x = size.width;
48 y = size.height;
49
50 //auto array = [UIFont familyNames];
51 //for( String *s in array )
52 // NSLog( s );
53 auto label = Label::createWithSystemFont("cocos2d", "Tahoma", 64);
54
55 label->setPosition( Vec2(x/2,y/2) );
56
57 addChild(label);
58}
59
60//------------------------------------------------------------------
61//
62// SpriteLayer
63//
64//------------------------------------------------------------------
66{
67 Layer::onEnter();
68
69 float x,y;
70
71 auto size = Director::getInstance()->getWinSize();
72 x = size.width;
73 y = size.height;
74
75 auto sprite = Sprite::create(s_pathGrossini);
76 auto spriteSister1 = Sprite::create(s_pathSister1);
77 auto spriteSister2 = Sprite::create(s_pathSister2);
78
79 sprite->setScale(1.5f);
80 spriteSister1->setScale(1.5f);
81 spriteSister2->setScale(1.5f);
82
83 sprite->setPosition(Vec2(x/2,y/2));
84 spriteSister1->setPosition(Vec2(40.0f,y/2));
85 spriteSister2->setPosition(Vec2(x-40,y/2));
86
87 auto rot = RotateBy::create(16, -3600);
88
89 addChild(sprite);
90 addChild(spriteSister1);
91 addChild(spriteSister2);
92
93 sprite->runAction(rot);
94
95 auto jump1 = JumpBy::create(4, Vec2(-400,0), 100, 4);
96 auto jump2 = jump1->reverse();
97
98 auto rot1 = RotateBy::create(4, 360*2);
99 auto rot2 = rot1->reverse();
100
101 spriteSister1->runAction(Repeat::create( Sequence::create(jump2, jump1, nullptr), 5 ));
102 spriteSister2->runAction(Repeat::create( Sequence::create(jump1->clone(), jump2->clone(), nullptr), 5 ));
103
104 spriteSister1->runAction(Repeat::create( Sequence::create(rot1, rot2, nullptr), 5 ));
105 spriteSister2->runAction(Repeat::create( Sequence::create(rot2->clone(), rot1->clone(), nullptr), 5 ));
106}
107
108//------------------------------------------------------------------
109//
110// RotateWorldMainLayer
111//
112//------------------------------------------------------------------
113
115{
116 Layer::onEnter();
117
118 float x,y;
119
120 auto size = Director::getInstance()->getWinSize();
121 x = size.width;
122 y = size.height;
123
124 auto blue = LayerColor::create(Color4B(0,0,255,255));
125 auto red = LayerColor::create(Color4B(255,0,0,255));
126 auto green = LayerColor::create(Color4B(0,255,0,255));
127 auto white = LayerColor::create(Color4B(255,255,255,255));
128
129 blue->setScale(0.5f);
130 blue->setPosition(Vec2(-x/4,-y/4));
131 blue->addChild( SpriteLayer::create() );
132
133 red->setScale(0.5f);
134 red->setPosition(Vec2(x/4,-y/4));
135
136 green->setScale(0.5f);
137 green->setPosition(Vec2(-x/4,y/4));
138 green->addChild(TestLayer::create());
139
140 white->setScale(0.5f);
141 white->setPosition(Vec2(x/4,y/4));
142 white->setIgnoreAnchorPointForPosition(false);
143 white->setPosition(Vec2(x/4*3,y/4*3));
144
145 addChild(blue, -1);
146 addChild(white);
147 addChild(green);
148 addChild(red);
149
150 auto rot = RotateBy::create(8, 720);
151
152 blue->runAction(rot);
153 red->runAction(rot->clone());
154 green->runAction(rot->clone());
155 white->runAction(rot->clone());
156}
157
159{
160 if (TestCase::init())
161 {
162 auto layer = RotateWorldMainLayer::create();
163
164 addChild(layer);
165 runAction(RotateBy::create(4.0f, -360.0f));
166
167 return true;
168 }
169
170 return false;
171}
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
USING_NS_CC
virtual void onEnter() override
virtual bool init() override
virtual void onEnter() override
virtual void onEnter() override
static const char s_pathSister1[]
Definition: testResource.h:29
static const char s_pathSister2[]
Definition: testResource.h:30
static const char s_pathGrossini[]
Definition: testResource.h:28