// Creates an instance of Player // @param png - The path to the PNG representation of the sprite // @param plist - The path to the PLIST representation of the sprite Player* Player::create() { // Create an instance of Player Player* playerSprite = new Player(); // Reset travelled distance playerSprite->setDistanceTravelled(0); // Get resource loader instance ResourceLoader resLoader = ResourceLoader::getInstance(); // Get running animation Vector<SpriteFrame*> runningAnimation = resLoader.getAnimation(PLAYER_ANIMATION_RUNNING); // Generate player movement sprites if (playerSprite->initWithSpriteFrame(runningAnimation.at(0))) { auto animation = Animation::createWithSpriteFrames(runningAnimation); // Set delay between frames animation->setDelayPerUnit(PLAYER_SPRITE_DELAY_RUNNING); //Create running action auto runningAction = RepeatForever::create(Animate::create(animation)); //Set tag for action runningAction->setTag(PLAYER_ANIMATION_RUNNING); // Run animation forever playerSprite->runAction(runningAction); // Set properties playerSprite->autorelease(); playerSprite->initOptions(); playerSprite->setScale(Director::getInstance()->getWinSize().width * 1.8 / 800); playerSprite->scheduleUpdate(); // Add weapon Weapon* weapon = Weapon::create(); playerSprite->setWeapon(weapon); //Create physical body auto spriteBody = PhysicsBody::createBox(playerSprite->boundingBox().size, PhysicsMaterial(1.0f, 0.5f, 0.5f)); spriteBody->setAngularVelocityLimit(0.0f); spriteBody->setMass(1); spriteBody->setCollisionBitmask(PLAYER_COLLISION_BITMASK); spriteBody->setContactTestBitmask(true); playerSprite->setPhysicsBody(spriteBody); // Return return playerSprite; } CC_SAFE_DELETE(playerSprite); return NULL; }
void Player::resumePlayer() { auto spriteBody = PhysicsBody::createBox(this->boundingBox().size, PhysicsMaterial(1.0f, 0.5f, 0.5f)); spriteBody->setAngularVelocityLimit(0.0f); spriteBody->setMass(1); spriteBody->setCollisionBitmask(PLAYER_COLLISION_BITMASK); spriteBody->setContactTestBitmask(true); this->setPhysicsBody(spriteBody); this->getPhysicsBody()->setVelocity(velocityOnPause); }
bool Player::init() { this->initWithFile("mario_mini.png"); //this->setScale(0.2f); auto pb = PhysicsBody::createBox(Size(this->getContentSize().width - 10, this->getContentSize().height-20)); //log("%f,%f",size.width,size.height); pb->setEnable(true); pb->setMass(1.0f); pb->setVelocity(Vect(0,1)); pb->setVelocityLimit(100.0); pb->setRotationEnable(true); pb->setAngularVelocityLimit(150.0f); pb->setDynamic(true); pb->setContactTestBitmask(0xFFFFFFFF); this->setPosition(Point(228,708)); this->setPhysicsBody(pb); return true; }