bool CCActivityIndicator::init()
{
    auto spritecache = SpriteFrameCache::getInstance();
    
    spritecache->addSpriteFramesWithFile("ccactivityindicator.plist");
    CCSpriteBatchNode::initWithFile("ccactivityindicator.png", 1);
    
    Size winSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    indicator = CCSprite::createWithSpriteFrameName("ccactivityindicator_1.gif");
    indicator->setPosition(Vec2(winSize.width/2,winSize.height/2));
    addChild(indicator);
    
    animating = false;
    hidesWhenStopped = true;
    
//    beginCallback = NULL;
//    endCallback =


    //load all sprite frames into array
    for (int i=1; i<=kActivityIndicatorFramesCount; i++) {
        SpriteFrame * frame = spritecache->getSpriteFrameByName(CCString::createWithFormat("ccactivityindicator_%d.gif",i)->getCString());
        frame->retain();
        spriteFrames.pushBack(frame);
    }
    
    return true;
}
예제 #2
0
bool SGSHero::initAttackActions()
{
  std::string hero_attack_res_file_full_path = getHeroResFile(SG_SKIRMISH_SCENE_HERO_ATTACK_RES_PATH);

  Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(hero_attack_res_file_full_path);
  for (int i = 0; i < 12; i++) {
    SpriteFrame* frame = SpriteFrame::createWithTexture(
      texture, Rect(0, SG_SKIRMISH_SCENE_HERO_ATTACK_RES_HEIGHT * i, 
      SG_SKIRMISH_SCENE_HERO_ATTACK_RES_WIDTH, SG_SKIRMISH_SCENE_HERO_ATTACK_RES_HEIGHT));
    frame->retain();
    __attack_sprite_frames.pushBack(frame);
  }

  Vector<SpriteFrame*>* animFrames_south = new Vector<SpriteFrame*>;
  animFrames_south->pushBack(__attack_sprite_frames.at(0));
  animFrames_south->pushBack(__attack_sprite_frames.at(1));
  animFrames_south->pushBack(__attack_sprite_frames.at(2));
  animFrames_south->pushBack(__attack_sprite_frames.at(3));
  Animation* animation_south = Animation::createWithSpriteFrames(*animFrames_south, SGS_HERO_ATTACK_ACTION_INTERVAL);
  Animate* animate_south = Animate::create(animation_south);
  animate_south->retain();
  std::string animate_name = "attack_south";
  __animate_map[animate_name] = animate_south;

  Vector<SpriteFrame*>* animFrames_north = new Vector<SpriteFrame*>;
  animFrames_north->pushBack(__attack_sprite_frames.at(4));
  animFrames_north->pushBack(__attack_sprite_frames.at(5));
  animFrames_north->pushBack(__attack_sprite_frames.at(6));
  animFrames_north->pushBack(__attack_sprite_frames.at(7));
  Animation* animation_north = Animation::createWithSpriteFrames(*animFrames_north, SGS_HERO_ATTACK_ACTION_INTERVAL);
  Animate* animate_north = Animate::create(animation_north);
  animate_north->retain();
  animate_name = "attack_north";
  __animate_map[animate_name] = animate_north;

  Vector<SpriteFrame*>* animFrames_west = new Vector<SpriteFrame*>;
  animFrames_west->pushBack(__attack_sprite_frames.at(8));
  animFrames_west->pushBack(__attack_sprite_frames.at(9));
  animFrames_west->pushBack(__attack_sprite_frames.at(10));
  animFrames_west->pushBack(__attack_sprite_frames.at(11));
  Animation* animation_west = Animation::createWithSpriteFrames(*animFrames_west, SGS_HERO_ATTACK_ACTION_INTERVAL);
  Animate* animate_west = Animate::create(animation_west);
  animate_west->retain();
  animate_name = "attack_west";
  __animate_map[animate_name] = animate_west;

  return true;
}
예제 #3
0
bool SGSHero::initSpecActions()
{
  std::string hero_spec_res_file_full_path = getHeroResFile(SG_SKIRMISH_SCENE_HERO_SPEC_RES_PATH);
  Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(hero_spec_res_file_full_path);
  for (int i = 0; i < 5; i++) {
    SpriteFrame* frame = SpriteFrame::createWithTexture(
      texture, Rect(0, SG_SKIRMISH_SCENE_HERO_SPEC_RES_WIDTH * i, 
      SG_SKIRMISH_SCENE_HERO_SPEC_RES_WIDTH, SG_SKIRMISH_SCENE_HERO_SPEC_RES_HEIGHT));
    frame->retain();
    __spec_sprite_frames.pushBack(frame);
  }
  Vector<SpriteFrame*>* block_south = new Vector<SpriteFrame*>;
  block_south->pushBack(__spec_sprite_frames.at(0));
  Animation* animation_south = Animation::createWithSpriteFrames(*block_south, 0.5f);
  Animate* animate_south = Animate::create(animation_south);
  animate_south->retain();
  std::string animate_name = "block_south";
  __animate_map[animate_name] = animate_south;

  Vector<SpriteFrame*>* block_north = new Vector<SpriteFrame*>;
  block_north->pushBack(__spec_sprite_frames.at(1));
  Animation* animation_north = Animation::createWithSpriteFrames(*block_north, 0.5f);
  Animate* animate_north = Animate::create(animation_north);
  animate_north->retain();
  animate_name = "block_north";
  __animate_map[animate_name] = animate_north;

  Vector<SpriteFrame*>* block_west = new Vector<SpriteFrame*>;
  block_west->pushBack(__spec_sprite_frames.at(2));
  Animation* animation_west = Animation::createWithSpriteFrames(*block_west, 0.5f);
  Animate* animate_west = Animate::create(animation_west);
  animate_west->retain();
  animate_name = "block_west";
  __animate_map[animate_name] = animate_west;

  Vector<SpriteFrame*>* attacked = new Vector<SpriteFrame*>;
  attacked->pushBack(__spec_sprite_frames.at(3));
  Animation* animation_attacked = Animation::createWithSpriteFrames(*attacked, 1.0f);
  Animate* animate_attack = Animate::create(animation_attacked);
  animate_attack->retain();
  animate_name = "attacked";
  __animate_map[animate_name] = animate_attack;
  return true;
}
예제 #4
0
bool SGSHero::initActions()
{
  std::string hero_res_file_full_path = getHeroResFile(SG_SKIRMISH_SCENE_HERO_RES_PATH);
  // Init hero start picture
  if (!Sprite::initWithFile(hero_res_file_full_path, Rect(0, 0, SG_SKIRMISH_SCENE_HERO_WALK_RES_WIDTH, SG_SKIRMISH_SCENE_HERO_WALK_RES_HEIGHT))) {
    return false;
  }

  Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(hero_res_file_full_path);
  for (int i = 0; i < 11; i++) {
    SpriteFrame* frame = SpriteFrame::createWithTexture(
      texture, Rect(0, SG_SKIRMISH_SCENE_HERO_WALK_RES_HEIGHT * i, 
      SG_SKIRMISH_SCENE_HERO_WALK_RES_WIDTH, SG_SKIRMISH_SCENE_HERO_WALK_RES_HEIGHT));
    frame->retain();
    __sprite_frames.pushBack(frame);
  }

  Vector<SpriteFrame*>* animFrames = new Vector<SpriteFrame*>;
  animFrames->pushBack(__sprite_frames.at(0));
  animFrames->pushBack(__sprite_frames.at(1));
  Animation* animation = Animation::createWithSpriteFrames(*animFrames, 0.2f);
  Animate* animate = Animate::create(animation);
  animate->retain();
  std::string animate_name = "face_south";
  __animate_map[animate_name] = animate;

  Vector<SpriteFrame*>* animFrames_north = new Vector<SpriteFrame*>;
  animFrames_north->pushBack(__sprite_frames.at(2));
  animFrames_north->pushBack(__sprite_frames.at(3));
  Animation* animation_north = Animation::createWithSpriteFrames(*animFrames_north, 0.2f);
  Animate* animate_north = Animate::create(animation_north);
  animate_north->retain();
  animate_name = "face_north";
  __animate_map[animate_name] = animate_north;

  Vector<SpriteFrame*>* animFrames_west = new Vector<SpriteFrame*>;
  animFrames_west->pushBack(__sprite_frames.at(4));
  animFrames_west->pushBack(__sprite_frames.at(5));
  Animation* animation_west = Animation::createWithSpriteFrames(*animFrames_west, 0.2f);
  Animate* animate_west = Animate::create(animation_west);
  animate_west->retain();
  animate_name = "face_west";
  __animate_map[animate_name] = animate_west;

  Vector<SpriteFrame*>* fragile = new Vector<SpriteFrame*>;
  fragile->pushBack(__sprite_frames.at(9));
  Animation* animation_fragile = Animation::createWithSpriteFrames(*fragile, 1.0f);
  Animate* animate_fragile = Animate::create(animation_fragile);
  animate_fragile->retain();
  animate_name = "fragile";
  __animate_map[animate_name] = animate_fragile;


  Vector<SpriteFrame*>* wheeze = new Vector<SpriteFrame*>;
  wheeze->pushBack(__sprite_frames.at(9));
  wheeze->pushBack(__sprite_frames.at(10));
  Animation* animation_wheeze = Animation::createWithSpriteFrames(*wheeze, 0.2f);
  Animate* animate_wheeze = Animate::create(animation_wheeze);
  animate_wheeze->retain();
  animate_name = "wheeze";
  __animate_map[animate_name] = animate_wheeze;
  return true;
}