#include "FlappyBird.h"
Scene* FlappyBird::createScene(){
auto scene = Scene::create();
auto layer = FlappyBird::create();
scene->addChild(layer);
return scene;
}
bool FlappyBird::init(){
if (!Layer::init()){
return false;
}
sizeWin = Director::getInstance()->getVisibleSize();
initPhysice();
addSprite();
scheduleUpdate();
return true;
}
void FlappyBird::addSprite(){
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(sizeWin.width / 2 / RAITO,9);
b2Body* body = world->CreateBody(&bodyDef);
PhysicsSprite* sprite = PhysicsSprite::create("birds.png",Rect(0,0,52,45));
sprite->setB2Body(body);
sprite->setPTMRatio(RAITO);
//sprite->setPosition(Point(sizeWin.width/2,sizeWin.height/2));
addChild(sprite);
}
void FlappyBird::update(float dt){
world->Step(dt,8,3);
}
void FlappyBird::initPhysice(){
world = new b2World(b2Vec2(0.0f,-10.0f));
}