コード例 #1
0
ファイル: Player.cpp プロジェクト: wayonglee/LoliRun
void Player::addAnimate()
{
	Vector<SpriteFrame*> pFrames;
	for(int i=0;i<6;i++)
	{
		const char* frameName = String::createWithFormat("s_%d.png",i+1)->getCString();
		SpriteFrame* pFrame = SpriteFrame::create(frameName,Rect(0,0,200,250));
		pFrames.pushBack(pFrame);
	}
	auto walkAnimation = Animation::createWithSpriteFrames(pFrames, 0.05);
	auto walkAnimate = Animate::create(walkAnimation);
	setWalkAction(RepeatForever::create(walkAnimate));

	pFrames.clear();
	pFrames.pushBack(SpriteFrame::create("s_jump.png",Rect(0,0,200,250)));

	auto jumpAnimation = Animation::createWithSpriteFrames(pFrames,0.1);
	auto jumpAnimate = Animate::create(jumpAnimation);
	setJumpAction(RepeatForever::create(jumpAnimate));

	pFrames.clear();
	pFrames.pushBack(SpriteFrame::create("s_hurt.png", Rect(0, 0, 200, 250)));

	auto hurtAnimation = Animation::createWithSpriteFrames(pFrames, 0.1);
	auto hurtAnimate = Animate::create(hurtAnimation);
	setHurtAction(RepeatForever::create(hurtAnimate));
}
コード例 #2
0
ファイル: Role.cpp プロジェクト: huakaitingqian/MHE_new
bool Role1::init()
{
	do 
	{

		CC_BREAK_IF(!Person::initWithSpriteFrameName("Role1Normal1.png"));

		CallFunc *callbackNormal = CallFunc::create(std::bind(&Role1::normalAction, this));

		Size visibleSize = Director::getInstance()->getVisibleSize();
		Vec2 origin = Director::getInstance()->getVisibleOrigin();

		//Õý³£×´Ì¬Ï¶¯»­
		const char* normalPng = String::createWithFormat("%s%s", roleName, "Normal")->getCString();
		Animation* normalAnimation = createAnimation(normalPng,6,12);
		setNormalAction(RepeatForever::create(Animate::create(normalAnimation)));

		//Òƶ¯×´Ì¬ÏÂ
		//const char* movePng = String::createWithFormat(roleName,"Move")->getCString();
		//Animation* moveAnimation = createAnimation(movePng,6,12);
		setMoveAction(RepeatForever::create(Animate::create(normalAnimation)));

		//¹¥»÷״̬϶¯»­
		const char* firePng = String::createWithFormat("%s%s", roleName, "Fire")->getCString();
		Animation* fireAnimation = createAnimation(firePng,2,10);
		setFireAction(Sequence::create(Animate::create(fireAnimation), callbackNormal, NULL));

		//Êܵ½¹¥»÷״̬϶¯»­
		const char* attackedPng = String::createWithFormat("%s%s", roleName, "Attacked")->getCString();
		Animation* attackedAnimation = createAnimation(attackedPng,3,12);
		setAttackedAction(Sequence::create(Animate::create(attackedAnimation), callbackNormal, NULL));

		//ÌøԾ״̬϶¯»­
		auto actionBy = JumpBy::create(2, Vec2(0,0), visibleSize.height/4, 1);
		//auto actionByBack = actionBy->reverse();
		setJumpAction(Sequence::create(actionBy, callbackNormal, NULL));

		return true;
	}while(0);

	return false;
}
コード例 #3
0
ファイル: NPC.cpp プロジェクト: huakaitingqian/MHE_new
bool NPC1::init()
{
	do 
	{
		CC_BREAK_IF(!Person::initWithSpriteFrameName("Role2Normal1.png"));

		CallFunc *callbackNormal = CallFunc::create(std::bind(&NPC1::normalAction, this));
		CallFunc *callbackJumpEnd = CallFunc::create(std::bind(&NPC1::jumpActionEnd, this));

		Size visibleSize = Director::getInstance()->getVisibleSize();
		Vec2 origin = Director::getInstance()->getVisibleOrigin();

		//Õý³£×´Ì¬Ï¶¯»­
		const char* normalPng = String::createWithFormat("%s%s", roleName, "Normal")->getCString();
		Animation* normalAnimation = createAnimation(normalPng,6,12);
		setNormalAction(RepeatForever::create(Animate::create(normalAnimation)));

		//Òƶ¯×´Ì¬ÏÂ
		//const char* movePng = String::createWithFormat(roleName,"Move")->getCString();
		//Animation* moveAnimation = createAnimation(movePng,6,12);
		setMoveAction(RepeatForever::create(Animate::create(normalAnimation)));

		//¹¥»÷״̬϶¯»­
		const char* firePng = String::createWithFormat("%s%s", roleName, "Fire")->getCString();
		Animation* fireAnimation = createAnimation(firePng,2,10);
		setFireAction(Sequence::create(Animate::create(fireAnimation), callbackNormal, NULL));

		//Êܵ½¹¥»÷״̬϶¯»­
		const char* attackedPng = String::createWithFormat("%s%s", roleName, "Attacked")->getCString();
		Animation* attackedAnimation = createAnimation(attackedPng,3,12);
		setAttackedAction(Sequence::create(Animate::create(attackedAnimation), callbackNormal, NULL));

		//±»¶³×¡×´Ì¬ÏÂ
		const char* frozenPng = String::createWithFormat("%s%s", roleName, "Frozen")->getCString();
		Animation* frozenAnimation = createAnimation(frozenPng,2,10);
		setFrozenAction(Sequence::create(Animate::create(frozenAnimation), DelayTime::create(5), callbackNormal, NULL));

		//±»ºÚ¶´À§×¡×´Ì¬ÏÂ
		const char* holePng = String::createWithFormat("%s%s", roleName, "Hole")->getCString();
		Animation* holeAnimation = createAnimation(holePng,2,10);
		setHoleAction(Sequence::create(Animate::create(holeAnimation), DelayTime::create(5), callbackNormal, NULL));

		//±»Íøס״̬ÏÂ
		const char* netPng = String::createWithFormat("%s%s", roleName, "Net")->getCString();
		Animation* netAnimation = createAnimation(netPng,2,10);
		setNetAction(Sequence::create(Animate::create(netAnimation), DelayTime::create(5), callbackNormal, NULL));

		//ÌøԾ״̬϶¯»­
		auto actionBy = JumpBy::create(1, Vec2(0,0), visibleSize.height/4, 1);
		//auto actionByBack = actionBy->reverse();
		setJumpAction(Sequence::create(actionBy, callbackJumpEnd, NULL));

		//ʤÀû״̬ÏÂ
		const char* victoryPng = String::createWithFormat("%s%s", roleName, "Victory")->getCString();
		Animation* victoryAnimation = createAnimation(victoryPng,2,10);
		setVictoryAction(Sequence::create(Animate::create(victoryAnimation), DelayTime::create(5), NULL));

		//ʧ°Ü״̬ÏÂ
		const char* failPng = String::createWithFormat("%s%s", roleName, "Failure")->getCString();
		Animation* failAnimation = createAnimation(failPng,2,10);
		setFailAction(Sequence::create(Animate::create(failAnimation), DelayTime::create(5), NULL));

		setTotalHP(100);
		setTotalSP(100);

		setHP(100);
		setSP(0);

		return true;
	}while(0);

	return false;
}