Beispiel #1
0
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);

}
Beispiel #2
0
FiniteTimeAction* KSAnimation::moveFromRightToCenter(float time)
{
    ccBezierConfig bezier;
    bezier.controlPoint_1 = ccp(CONTROL_POINT_X4, CONTROL_POINT_Y2);
    bezier.controlPoint_2 = ccp(CONTROL_POINT_X3, CONTROL_POINT_Y2);
    bezier.endPosition = BOX_LOC_CENTER;
    
    FiniteTimeAction* action = BezierTo::create(time, bezier);
    action->setTag(TAG_ACTION);
    
    return action;
}
Beispiel #3
0
FiniteTimeAction* KSAnimation::moveFromLeftToRight(float time)
{
    ccBezierConfig bezier;
    bezier.controlPoint_1 = ccp(CONTROL_POINT_X1, CONTROL_POINT_Y1);
    bezier.controlPoint_2 = ccp(CONTROL_POINT_X4, CONTROL_POINT_Y1);
    bezier.endPosition = BOX_LOC_RIGHT;
    
    FiniteTimeAction* action = BezierTo::create(time, bezier);
    action->setTag(TAG_ACTION);
    
    return action;
}