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);

}
SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::addNewSpriteWithCoords(const Point& p)
{
    int idx = CCRANDOM_0_1() * 1400 / 100;
	int x = (idx%5) * 85;
	int y = (idx/5) * 121;
    
    auto sprite = SpriteRenderTextureBug::SimpleSprite::create("Images/grossini_dance_atlas.png",
                                                                                                Rect(x,y,85,121));
    addChild(sprite);
    
    sprite->setPosition(p);
    
	FiniteTimeAction *action = NULL;
	float rd = CCRANDOM_0_1();
    
	if (rd < 0.20)
        action = ScaleBy::create(3, 2);
	else if (rd < 0.40)
		action = RotateBy::create(3, 360);
	else if (rd < 0.60)
		action = Blink::create(1, 3);
	else if (rd < 0.8 )
		action = TintBy::create(2, 0, -255, -255);
	else
		action = FadeOut::create(2);
    
    auto action_back = action->reverse();
    auto seq = Sequence::create(action, action_back, NULL);
    
    sprite->runAction(RepeatForever::create(seq));
    
    //return sprite;
    return NULL;
}
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;
}
Beispiel #4
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;
}
RenderTexturePartTest::RenderTexturePartTest()
{
    auto sprite1 = Sprite::create("Images/grossini.png");
    auto sprite11 = Sprite::create("Images/grossini.png");
    auto sprite2 = Sprite::create("Images/grossinis_sister1.png");
    auto sprite22 = Sprite::create("Images/grossinis_sister1.png");
    Size size = Director::getInstance()->getWinSize();
    Size sprite1Size = sprite1->getContentSize();
    sprite1->setPosition((size.width-sprite1Size.width)/2 - 20, (size.height - sprite1Size.height)/2 - 20);
    sprite11->setPosition(size.width/2 + 20, (size.height - sprite1Size.height)/2 - 20);
    
    sprite2->setPosition((size.width-sprite1Size.width)/2 - 20, size.height/2 + 20);
    sprite22->setPosition(size.width/2 + 20, size.height/2 + 20);
    
    addChild(sprite1);
    addChild(sprite11);
    addChild(sprite2);
    addChild(sprite22);
    
    _rend = RenderTexture::create(200, 200, Texture2D::PixelFormat::RGBA8888);
    _rend->retain();
    _rend->setKeepMatrix(true);
    Size pixelSize = Director::getInstance()->getWinSizeInPixels();
    _rend->setVirtualViewport(Point(size.width/2-150, size.height/2-150),Rect(0,0,size.width,size.height),Rect(0,0,pixelSize.width,pixelSize.height));
    
    _rend->beginWithClear(1, 0, 0, 1);
    sprite1->visit();
    sprite11->visit();
    sprite2->visit();
    sprite22->visit();
    _rend->end();
    
    _spriteDraw = Sprite::createWithTexture(_rend->getSprite()->getTexture());
    FiniteTimeAction* baseAction = MoveBy::create(1, Point(size.width,0));
    _spriteDraw->setPosition(0,size.height/2);
    _spriteDraw->setScaleY(-1);
    _spriteDraw->runAction(RepeatForever::create(Sequence::create
                                          (baseAction,baseAction->reverse(), NULL)));
    addChild(_spriteDraw);
}