void FishingJoy::reset() { int gold = STATIC_DATA_INT(GameConfig::GOLD); this->setGold(gold); this->setSoundVolume(STATIC_DATA_FLOAT(GameConfig::SOUND_VALUME)); this->setMusicVolume(STATIC_DATA_FLOAT(GameConfig::MUSIC_VALUME)); this->flush(); }
//----------------------------------------------------------------------------- //todo 预载入资源,实现StartScene后将其删除 void CGameScene::preloadResources() { CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("fishingjoy_resource.plist"); //以下代码创建了两个不同的动画帧序列,使用时获取动画可以这么做:CCAnimation* animation = CCAnimationCache::sharedAnimationCache()->animationByName(const char* name); int frameCount = STATIC_DATA_INT("fish_frame_count"); for (int type = k_Fish_Type_Red; type < k_Fish_Type_Count; type++) { //以下代码会创建animation失败 // CCAnimation* fishAnimation = CCAnimation::create(); // for (int i = 0; i < frameCount; i++) // { // fishAnimation->addSpriteFrameWithFileName( // CCString::createWithFormat(STATIC_DATA_STRING("fish_frame_name_format"), type, i)->getCString()); // } CCArray* spriteFramesArray = CCArray::createWithCapacity(frameCount); for (int i = 0; i < frameCount; i++) { CCString* fileName = CCString::createWithFormat(STATIC_DATA_STRING("fish_frame_name_format"), type, i); CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fileName->getCString()); spriteFramesArray->addObject(spriteFrame); } CCAnimation* fishAnimation = CCAnimation::createWithSpriteFrames(spriteFramesArray); fishAnimation->setDelayPerUnit(STATIC_DATA_FLOAT("fish_frame_delay")); CCString* animationName = CCString::createWithFormat(STATIC_DATA_STRING("fish_animation"),type); CCAnimationCache::sharedAnimationCache()->addAnimation(fishAnimation, animationName->getCString()); } }
void Bullet::flyTo(cocos2d::Vec2 targetInWorldSpace) { this->setVisible(true); //设置方向 Vec2 startInNodeSpace = Vec2::ZERO; Vec2 startInWorldSpace = this->getParent()->convertToWorldSpace(startInNodeSpace); Vec2 targetInNodeSpace = this->getParent()->convertToNodeSpace(targetInWorldSpace); Vec2 normal = targetInWorldSpace-startInWorldSpace; float angle = normal.getNormalized().getAngle(Vec2(0,1)); this->setRotation(CC_RADIANS_TO_DEGREES(angle)); this->setPosition(startInNodeSpace); this->setVisible(true); float speed = STATIC_DATA_FLOAT(GameConfig::BULLET_SPEED_NORMAL); float duration = startInNodeSpace.getDistance(targetInNodeSpace)/speed; MoveTo * pMove = MoveTo::create(duration,targetInNodeSpace); FiniteTimeAction * pSeq = Sequence::create(pMove,CallFunc::create(CC_CALLBACK_0(Bullet::end,this)),nullptr); pSeq->setTag(BULLET_ANCTION::k_Action_1); this->runAction(pSeq); }
//todo 预载入资源,实现StartScene后将其删除 void GameScene::preloadResources() { CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("fishingjoy_resource.plist"); int frameCount = STATIC_DATA_INT("fish_frame_count"); for (int type = k_Fish_Type_Red; type < k_Fish_Type_Count; type++) { CCArray* spriteFrames = CCArray::createWithCapacity(frameCount); for(int i = 0;i < frameCount;i++){ CCString* filename = CCString::createWithFormat(STATIC_DATA_STRING("fish_frame_name_format"),type,i); CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(filename->getCString()); spriteFrames->addObject(spriteFrame); } CCAnimation* fishAnimation = CCAnimation::createWithSpriteFrames(spriteFrames); fishAnimation->setDelayPerUnit(STATIC_DATA_FLOAT("fish_frame_delay")); CCString* animationName = CCString::createWithFormat(STATIC_DATA_STRING("fish_animation"), type); CCAnimationCache::sharedAnimationCache()->addAnimation(fishAnimation, animationName->getCString()); } }