Scene* HelloWorld::createScene() { // 'scene' is an autorelease object auto scene = Scene::createWithPhysics(); // 'layer' is an autorelease object auto layer = HelloWorld::create(); // add layer as a child to scene scene->addChild(layer); // 重力の設定. layer->world = scene->getPhysicsWorld(); Vect gravity; gravity.setPoint(0.0f, -1500.0f); layer->world->setGravity(gravity); // layer->world Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); // 地面の描画. auto floor = Sprite::create("Texture/Background.png"); auto backgroundSize = floor->getContentSize(); floor->setPosition(Vec2(visibleSize.width / 2 + origin.x, backgroundSize.height / 2.0f)); layer->addChild(floor, 0); // 地面の物理設定. auto floorPhysicsBody = PhysicsBody::createBox(backgroundSize); floorPhysicsBody->setDynamic(false); floorPhysicsBody->setCategoryBitmask(1); auto dummyPhysicsBody = PhysicsBody::createBox(Size(0, 0)); dummyPhysicsBody->setPositionOffset(floor->getPosition()); dummyPhysicsBody->setDynamic(false); //auto joint = PhysicsJointDistance::construct(floorPhysicsBody, dummyPhysicsBody, floor->getPosition(), Vec2(0, 10)); auto pin = PhysicsJointPin::construct(floorPhysicsBody, dummyPhysicsBody, Vec2(0, 90)); pin->setCollisionEnable(false); floor->setPhysicsBody(floorPhysicsBody); layer->floor = floor; //scene->getPhysicsWorld()->addJoint(pin); for (int i = 0; i < 2; i++) { // ボールの描画. auto ball = Sprite::create("Texture/Ball.png"); layer->ballList.push_back(ball); ball->setPosition(Vec2(visibleSize.width / 2 + origin.x + i * 32, visibleSize.height / 2.0f + i * 256)); // ボールの物理設定. auto ballMaterial = PHYSICSBODY_MATERIAL_DEFAULT; ballMaterial.restitution = 1.5f; ballMaterial.friction = 0.8f; auto ballPhysicsBody = PhysicsBody::createCircle(ball->getContentSize().width / 2.0f, ballMaterial); ballPhysicsBody->setMass(10.0f); ballPhysicsBody->setCollisionBitmask(1); ballPhysicsBody->setCategoryBitmask(2); ball->setPhysicsBody(ballPhysicsBody); layer->addChild(ball, -i); } layer->setTouchMode(kCCTouchesOneByOne); layer->setTouchEnabled(true); // return the scene return scene; }