Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
物理エンジン使ってみる
#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