PuzzleSDK
MotionStreakTest.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 "MotionStreakTest.h"
26#include "../testResource.h"
27#include <YjzLib/yjz_clip.hpp>
28
30
31enum {
35};
36
37MotionStreakTests::MotionStreakTests()
38{
43}
44
45//------------------------------------------------------------------
46//
47// MotionStreakTest1
48//
49//------------------------------------------------------------------
50
52{
54
55 auto s = Director::getInstance()->getWinSize();
56
57 // the root object just rotates around
58 _root = Sprite::create(s_pathR1);
59 addChild(_root, 1);
60 _root->setPosition(Vec2(s.width/2, s.height/2));
61
62 // the target object is offset from root, and the streak is moved to follow it
63 _target = Sprite::create(s_pathR1);
64 _root->addChild(_target);
65 _target->setPosition(Vec2(s.width/4, 0.0f));
66
67 // create the streak object and add it to the scene
68 _streak = MotionStreak::create(2, 3, 32, Color3B::GREEN, s_streak);
69 addChild(_streak);
70 // schedule an update on each frame so we can synchronize the streak with the target
71 schedule(CC_SCHEDULE_SELECTOR(MotionStreakTest1::onUpdate));
72
73 auto a1 = RotateBy::create(2, 360);
74
75 auto action1 = RepeatForever::create(a1);
76 auto motion = MoveBy::create(2, Vec2(100,0) );
77 _root->runAction( RepeatForever::create(Sequence::create(motion, motion->reverse(), nullptr) ) );
78 _root->runAction( action1 );
79
80 auto colorAction = RepeatForever::create(Sequence::create(
81 TintTo::create(0.2f, 255, 0, 0),
82 TintTo::create(0.2f, 0, 255, 0),
83 TintTo::create(0.2f, 0, 0, 255),
84 TintTo::create(0.2f, 0, 255, 255),
85 TintTo::create(0.2f, 255, 255, 0),
86 TintTo::create(0.2f, 255, 0, 255),
87 TintTo::create(0.2f, 255, 255, 255),
88 nullptr));
89
90 _streak->runAction(colorAction);
91}
92
94{
95 _streak->setPosition( _target->convertToWorldSpace(Vec2::ZERO) );
96}
97
98std::string MotionStreakTest1::title() const
99{
100 return "MotionStreak test 1";
101}
102
103//------------------------------------------------------------------
104//
105// MotionStreakTest2
106//
107//------------------------------------------------------------------
108
110{
112
113 auto listener = EventListenerTouchAllAtOnce::create();
114 listener->onTouchesMoved = CC_CALLBACK_2(MotionStreakTest2::onTouchesMoved, this);
115 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
116
117 _yjzTest([this,listener]()
118 {
119 listener->onTouchesBegan =
120 [this](const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event)
121 {
122 auto streak = this->_streak ;
123 streak->reset() ;
124 };
125
126 listener->onTouchesEnded =
127 [this](const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event)
128 {
129 auto streak = this->_streak ;
130 streak->reset() ;
131 };
132
133 listener->onTouchesCancelled =
134 [this](const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event)
135 {
136 auto streak = this->_streak ;
137 streak->reset() ;
138 };
139 });
140 auto s = Director::getInstance()->getWinSize();
141
142 // create the streak object and add it to the scene
143 _streak = MotionStreak::create(10, 3, 64, Color3B::WHITE, s_streak );
144 addChild(_streak);
145
146 _streak->setPosition( Vec2(s.width/2, s.height/2) );
147}
148
149void MotionStreakTest2::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
150{
151 auto touchLocation = touches[0]->getLocation();
152
153 _streak->setPosition( touchLocation );
154}
155
156std::string MotionStreakTest2::title() const
157{
158 return "MotionStreak test";
159}
160
162{
163 return "Need Touch Movement";
164}
165
166//------------------------------------------------------------------
167//
168// Issue1358
169//
170//------------------------------------------------------------------
171
173{
175
176 // ask director the the window size
177 auto size = Director::getInstance()->getWinSize();
178
179 _streak = MotionStreak::create(2.0f, 1.0f, 50.0f, Color3B(255, 255, 0), "Images/Icon.png");
180 addChild(_streak);
181
182
183 _center = Vec2(size.width/2, size.height/2);
184 _radius = size.width/3;
185 _angle = 0.0f;
186
187 schedule(CC_SCHEDULE_SELECTOR(Issue1358::update), 0);
188}
189
190void Issue1358::update(float dt)
191{
192 _angle += 1.0f;
193 _streak->setPosition(Vec2(_center.x + cosf(_angle/180 * M_PI)*_radius,
194 _center.y + sinf(_angle/ 180 * M_PI)*_radius));
195}
196
197std::string Issue1358::title() const
198{
199 return "Issue 1358";
200}
201
202std::string Issue1358::subtitle() const
203{
204 return "The tail should use the texture";
205}
206
207//------------------------------------------------------------------
208//
209// Issue12226
210//
211//------------------------------------------------------------------
212
214{
216
217 // ask director the the window size
218 auto size = Director::getInstance()->getWinSize();
219
220 auto radius = size.width/3;
221
222 auto outer = Sprite::create("Images/grossini.png");
223 outer->setPosition(size/2);
224 addChild(outer);
225
226
227 _streak = MotionStreak::create(1.0f, 3, radius * 1.5f, Color3B(0xA0, 0xA0, 0xA0), "ccb/particle-smoke.png");
228// motionStreak->setOpacity(0x70);
229 _streak->setPosition(outer->getPosition());
230
231 this->addChild(_streak, outer->getLocalZOrder() - 1);
232
233 outer->setUserData(_streak);
234
235 const uint32_t length = (radius * 0.95);
236
237 std::function<void(float)> updateMotionStreak = [=](float dt) {
238
239 Vec2 position = Vec2(outer->getPositionX() + length * cosf(-1 * CC_DEGREES_TO_RADIANS(outer->getRotation() + 90.0f)),
240 outer->getPositionY() + length * sinf(-1 * CC_DEGREES_TO_RADIANS(outer->getRotation() + 90.0f)));
241
242 _streak->setPosition(position);
243 };
244
245 outer->schedule(updateMotionStreak, 1 / 240.0f, CC_REPEAT_FOREVER, 0, "motion1scheduler");
246
247 auto rot = RotateBy::create(2, 360);
248 auto forever = RepeatForever::create(rot);
249 outer->runAction(forever);
250
251}
252
253std::string Issue12226::title() const
254{
255 return "Github Issue 12226";
256}
257
258std::string Issue12226::subtitle() const
259{
260 return "Image should look without artifacts";
261}
262
263//------------------------------------------------------------------
264//
265// MotionStreakTest
266//
267//------------------------------------------------------------------
268
270{
271}
272
274{
275}
276
277std::string MotionStreakTest::title() const
278{
279 return "No title";
280}
281
282std::string MotionStreakTest::subtitle() const
283{
284 return "";
285}
286
288{
290
291 auto s = Director::getInstance()->getWinSize();
292
293 auto itemMode = MenuItemToggle::createWithCallback( CC_CALLBACK_1(MotionStreakTest::modeCallback, this),
294 MenuItemFont::create("Use High Quality Mode"),
295 MenuItemFont::create("Use Fast Mode"),
296 nullptr);
297
298 auto menuMode = Menu::create(itemMode, nullptr);
299 addChild(menuMode);
300
301 menuMode->setPosition(Vec2(s.width/2, s.height/4));
302}
303
305{
306 bool fastMode = _streak->isFastMode();
307 _streak->setFastMode(! fastMode);
308}
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
@ kTagSprite2
@ kTagSprite1
@ kTagLabel
USING_NS_CC
virtual std::string subtitle() const override
virtual std::string title() const override
virtual void onEnter() override
virtual std::string subtitle() const override
cocos2d::Vec2 _center
virtual std::string title() const override
virtual void onEnter() override
virtual void update(float dt) override
cocos2d::Node * _target
void onUpdate(float delta)
virtual void onEnter() override
virtual std::string title() const override
cocos2d::Node * _root
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual void onEnter() override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
void modeCallback(cocos2d::Ref *sender)
virtual void onEnter() override
virtual std::string subtitle() const override
cocos2d::MotionStreak * _streak
virtual void onEnter() override
Definition: BaseTest.cpp:430
static const char s_streak[]
Definition: testResource.h:46
static const char s_pathR1[]
Definition: testResource.h:33