Skip to content

Instantly share code, notes, and snippets.

@lamlambda
Created January 18, 2016 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lamlambda/534d7700579739da47bc to your computer and use it in GitHub Desktop.
Save lamlambda/534d7700579739da47bc to your computer and use it in GitHub Desktop.
物理エンジン使ってみる
#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