29#include "../BaseTest.h"
40 virtual ~PhysicsDemo();
42 virtual bool init()
override;
43 virtual void onEnter()
override;
44 virtual std::string
title()
const override;
46 void toggleDebugCallback(cocos2d::Ref* sender);
48 cocos2d::Sprite* addGrossiniAtPosition(cocos2d::Vec2 p,
float scale = 1.0);
49 cocos2d::Sprite* makeBall(cocos2d::Vec2 point,
float radius, cocos2d::PhysicsMaterial material = cocos2d::PHYSICSBODY_MATERIAL_DEFAULT);
50 cocos2d::Sprite* makeBox(cocos2d::Vec2 point, cocos2d::Size size,
int color = 0, cocos2d::PhysicsMaterial material = cocos2d::PHYSICSBODY_MATERIAL_DEFAULT);
51 cocos2d::Sprite* makeTriangle(cocos2d::Vec2 point, cocos2d::Size size,
int color = 0, cocos2d::PhysicsMaterial material = cocos2d::PHYSICSBODY_MATERIAL_DEFAULT);
53 bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
54 void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event);
55 void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
61 cocos2d::Texture2D* _spriteTexture;
62 cocos2d::SpriteBatchNode* _ball;
63 std::unordered_map<int, cocos2d::Node*> _mouses;
67class PhysicsDemoLogoSmash :
public PhysicsDemo
70 CREATE_FUNC(PhysicsDemoLogoSmash);
72 void onEnter()
override;
73 virtual std::string title()
const override;
76class PhysicsDemoClickAdd :
public PhysicsDemo
79 CREATE_FUNC(PhysicsDemoClickAdd);
81 virtual ~PhysicsDemoClickAdd();
82 void onEnter()
override;
83 virtual std::string subtitle()
const override;
85 void onTouchesEnded(
const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
86 void onAcceleration(cocos2d::Acceleration* acc, cocos2d::Event* event);
89class PhysicsDemoPyramidStack :
public PhysicsDemo
92 CREATE_FUNC(PhysicsDemoPyramidStack);
94 void onEnter()
override;
95 void updateOnce(
float delta);
96 virtual std::string title()
const override;
99class PhysicsDemoRayCast :
public PhysicsDemo
102 CREATE_FUNC(PhysicsDemoRayCast);
104 PhysicsDemoRayCast();
106 void onEnter()
override;
107 virtual std::string title()
const override;
108 void update(
float delta)
override;
109 void onTouchesEnded(
const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
111 void changeModeCallback(cocos2d::Ref* sender);
113 bool anyRay(cocos2d::PhysicsWorld& world,
const cocos2d::PhysicsRayCastInfo& info,
void* data);
117 cocos2d::DrawNode* _node;
121class PhysicsDemoActions :
public PhysicsDemo
124 CREATE_FUNC(PhysicsDemoActions);
126 void onEnter()
override;
127 virtual std::string title()
const override;
130class PhysicsDemoJoints :
public PhysicsDemo
133 CREATE_FUNC(PhysicsDemoJoints);
135 void onEnter()
override;
136 virtual std::string title()
const override;
139class PhysicsDemoPump :
public PhysicsDemo
142 CREATE_FUNC(PhysicsDemoPump);
144 void onEnter()
override;
145 void update(
float delta)
override;
146 virtual std::string title()
const override;
147 virtual std::string subtitle()
const override;
149 bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
150 void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event);
151 void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
158class PhysicsDemoOneWayPlatform :
public PhysicsDemo
161 CREATE_FUNC(PhysicsDemoOneWayPlatform);
163 void onEnter()
override;
164 virtual std::string title()
const override;
166 bool onContactBegin(cocos2d::PhysicsContact& contact);
169class PhysicsDemoSlice :
public PhysicsDemo
172 CREATE_FUNC(PhysicsDemoSlice);
174 void onEnter()
override;
175 virtual std::string title()
const override;
176 virtual std::string subtitle()
const override;
178 bool slice(cocos2d::PhysicsWorld& world,
const cocos2d::PhysicsRayCastInfo& info,
void* data);
179 void clipPoly(cocos2d::PhysicsShapePolygon* shape, cocos2d::Vec2 normal,
float distance);
181 void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
187class PhysicsDemoBug3988 :
public PhysicsDemo
190 CREATE_FUNC(PhysicsDemoBug3988);
192 void onEnter()
override;
193 virtual std::string title()
const override;
194 virtual std::string subtitle()
const override;
197class PhysicsContactTest :
public PhysicsDemo
200 CREATE_FUNC(PhysicsContactTest);
202 void onEnter()
override;
204 bool onContactBegin(cocos2d::PhysicsContact& contact);
205 virtual std::string title()
const override;
206 virtual std::string subtitle()
const override;
208 void onDecrease(cocos2d::Ref* sender);
209 void onIncrease(cocos2d::Ref* sender);
214 int _yellowTriangleNum;
215 int _blueTriangleNum;
218class PhysicsPositionRotationTest :
public PhysicsDemo
221 CREATE_FUNC(PhysicsPositionRotationTest);
223 void onEnter()
override;
224 virtual std::string title()
const override;
227class PhysicsSetGravityEnableTest :
public PhysicsDemo
230 CREATE_FUNC(PhysicsSetGravityEnableTest);
232 void onEnter()
override;
233 void onScheduleOnce(
float delta);
234 virtual std::string title()
const override;
235 virtual std::string subtitle()
const override;
238class PhysicsDemoBug5482 :
public PhysicsDemo
241 CREATE_FUNC(PhysicsDemoBug5482);
243 void onEnter()
override;
244 void onExit()
override;
245 virtual std::string title()
const override;
246 virtual std::string subtitle()
const override;
248 void changeBodyCallback(cocos2d::Ref* sender);
250 cocos2d::Sprite* _nodeA;
251 cocos2d::Sprite* _nodeB;
252 cocos2d::PhysicsBody* _body;
253 cocos2d::MenuItemFont* _button;
257class PhysicsFixedUpdate :
public PhysicsDemo
260 CREATE_FUNC(PhysicsFixedUpdate);
261 void onEnter()
override;
262 void updateStart(
float delta);
264 virtual void update(
float delta)
override;
265 virtual std::string title()
const override;
266 virtual std::string subtitle()
const override;
269class PhysicsTransformTest :
public PhysicsDemo
272 CREATE_FUNC(PhysicsTransformTest);
274 void onEnter()
override;
275 virtual std::string title()
const override;
277 bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
280 cocos2d::Sprite* _parentSprite;
281 cocos2d::Layer* _rootLayer;
284class PhysicsIssue9959 :
public PhysicsDemo
287 CREATE_FUNC(PhysicsIssue9959);
289 void onEnter()
override;
290 virtual std::string title()
const override;
291 virtual std::string subtitle()
const override;
294class PhysicsIssue15932 :
public PhysicsDemo
297 CREATE_FUNC(PhysicsIssue15932);
299 void onEnter()
override;
300 virtual std::string title()
const override;
301 virtual std::string subtitle()
const override;
#define DEFINE_TEST_SUITE(__className__)
virtual std::string title() const
virtual void onEnter() override