#include "HelloWorldScene.h"
Scene* HelloWorld::createScene()
{
… 생략 : Box2dEx02의 코드와 같음 …
}
bool HelloWorld::init()
{
… 생략 : Box2dEx02의 코드와 같음 …
}
bool HelloWorld::createBox2dWorld(bool debug)
{
… 생략 : Box2dEx02의 코드와 같음 …
}
void HelloWorld::setBox2dWorld()
{
b2RevoluteJointDef revJointDef1;
b2RevoluteJointDef revJointDef2;
b2RevoluteJointDef revJointDef3;
b2RevoluteJointDef revJointDef4;
b2Body* body1 = this->addNewSprite(Vec2(160, 260), Size(34, 34),
b2_staticBody, "test", 0);
b2Body* body2 = this->addNewSprite(Vec2(200, 260), Size(34, 34),
b2_dynamicBody, "test", 0);
b2Body* body3 = this->addNewSprite(Vec2(240, 260), Size(34, 34),
b2_dynamicBody, "test", 0);
b2Body* body4 = this->addNewSprite(Vec2(280, 260), Size(34, 34),
b2_dynamicBody, "test", 0);
b2Body* body5 = this->addNewSprite(Vec2(320, 260), Size(34, 34),
b2_staticBody, "test", 0);
revJointDef1.Initialize(body1, body2, body1->GetPosition());
revJointDef2.Initialize(body2, body3, body2->GetPosition());
revJointDef3.Initialize(body4, body3, body4->GetPosition());
revJointDef4.Initialize(body5, body4, body5->GetPosition());
_world->CreateJoint(&revJointDef1);
_world->CreateJoint(&revJointDef2);
_world->CreateJoint(&revJointDef3);
_world->CreateJoint(&revJointDef4);
}
HelloWorld::~HelloWorld()
{
… 생략 : Box2dEx02의 코드와 같음 …
}
void HelloWorld::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
… 생략 : Box2dEx02의 코드와 같음 …
}
void HelloWorld::onDraw(const Mat4 &transform, uint32_t flags)
{
… 생략 : Box2dEx02의 코드와 같음 …
}
void HelloWorld::onEnter()
{
Scene::onEnter();
// 싱글터치모드로 터치리스너 등록
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
void HelloWorld::onExit()
{
… 생략 : Box2dEx02의 코드와 같음 …
}
void HelloWorld::tick(float dt)
{
… 생략 : Box2dEx02의 코드와 같음 …
}
b2Body* HelloWorld::addNewSprite(Vec2 point, Size size, b2BodyType bodytype,
const char* spriteName, int type)
{
… 생략 : Box2dEx02의 코드와 같음 …
}
b2Body* HelloWorld::getBodyAtTab(Vec2 p)
{
… 생략 : Box2dEx02의 코드와 같음 …
}
bool HelloWorld::onTouchBegan(Touch* touch, Event* event)
{
Vec2 touchPoint = touch->getLocation();
if (b2Body* b = this->getBodyAtTab(touchPoint))
{
b2JointEdge* joints = b->GetJointList();
while (joints)
{
b2Joint* joint = joints->joint;
joints = joints->next;
_world->DestroyJoint(joint);
}
}
return true;
}