void textHandler(void *ctx, const char *ch, int len)
 {
     CC_UNUSED_PARAM(ctx);
     
     const std::string text = std::string((char*)ch,len);
     
     if (_key)
     {
         if (_keys.size() == 1 && _keys.front() == "frames")
         {
             SpriteFrame* frame = _cache->getSpriteFrameByName(text);
             _frames.pushBack(frame);
         }
         
         _keys.push_back(text);
     }
 }
void Bacterial::setLevel(int value)
{
	if(level != value && value <= MAXLEVEL)
	{
		level = value;
		SpriteFrameCache* cache = SpriteFrameCache::getInstance();
		if(level > 0)
		{
			inited = true;
			SpriteFrame* frame = cache->getSpriteFrameByName(String::createWithFormat("res/%d%d.png", type, level)->getCString());
			bg->setSpriteFrame(frame);
		}
		else
		{
			inited = false;
		}
	}
}
Exemple #3
0
cocos2d::Animation * Entity::createAnimation(const char *str, int num) {
	//»ñÈ¡»º´æʵÀý
	SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();

	SpriteFrame *frame = nullptr;
	Vector<SpriteFrame*> frameVec;


	for (int i = 0; i < num; i++) {
		frame = frameCache->getSpriteFrameByName(StringUtils::format("%s%d.png", str, i));
		frameVec.pushBack(frame);
	}

	Animation *animation = Animation::createWithSpriteFrames(frameVec);
	animation->setLoops(-1);
	animation->setDelayPerUnit(0.2f);

	return animation;
}
Exemple #4
0
Size CTextRich::_getMesureSpriteContentSize(const std::string& path)
{
	if (_mesureSprite == nullptr)
	{
		_mesureSprite = Sprite::create();
		_mesureSprite->retain();
	}

	SpriteFrameCache *cache = SpriteFrameCache::getInstance();
	SpriteFrame *spriteFrame = cache->getSpriteFrameByName(path);
	if (spriteFrame)
	{
		_mesureSprite->setSpriteFrame(spriteFrame);
		return _mesureSprite->getContentSize();
	}else{
		CCLOG("miss SpriteFrame: ",path.c_str());
		return Size();
	}
}
Exemple #5
0
Action* CSprite::createFrameCaheAction(const string& pattern, int count, float duration, bool loop) {
    SpriteFrameCache* spriteFrameCache = SpriteFrameCache::getInstance();
    Vector<SpriteFrame*>* framesVector = new Vector<SpriteFrame*>;
    char frameName[128];
    for(int i = 1; i <= count; i++){
        sprintf(frameName, pattern.c_str(), i);
        SpriteFrame* frame = spriteFrameCache->getSpriteFrameByName(frameName);
        framesVector->pushBack(frame);
    }

    float delay = duration / framesVector->size();
    Animation* animation = Animation::createWithSpriteFrames(*framesVector, delay);
    Animate* animate = Animate::create(animation);
    Action* action = NULL;
    if (loop) {
        action = RepeatForever::create(animate);
    } else {
        action = (Action*) animate;
    }
    delete framesVector;
    return action;
}
Exemple #6
0
RepeatForever* PeerJelly::moving()
{
    // 3. repeat the frame
    int numFrame = 3;

    cocos2d::Vector<cocos2d::SpriteFrame *> frames;
    SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();

    char file[100] = {0};

    for (int i = 0; i < numFrame; i++)
    {
        sprintf(file, "redJelly_%d.png", i+1);
        SpriteFrame *frame = frameCache->getSpriteFrameByName(file);
        frames.pushBack(frame);
    }

    Animation *animation = Animation::createWithSpriteFrames(frames, 0.3f);
    Animate *animate = Animate::create(animation);
    auto easeInAnimation = EaseIn::create(animate, 0.3f);
    RepeatForever *repeat = RepeatForever::create(easeInAnimation);
    return repeat;
}
Exemple #7
0
void Item::explode(){
    //play the explode animation
    explodeIndicator = 1;
    if(haveExplode == 0){
    haveExplode=1;
    SpriteFrameCache* cache = SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile("explode/explode.plist");
    Vector<SpriteFrame*> animFrames(14);
    char str[100]={0};
    for(int i=1; i<=14; i++){
        sprintf(str, "exp%d.png",i);
        SpriteFrame* frame = cache->getSpriteFrameByName(str);
        animFrames.insert(i-1, frame);
    }

    Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
    Animate* act = Animate::create(animation);
        
    Sequence* endAct=Sequence::create(act,CallFunc::create( std::bind(&Item::explodeEnd,this) ),NULL);
    item->runAction(endAct);

    }
}
void gameLevel2::shipExplosions(Vec2 vec,bool scale) {

	SpriteBatchNode* spritebatch = SpriteBatchNode::create("animations/explosion.png");
	SpriteFrameCache* cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile("animations/explosion.plist");
	auto explosion = Sprite::createWithSpriteFrameName("explosion_01.png");
	explosion->setPosition(vec);
	if (scale) explosion->setScale(0.5);
	spritebatch->addChild(explosion);
	this->addChild(spritebatch);
	Vector<SpriteFrame*> animFrames(48);

	char str[100] = { 0 };
	for (int i = 1; i < 49; i++)
	{
		sprintf(str, "explosion_%02d.png", i);
		SpriteFrame* frame = cache->getSpriteFrameByName(str);
		animFrames.pushBack(frame);
	}

	Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.02);
	explosion->runAction(Sequence::create(Animate::create(animation),RemoveSelf::create(),NULL));
	
}
Exemple #9
0
RepeatForever*Bird::moving()
{
    // 3. repeat the frame
    int numFrame = 3;
    
    //ocos2d::Vector<cocos2d::SpriteFrame *> frames;
    SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
    
    char file[100] = {0};
    
    for (int i = 0; i < numFrame; i++) {
        sprintf(file, "FlappyBird%d.png", i+1);
        SpriteFrame *frame = frameCache->getSpriteFrameByName(file);
        frames.pushBack(frame);
       // frames->getPositionY.
    }
    
    Animation *animation = Animation::createWithSpriteFrames(frames, 0.1);
    
    Animate *animate = Animate::create(animation);
    
    RepeatForever *repeat = RepeatForever::create(animate);
    return repeat;
}
Exemple #10
0
Animate*  EffectUtil::getSkillEffectById(int id,int loop){
	SpriteFrameCache* cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile(String::createWithFormat("Skill/Effect/%d.plist",id)->getCString(),
		String::createWithFormat("Skill/Effect/%d.png",id)->getCString());
	SpriteFrame* temp;
	Vector<SpriteFrame*> v;
	int index = 1;
	do{
		CCLOG("INDEX = %d",index);
		temp = cache->getSpriteFrameByName(String::createWithFormat("%d_%d.png",id,index)->getCString());
		index++;
		if(temp == nullptr){
			break;
		}else{
			v.pushBack(temp);
		}
	}while(true);

	Animation* animation = Animation::createWithSpriteFrames(v);
	animation->setLoops(loop);
	animation->setDelayPerUnit(0.1f);
	Animate* ret = Animate::create(animation);
	return ret;
}
Exemple #11
0
CCBKeyframe* CCBReader::readKeyframe(PropertyType type)
{
    CCBKeyframe *keyframe = new (std::nothrow) CCBKeyframe();
    keyframe->autorelease();

    keyframe->setTime(readFloat());

    CCBKeyframe::EasingType easingType = static_cast<CCBKeyframe::EasingType>(readInt(false));
    float easingOpt = 0;
    Value value;

    if (easingType == CCBKeyframe::EasingType::CUBIC_IN
        || easingType == CCBKeyframe::EasingType::CUBIC_OUT
        || easingType == CCBKeyframe::EasingType::CUBIC_INOUT
        || easingType == CCBKeyframe::EasingType::ELASTIC_IN
        || easingType == CCBKeyframe::EasingType::ELASTIC_OUT
        || easingType == CCBKeyframe::EasingType::ELASTIC_INOUT)
    {
        easingOpt = readFloat();
    }
    keyframe->setEasingType(easingType);
    keyframe->setEasingOpt(easingOpt);

    if (type == PropertyType::CHECK)
    {
        value = readBool();
    }
    else if (type == PropertyType::BYTE)
    {
        value = readByte();
    }
    else if (type == PropertyType::COLOR3)
    {
        unsigned char r = readByte();
        unsigned char g = readByte();
        unsigned char b = readByte();

        ValueMap colorMap;
        colorMap["r"] = r;
        colorMap["g"] = g;
        colorMap["b"] = b;

        value = colorMap;
    }
    else if (type == PropertyType::DEGREES)
    {
        value = readFloat();
    }
    else if (type == PropertyType::SCALE_LOCK || type == PropertyType::POSITION
         || type == PropertyType::FLOAT_XY)
    {
        float a = readFloat();
        float b = readFloat();

        ValueVector ab;
        ab.push_back(Value(a));
        ab.push_back(Value(b));

        value = ab;
    }
    else if (type == PropertyType::SPRITEFRAME)
    {
        std::string spriteSheet = readCachedString();
        std::string spriteFile = readCachedString();

        SpriteFrame* spriteFrame;

        if (spriteSheet.empty())
        {
            spriteFile = _CCBRootPath + spriteFile;

            Texture2D *texture = Director::DirectorInstance->getTextureCache()->addImage(spriteFile);
            Rect bounds = Rect(0, 0, texture->getContentSize().width, texture->getContentSize().height);

            spriteFrame = SpriteFrame::createWithTexture(texture, bounds);
        }
        else
        {
            spriteSheet = _CCBRootPath + spriteSheet;
            SpriteFrameCache* frameCache = SpriteFrameCache::getInstance();

            // Load the sprite sheet only if it is not loaded
            if (_loadedSpriteSheets.find(spriteSheet) == _loadedSpriteSheets.end())
            {
                frameCache->addSpriteFramesWithFile(spriteSheet);
                _loadedSpriteSheets.insert(spriteSheet);
            }

            spriteFrame = frameCache->getSpriteFrameByName(spriteFile);
        }

        keyframe->setObject(spriteFrame);
    }

    if (!value.isNull())
        keyframe->setValue(value);

    return  keyframe;
}
bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    this->isGameOver = false;
    
    visibleSize = Director::getInstance()->getVisibleSize();
    
    // Ground setup
    groundSprite0 = Sprite::create("ground.png");
    this->addChild(groundSprite0);
    groundSprite0->setPosition(Vec2(groundSprite0->getContentSize().width/2.0 , groundSprite0->getContentSize().height/2));
    
    groundSprite1 = Sprite::create("ground.png");
    this->addChild(groundSprite1);
    groundSprite1->setPosition(Vec2(visibleSize.width + groundSprite1->getContentSize().width/2.0 -10, groundSprite1->getContentSize().height/2));
    
    auto groundbody0 = PhysicsBody::createBox(groundSprite0->getContentSize());
    groundbody0->setDynamic(false);
    groundbody0->setContactTestBitmask(true);
    groundSprite0->setPhysicsBody(groundbody0);
    auto groundbody1 = PhysicsBody::createBox(groundSprite1->getContentSize());
    groundbody1->setDynamic(false);
    groundbody1->setContactTestBitmask(true);
    groundSprite1->setPhysicsBody(groundbody1);
    
    // SkyGround setup
    Sprite *skySprite0 = Sprite::create("flappy_background.png");
    Sprite *skySprite1 = Sprite::create("flappy_background.png");
    Sprite *skySprite2 = Sprite::create("flappy_background.png");
    this->addChild(skySprite0);
    this->addChild(skySprite1);
    this->addChild(skySprite2);
    skySprite0->setPosition(visibleSize.width/2, 168 + 200);
    skySprite1->setPosition(visibleSize.width/2 - skySprite1->getContentSize().width, 168 + 200);
    skySprite2->setPosition(visibleSize.width/2 + skySprite1->getContentSize().width, 168 + 200);
    
    // bird setup
    /*
    Sprite *birdSprite = Sprite::create("flappybird1.png");
    this->addChild(birdSprite);
    birdSprite->setPosition(visibleSize.width/2, visibleSize.height/2 + 120);
    */

    SpriteFrameCache* cache = SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile("bird.plist");
    
    auto flyAnim = Animation::create();
    for (int i = 1; i < 4; i++) {
        SpriteFrame * frame = cache->getSpriteFrameByName("flappybird" + to_string(i) + ".png");
        flyAnim->addSpriteFrame(frame);
    }
    auto birdSprite = Sprite::createWithSpriteFrameName("flappybird1.png");

    flyAnim->setDelayPerUnit(0.2f);
    
    auto action = Animate::create(flyAnim);
    auto animation = RepeatForever::create(action);
    birdSprite->runAction(animation);
    
    birdSprite->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2 + 80));
    this->addChild(birdSprite);

    auto birdBody = PhysicsBody::createCircle(17.0);
    birdBody->setDynamic(true);
    birdBody->setMass(1.0f);
    birdBody->setVelocity(Vec2(4.0f, 2.0f));
    birdBody->setVelocityLimit(50);
    birdBody->setContactTestBitmask(true);
    birdSprite->setPhysicsBody(birdBody);
    
    //pipe setup
    topPipeSprite = Sprite::create("top_pipe.png");
    bottomPipeSprite = Sprite::create("bottom_pipe.png");
    topPipeSprite->setPosition(visibleSize.width + topPipeSprite->getContentSize().width/2, 600);
    
    auto pipebody0 = PhysicsBody::createBox(topPipeSprite->getContentSize());
    pipebody0->setDynamic(false);
    topPipeSprite->setPhysicsBody(pipebody0);
    pipebody0->setContactTestBitmask(true);
    auto pipebody1 = PhysicsBody::createBox(bottomPipeSprite->getContentSize());
    pipebody1->setDynamic(false);
    pipebody1->setContactTestBitmask(true);
    bottomPipeSprite->setPhysicsBody(pipebody1);
    
    this->positionBottomPipe();
    this->addChild(topPipeSprite);
    this->addChild(bottomPipeSprite);
    
    //setup touch listener
    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);

    listener->onTouchBegan = [=](Touch *touch, Event *event){
        if (!this->isGameOver) {
            birdBody->applyImpulse(Vec2(0, 90.0f));
        }
        log("touch detected!");
        return true;
    };
    
    //setup collision listener
    auto plistener = EventListenerPhysicsContact::create();
    plistener->onContactBegin = [=](PhysicsContact &contact){
        log("collision detected!");
        auto gameOverSprite = Sprite::create("game_over.png");
        gameOverSprite->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
        this->addChild(gameOverSprite);
        this->isGameOver = true;
        
        auto restartListner = EventListenerTouchOneByOne::create();
        restartListner->setSwallowTouches(true);
        restartListner->onTouchBegan = [](Touch *touch, Event* event){
            Director::getInstance()->replaceScene(HelloWorld::createScene());
            return true;
        };
        Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(restartListner, gameOverSprite);
        return true;
    };
    
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(plistener, this);
    this->scheduleUpdate();
    
    return true;
}
Exemple #13
0
void Guns::flashRender() {

	const float FLASH_SPEED = 0.08f;
	const float DELAY_ANIMATION = 0.2f;

	const char *FLASH_NAME = "flash";

	const int LOCAL_Z_ORDER_FLASH = 15;

	SpriteFrameCache* cache = SpriteFrameCache::getInstance();

	Vector<SpriteFrame*> animFrames(2);

	char str[100] = { 0 };

	for (int i = 0; i <= 1; i++)
	{
		sprintf(str, "gunflash%d.png", i);
		SpriteFrame* frame = cache->getSpriteFrameByName(str);
		animFrames.pushBack(frame);
	}

	Animation* animation = Animation::createWithSpriteFrames(animFrames, DELAY_ANIMATION);

	*flash = Sprite::createWithSpriteFrameName("gunflash0.png");

	map->addChild(*flash, LOCAL_Z_ORDER_FLASH, FLASH_NAME);

	(*flash)->setPosition(Vec2(character->getPosition().x - gun->getContentSize().width - 5, character->getPosition().y));

	switch (currentKey) {

	case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
	case EventKeyboard::KeyCode::KEY_A:

		(*flash)->setPosition(Vec2(character->getPosition().x - gun->getContentSize().width - 5, character->getPosition().y));

		break;

	case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
	case EventKeyboard::KeyCode::KEY_D:

		(*flash)->setPosition(Vec2(character->getPosition().x + gun->getContentSize().width + 5, character->getPosition().y));

		break;

	case EventKeyboard::KeyCode::KEY_UP_ARROW:
	case EventKeyboard::KeyCode::KEY_W:

		(*flash)->setPosition(Vec2(character->getPosition().x - gun->getContentSize().width - 5, character->getPosition().y));

		break;

	case EventKeyboard::KeyCode::KEY_DOWN_ARROW:
	case EventKeyboard::KeyCode::KEY_S:

		(*flash)->setPosition(Vec2(character->getPosition().x + gun->getContentSize().width + 5, character->getPosition().y));

		break;
	}

	(*flash)->runAction(Animate::create(animation));

	// Remove flash
	auto delay = DelayTime::create(FLASH_SPEED);

	auto callback = CallFunc::create([=]() {

		map->removeChildByName(FLASH_NAME);
	});

	auto sequence = Sequence::createWithTwoActions(delay, callback);

	this->runAction(sequence);
}
bool StartScreen::init()
{
	if (!Layer::init())
	{
		return false;
	}

	auto rootNode = CSLoader::createNode("Screens/StartScreen.csb");
	addChild(rootNode);
	this->scheduleUpdate();
	auto winSize = Director::getInstance()->getVisibleSize();

	//Animated Santa Sprite
	SpriteBatchNode* spritebatch = SpriteBatchNode::create("Assets/Animation/Idle.png");

	SpriteFrameCache* cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile("Assets/Animation/Idle.plist");

	_santa = Sprite::createWithSpriteFrameName("Assets/Santa/idle_0001.png");
	spritebatch->addChild(_santa);
	addChild(spritebatch);
	_santa->setPosition(Vec2(winSize.width*0.5f, winSize.height*0.7f));

	_background = (Sprite*)rootNode->getChildByName("Background");
	_background->setPosition(Vec2(winSize.width * 0.5, winSize.height * 0.5));

	Vector<SpriteFrame*> animFrames;

	char str[100] = { 0 };
	for (int i = 1; i <= 12; i++)
	{
		sprintf(str, "Assets/Santa/idle_%04d.png", i);
		SpriteFrame* frame = cache->getSpriteFrameByName(str);
		animFrames.pushBack(frame);
	}

	Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
	_santa->runAction(RepeatForever::create(Animate::create(animation)));

	//TOUCHES

	//Set up a touch listener.
	auto touchListener = EventListenerTouchOneByOne::create();

	//Set callbacks for our touch functions.
	touchListener->onTouchBegan = CC_CALLBACK_2(StartScreen::onTouchBegan, this);
	touchListener->onTouchEnded = CC_CALLBACK_2(StartScreen::onTouchEnded, this);
	touchListener->onTouchMoved = CC_CALLBACK_2(StartScreen::onTouchMoved, this);
	touchListener->onTouchCancelled = CC_CALLBACK_2(StartScreen::onTouchCancelled, this);

	//Add our touch listener to event listener list.
	_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

	//BUTTONS
	//Start button
	_btnStart = static_cast<ui::Button*>(rootNode->getChildByName("btnStart"));
	_btnStart->addTouchEventListener(CC_CALLBACK_2(StartScreen::StartButtonPressed, this));
	_btnStart->setPosition(Vec2(winSize.width*0.5f, winSize.height*0.43f));

	//Highscore button.
	_btnHighscore = static_cast<ui::Button*>(rootNode->getChildByName("btnHighscore"));
	_btnHighscore->addTouchEventListener(CC_CALLBACK_2(StartScreen::HighscoreButtonPressed, this));
	_btnHighscore->setPosition(Vec2(winSize.width*0.5f, winSize.height*0.32f));

	//Options button
	_btnOptions = static_cast<ui::Button*>(rootNode->getChildByName("btnOptions"));
	_btnOptions->addTouchEventListener(CC_CALLBACK_2(StartScreen::OptionsButtonPressed, this));
	_btnOptions->setPosition(Vec2(winSize.width*0.5f, winSize.height*0.21f));

	//Exit button
	_btnExit = static_cast<ui::Button*>(rootNode->getChildByName("btnExit"));
	_btnExit->addTouchEventListener(CC_CALLBACK_2(StartScreen::ExitButtonPressed, this));
	_btnExit->setPosition(Vec2(winSize.width*0.5f, winSize.height*0.1f));

	return true;
}
void SetGameCacheController::setGameCache(){
	AnimationCache* animationCache = AnimationCache::getInstance();
	SpriteFrameCache * cache = SpriteFrameCache::getInstance();

	cache->addSpriteFramesWithFile(Constant::getEnemyGoblinPath());
	cache->addSpriteFramesWithFile(Constant::getEnemySoldierPath());
	cache->addSpriteFramesWithFile(Constant::getEnemyArrowEnemyPath());
	cache->addSpriteFramesWithFile(Constant::getEnemySheepPath());
	cache->addSpriteFramesWithFile(Constant::getEnemyBossAttackPath());
	cache->addSpriteFramesWithFile(Constant::getEnemyBossPath());
	//Goblin Move
	Vector <SpriteFrame*> temp;
	char name[20];
	memset(name, 0, sizeof(name));
	for (int i = 0; i < 5; i++){
		sprintf(name, "Goblin_%d.png", i + 1);
		SpriteFrame* sf = cache->spriteFrameByName(name);
		temp.pushBack(sf);
	}

	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.1f), Constant::getEnemyGoblinMove());

	//Sheep Move
	temp.clear();
	memset(name, 0, sizeof(name));
	for (int i = 4; i < 8; i++){
		sprintf(name, "Sheep_%d.png", i);
		SpriteFrame* sf = cache->spriteFrameByName(name);
		temp.pushBack(sf);
	}

	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.1f), Constant::getEnemySheepMove());

	//Soldier Move
	temp.clear();
	memset(name, 0, sizeof(name));
	for (int i = 0; i < 8; i++){
		sprintf(name, "Soldier_%d.png", i + 1);
		SpriteFrame* sf = cache->spriteFrameByName(name);
		temp.pushBack(sf);
	}
	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.1f), Constant::getEnemySoldierMove());

	//ArrowEnemy Attack
	temp.clear();
	for (int i = 9; i < 16; i++){
		sprintf(name, "ArrowEnemy_%d.png", i + 1);
		SpriteFrame* sf = cache->spriteFrameByName(name);
		temp.pushBack(sf);
	}
	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.2f), Constant::getEnemyArrowEnemyAttack());

	//Goblin Death
	temp.clear();
	for (int i = 10; i < 14; i++){
		sprintf(name, "Goblin_%d.png", i + 1);
		SpriteFrame* sf = cache->getSpriteFrameByName(name);
		temp.pushBack(sf);
	}
	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.5f), Constant::getEnemyGoblinDeath());

	//Sheep Death
	temp.clear();
	for (int i = 13; i < 22; i++){
		sprintf(name, "Sheep_%d.png", i);
		SpriteFrame* sf = cache->getSpriteFrameByName(name);
		temp.pushBack(sf);
	}
	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.5f), Constant::getEnemySheepDeath());


	//Soldier Death
	temp.clear();
	for (int i = 17; i < 23; i++){
		sprintf(name, "Soldier_%d.png", i + 1);
		SpriteFrame* sf = cache->getSpriteFrameByName(name);
		temp.pushBack(sf);
	}
	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.5f), Constant::getEnemySoldierDeath());

	//ArrowEnemy Death
	temp.clear();
	for (int i = 17; i < 21; i++){
		sprintf(name, "ArrowEnemy_%d.png", i + 1);
		SpriteFrame* sf = cache->getSpriteFrameByName(name);
		temp.pushBack(sf);
	}
	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.5f), Constant::getEnemyArrowEnemyDeath());

	//Boss Normal
	temp.clear();
	for (int i = 17; i < 23; i++){
		sprintf(name, "Boss_%d.png", i);
		SpriteFrame* sf = cache->getSpriteFrameByName(name);
		temp.pushBack(sf);
	}
	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.2f), Constant::getEnemyBossNormal());


	//Boss Attack
	temp.clear();
	for (int i = 1; i < 17; i++){
		sprintf(name, "Boss_%d.png", i);
		SpriteFrame* sf = cache->getSpriteFrameByName(name);
		temp.pushBack(sf);
	}
	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.1f), Constant::getEnemyBossAttack());

	//Boss Call

	temp.clear();
	for (int i = 23; i < 58; i++){
		sprintf(name, "Boss_%d.png", i);
		SpriteFrame* sf = cache->getSpriteFrameByName(name);
		temp.pushBack(sf);
	}
	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.1f), Constant::getEnemyBossCall());

	//BossAttack Real
	temp.clear();
	for (int i = 1; i < 20; i++){
		sprintf(name, "BossAttack_%d.png", i);
		SpriteFrame* sf = cache->getSpriteFrameByName(name);
		temp.pushBack(sf);
	}
	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.1f), Constant::getEnemyBossAttackReal());

	//BossAttack Call
	temp.clear();
	for (int i = 32; i < 37; i++){
		sprintf(name, "BossAttack_%d.png", i);
		SpriteFrame* sf = cache->getSpriteFrameByName(name);
		temp.pushBack(sf);
	}
	animationCache->addAnimation(Animation::createWithSpriteFrames(temp, 0.1f), Constant::getEnemyBossAttackCall());

	
}
Scene* BattleArena::createScene()
{
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // some upfront items that we need
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Director* dirs = Director::getInstance();
    Size visibleSize = dirs->getVisibleSize();
    Vec2 origin = dirs->getVisibleOrigin();
    
    Size playingSize = Size(visibleSize.width, visibleSize.height - (visibleSize.height/8)); // actual playing size to work with

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // create a scene
    // 'scene' is an autorelease object
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Scene* scene = Scene::create();
    
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // create a node to hold non-sprites.
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Node* nodeItems = Node::create();
    nodeItems->setName("nodeItems");
    
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // create a node to hold menu
    // create a menu
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Node* menuNode = Node::create();
    menuNode->setName("menuNode");
    int index = 2;

	
    MenuItemFont* menuItem3 = MenuItemFont::create("Summon Pikachu");
    menuItem3->setFontNameObj("fonts/Marker Felt.ttf");
    menuItem3->setFontSizeObj(32);
    menuItem3->setName("summon_pikachu");
    menuItem3->setVisible(true);
    menuItem3->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2).x,
                           (Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height).y - (index) * 40));
    menuItem3->setCallback([&](cocos2d::Ref *sender) {
		Director* dirs = Director::getInstance();
		Scene* runningScene = dirs->getRunningScene();
		SpriteFrameCache* spritecache = SpriteFrameCache::getInstance();

        spritecache->addSpriteFramesWithFile("learning/PIKACHU.plist");
		
		Sprite* newSprite = Sprite::createWithSpriteFrameName("0.gif");
		int xRandom = random(0, int(dirs->getVisibleSize().width));
		int yRandom = random(246, 266);
        newSprite->setPosition(xRandom, yRandom);
        newSprite->setName("sprite3");
        newSprite->setAnchorPoint(Vec2(0.5,0.5));
        runningScene->addChild(newSprite,1);

		Vector<SpriteFrame*> animFrames;
		int frames = 112;
		animFrames.reserve(frames);

		char gif[8] = {0};
		for(int index_frames = 0 ; index_frames < frames ; index_frames++){
			sprintf(gif, "%d.gif", index_frames);
			animFrames.pushBack(spritecache->getSpriteFrameByName(gif));
		}
        
        // create the animation out of the frames
        Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.05f);
        Animate* animate = Animate::create(animation);
        
        // run it and repeat it forever
        newSprite->runAction(RepeatForever::create(animate));
    });

	Menu* menu = Menu::create(menuItem3, NULL);
    menu->setName("menu");
    menuNode->addChild(menu, 1);
    menu->setPosition(Vec2::ZERO);
    
    scene->addChild(menuNode, 2);
    
    // return the scene
    return scene;
}