- FCO 배우 고윤정 [15]
- FCO 감스트 역량 파급력 개쩌네 [14]
- 로아 뉴비를 위한 로스트아크 직업 추천! [221]
- 걸그룹 정채연 인스타 [10]
- 차벤 우리 동네 당근 근황.jpg [6]
Document Version : V1.3 - 2017.07.12 with cocos2d-x 3.15.1
Document Version : V1.2 - 2015.06.08 with cocos2d-x 3.6
Document Version : V1.1 - 2014.03.14 with cocos2d-x 3.0beta2
Document Version : V1.0 - 2013.07.10 with cocos2d-x 2.1.4
제 책인 "시작하세요! Cocos2d-x 3.0 프로그래밍" 내용을 3.15.1 버전에 맞게 수정하여 올리고 있습니다.
이 글은 네이버카페 "Cocos2d-x 사용자 모임"에 동시에 게재되고 있습니다.
개발환경 :
c:> cocos new Box2dEx12 -p com.study.box12 -l cpp ↵
Box2dEx04의 모든 코드를 방금 만든 Box2dEx12에 적용시킵니다.
Box2dEx04의 Classes 폴더의 다음 파일들을 Box2dEx12의 Classes 폴더에 덮어 쓰면 됩니다.
■ HelloWorldScene.h
■ HelloWorldScene.cpp
■ GLES-Render.h
■ GLES-Render.cpp
그러고 나서 다음의 디렉터리에서
{Cocos2d-x가 설치된 디렉터리} / tests / cpp-tests / Resources / Images
아래의 파일을 찾아 리소스 폴더에 추가합니다.
[ HelloWorldScene.h – 박스2D 기어 조인트 ]
… 생략 : Box2dEx04의 코드와 같음 …
[ HelloWorldScene.cpp – 박스2D 기어 조인트 ]
… 생략 : Box2dEx04의 코드와 같음 …
void HelloWorld::setBox2dWorld()
{
// 마우스 조인트 바디를 생성해서 월드에 추가한다.
bDrag = false;
gbody = this->addNewSprite(Vec2(0, 0), Size(0, 0), b2_staticBody, nullptr, 0);
// *****************************************************************************
b2GearJointDef gearJointDef;
b2RevoluteJointDef jointDef1;
b2RevoluteJointDef jointDef2;
b2RevoluteJoint* joint1;
b2RevoluteJoint* joint2;
b2Body* body0 = this->addNewSprite(Vec2(240, 160), Size(160, 60),
b2_staticBody, nullptr, 0);
b2Body* body1 = this->addNewSprite(Vec2(240 - 40, 160), Size(40, 40),
b2_dynamicBody, nullptr, 1);
b2Body* body2 = this->addNewSprite(Vec2(240 + 20, 160), Size(80, 80),
b2_dynamicBody, nullptr, 1);
jointDef1.Initialize(body0, body1, body1->GetPosition());
jointDef2.Initialize(body0, body2, body2->GetPosition());
jointDef1.enableMotor = true;
jointDef1.motorSpeed = 1;
jointDef1.maxMotorTorque = 10;
// joint1 생성전에 위 모터의 속성들이 정의되어야 한다.
joint1 = (b2RevoluteJoint *)_world->CreateJoint(&jointDef1);
joint2 = (b2RevoluteJoint *)_world->CreateJoint(&jointDef2);
gearJointDef.bodyA = body1;
gearJointDef.bodyB = body2;
gearJointDef.joint1 = (b2Joint *)joint1;
gearJointDef.joint2 = (b2Joint *)joint2;
gearJointDef.ratio = 2.0;
_world->CreateJoint(&gearJointDef);
}
… 생략 : Box2dEx04의 코드와 같음 …
b2RevoluteJoint* joint1;
b2RevoluteJoint* joint2;
b2Body* body0 = this->addNewSprite(Vec2(240, 160), Size(160, 60),
b2_staticBody, nullptr, 0);
b2Body* body1 = this->addNewSprite(Vec2(240 - 40, 160), Size(40, 40),
b2_dynamicBody, nullptr, 1);
b2Body* body2 = this->addNewSprite(Vec2(240 + 20, 160), Size(80, 80),
b2_dynamicBody, nullptr, 1);
jointDef1.Initialize(body0, body1, body1->GetPosition());
jointDef2.Initialize(body0, body2, body2->GetPosition());
jointDef1.enableMotor = true;
jointDef1.motorSpeed = 1;
jointDef1.maxMotorTorque = 10;
gearJointDef.bodyA = body1;
gearJointDef.bodyB = body2;
gearJointDef.joint1 = (b2Joint *)joint1;
gearJointDef.joint2 = (b2Joint *)joint2;
gearJointDef.ratio = 2.0;
_world->CreateJoint(&gearJointDef);
내폰젤무거워