Created
January 18, 2016 20:45
-
-
Save lamlambda/534d7700579739da47bc to your computer and use it in GitHub Desktop.
物理エンジン使ってみる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HelloWorldScene.h" | |
USING_NS_CC; | |
Scene* HelloWorld::createScene() | |
{ | |
auto scene = Scene::createWithPhysics(); | |
auto layer = HelloWorld::create(); | |
scene->addChild(layer); | |
// 重力を設定 | |
PhysicsWorld* world = scene->getPhysicsWorld(); | |
Vect gravity; | |
gravity.setPoint(0, -300); | |
world->setGravity(gravity); | |
world->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL); | |
Size winSize = Director::getInstance()->getWinSize(); | |
// 壁下 | |
Sprite* bottom = Sprite::create("wall_yoko.png"); | |
bottom->setPosition(Point(winSize.width / 2, bottom->getContentSize().height / 2)); | |
PhysicsBody* bottomPb = PhysicsBody::createBox(bottom->getContentSize()); | |
bottomPb->setDynamic(false); | |
bottom->setPhysicsBody(bottomPb); | |
layer->addChild(bottom); | |
// cocos2dxちゃん追加 | |
Sprite* c2dx = Sprite::create("2dx.png"); | |
c2dx->setPosition(Point(winSize.width / 2, winSize.height / 2)); | |
PhysicsBody* c2dxPb = PhysicsBody::createBox(c2dx->getContentSize()); | |
c2dxPb->setMass(1.0f); | |
c2dx->setPhysicsBody(c2dxPb); | |
layer->addChild(c2dx); | |
return scene; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment