Exemplo n.º 1
0
void NewSpriteBatchTest::addNewSpriteWithCoords(Vec2 p)
{
    auto BatchNode = static_cast<SpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );

    int idx = (int) (CCRANDOM_0_1() * 1400 / 100);
    int x = (idx%5) * 85;
    int y = (idx/5) * 121;


    auto sprite = Sprite::createWithTexture(BatchNode->getTexture(), Rect(x,y,85,121));
    BatchNode->addChild(sprite);

    sprite->setPosition( Vec2( p.x, p.y) );

    ActionInterval* action;
    float random = CCRANDOM_0_1();

    if( random < 0.20 )
        action = ScaleBy::create(3, 2);
    else if(random < 0.40)
        action = RotateBy::create(3, 360);
    else if( random < 0.60)
        action = Blink::create(1, 3);
    else if( random < 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, nullptr);

    sprite->runAction( RepeatForever::create(seq));
}
Exemplo n.º 2
0
void ParticleComponentTest::defaultPlay()
{
	ComRender* Particle = static_cast<ComRender*>(_rootNode->getChildByTag(10020)->getComponent("CCParticleSystemQuad"));
	ActionInterval*  jump = CCJumpBy::create(5, Point(-500,0), 50, 4);
	FiniteTimeAction*  action = CCSequence::create( jump, jump->reverse(), nullptr);
	Particle->getNode()->runAction(action);
}
Exemplo n.º 3
0
void TransitionRotoZoom:: onEnter()
{
    TransitionScene::onEnter();

    _inScene->setScale(0.001f);
    _outScene->setScale(1.0f);

    _inScene->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
    _outScene->setAnchorPoint(Vec2::ANCHOR_MIDDLE);

    ActionInterval *rotozoom = (ActionInterval*)(Sequence::create
    (
        Spawn::create
        (
            ScaleBy::create(_duration/2, 0.001f),
            RotateBy::create(_duration/2, 360 * 2),
            nullptr
        ),
        DelayTime::create(_duration/2),
        nullptr
    ));

    _outScene->runAction(rotozoom);
    _inScene->runAction
    (
        Sequence::create
        (
            rotozoom->reverse(),
            CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
            nullptr
        )
    );
}
Exemplo n.º 4
0
void TransitionSplitCols::onEnter()
{
    TransitionScene::onEnter();

    _gridProxy->setTarget(_outScene);
    _gridProxy->onEnter();

    ActionInterval* split = action();
    ActionInterval* seq = (ActionInterval*)Sequence::create
    (
        split,
        CallFunc::create(CC_CALLBACK_0(TransitionSplitCols::switchTargetToInscene,this)),
        split->reverse(),
        nullptr
    );

    _gridProxy->runAction
    (
        Sequence::create
        (
            easeActionWithAction(seq),
            CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
            StopGrid::create(),
            nullptr
        )
    );
}
Exemplo n.º 5
0
ActionOrbit::ActionOrbit()
: ActionBase("ActionOrbit", NULL)
{
    ActionInterval * orbit1 = new OrbitCamera(2, 1, 0, 0, 180, 0, 0);
	ActionInterval * action1 = new Sequence(orbit1, orbit1->reverse(), NULL);
    
    ActionInterval * orbit2 = new OrbitCamera(2, 1, 0, 0, 180, -45, 0);
	ActionInterval * action2 = new Sequence(orbit2, orbit2->reverse(), NULL);

	ActionInterval * orbit3 = new OrbitCamera(2, 1, 0, 0, 180, 90, 0);
	ActionInterval * action3 = new Sequence(orbit3, orbit3->reverse(), NULL);


    kathia->runAction(new RepeatForever(action1));
    tamara->runAction(new RepeatForever(action2));
    grossini->runAction(new RepeatForever(action3));
    
    
	ActionInterval * move = new MoveBy(3, fzPoint(100, -100));;
	ActionInterval * move_back = move->reverse();
	ActionInterval * seq = new Sequence(move, move_back, NULL);
	Action * rfe = new RepeatForever(seq);
    
    kathia->runAction(rfe);
    tamara->runAction(rfe->copy());
    grossini->runAction(rfe->copy());
}
Exemplo n.º 6
0
void UIBuildingBase::setSharkAction()
{
    ActionInterval * ac = TintBy::create(1,-100,-100,-100);
    ActionInterval * acback = ac->reverse();
    ActionInterval * final = RepeatForever::create(Sequence::create(ac,acback,NULL));
    setSharkAction(final);
}
Exemplo n.º 7
0
ActionReverseSequence2::ActionReverseSequence2()
: ActionBase("ReverseSeq 2", NULL)
{
	// Test:
	//   Sequence should work both with IntervalAction and InstantActions
    ActionInterval *move1 = new MoveBy(1, fzPoint(250, 0));
    ActionInterval *move2 = new MoveBy(1, fzPoint(0, 50));
    ActionInstant *tog1 = new ToggleVisibility();
    ActionInstant *tog2 = new ToggleVisibility();
    ActionInterval *seq = new Sequence(move1,
                                       tog1,
                                       move2,
                                       tog2,
                                       move1->reverse(), NULL);
    
    ActionInterval *action = new Repeat(new Sequence(seq, seq->reverse(), NULL), 3);

    
	// Test:
	//   Also test that the reverse of Hide is Show, and vice-versa
    kathia->runAction(action);
    
    ActionInterval *move_tamara = new MoveBy(1, fzPoint(100, 0));
    ActionInterval *move_tamara2 = new MoveBy(1, fzPoint(50, 0));
    ActionInstant *hide = new Hide();
    ActionInterval *seq_tamara = new Sequence(move_tamara,
                                              hide,
                                              move_tamara2, NULL);
    
    ActionInterval *action_tamara = new Sequence(seq_tamara, seq_tamara->reverse(), NULL);
    tamara->runAction(action_tamara);
}
bool RenderTextureClippingNode::init()
{
    setContentSize(RenderContentSize);
    
    m_pTopSprite = Sprite::create("res/ui/water_bottle/bottle.png");
    m_pTopSprite->retain();
    
    m_pWater = Sprite::create("res/ui/water_bottle/water.png");
    m_pWater->retain();
    
    m_pMaskSprite = Sprite::create("res/ui/water_bottle/water_mask.png");
    m_pMaskSprite->retain();
    
    m_pTopSprite->setPosition(RenderContentSize*0.5f);
    m_pWater->setPosition(RenderContentSize*0.5f);
    m_pMaskSprite->setPosition(RenderContentSize*0.5f);
    
    Size s = Director::getInstance()->getWinSize();
    m_pTarget = RenderTexture::create(RenderContentSize.width, RenderContentSize.height);
    this->addChild(m_pTarget);
    
    BlendFunc maskBlend = {GL_ONE, GL_ZERO};
    BlendFunc waterBlend = {GL_DST_ALPHA, GL_ZERO};
    m_pMaskSprite->setBlendFunc(maskBlend);
    m_pWater->setBlendFunc(waterBlend);
    
    ActionInterval* pMoveAction = MoveBy::create(0.4f, Vec2(8.0f,0.0f));
    ActionInterval* pRepeatAction = Sequence::create(pMoveAction, pMoveAction->reverse(), NULL);
    m_pWater->runAction(RepeatForever::create(pRepeatAction));
    
    return true;
}
Exemplo n.º 9
0
ActionReverse::ActionReverse()
: ActionBase("Reverse", NULL)
{
    ActionInterval *jump = new JumpBy(2, fzPoint(300, 0), 50, 4);
    ActionInterval *action = new Sequence(jump, jump->reverse(), NULL);
    
    grossini->runAction(action);
}
Exemplo n.º 10
0
ActionScale::ActionScale()
: ActionBase("Scale", NULL)
{
    ActionInterval *actionTo = new ScaleTo(2, 0.5f);
    ActionInterval *actionBy = new ScaleBy(2, 1, 10);
    ActionInterval *actionBy2 = new ScaleBy(2, 5, 1);
    
    tamara->runAction(new Sequence(actionBy, actionBy->reverse(), NULL));
    grossini->runAction(actionTo);
    kathia->runAction(new Sequence(actionBy2, actionBy2->reverse(), NULL));
}
Exemplo n.º 11
0
ActionMove::ActionMove()
: ActionBase("Move", NULL)
{
	ActionInterval* actionTo = new MoveTo(2, fzPoint(getContentSize()-fzPoint(40, 40)));
	ActionInterval* actionBy = new MoveBy(2, fzPoint(80,80));
	ActionInterval* actionByBack = actionBy->reverse();
    
    tamara->runAction(actionTo);
    grossini->runAction(new Sequence(actionBy, actionByBack, NULL));
    kathia->runAction(new MoveTo(1, fzPoint(40, 40)));
}
Exemplo n.º 12
0
ActionJump::ActionJump()
: ActionBase("Jump", NULL)
{
    ActionInterval *actionTo = new JumpTo(2, fzPoint(300, 300), 50, 4);
    ActionInterval *actionBy = new JumpBy(2, fzPoint(300, 0), 50, 4);
    ActionInterval *actionUp = new JumpBy(2, fzPoint(0, 0), 80, 4);
    ActionInterval *actionByBack = actionBy->reverse();

    
    tamara->runAction(actionTo);
    grossini->runAction(new Sequence(actionBy, actionByBack, NULL));
    kathia->runAction(new RepeatForever(actionUp));
}
Exemplo n.º 13
0
ActionSkew::ActionSkew()
: ActionBase("Action Skew", NULL)
{
    ActionInterval *actionTo = new SkewTo(2, 37.2f, -37.2f);
    ActionInterval *actionToBack = new SkewTo(2, 0, 0);
    ActionInterval *actionBy = new SkewBy(2, 0, -90);
    ActionInterval *actionBy2 = new SkewBy(2, 45, 45);
    ActionInterval *actionByBack = actionBy->reverse();
    
    
    tamara->runAction(new Sequence(actionTo, actionToBack, NULL));
    grossini->runAction(new Sequence(actionBy, actionByBack, NULL));
    kathia->runAction(new Sequence(actionBy2, actionBy2->reverse(), NULL));
}
Exemplo n.º 14
0
ActionReverseSequence::ActionReverseSequence()
: ActionBase("ReverseSeq", NULL)
{
    ActionInterval *move1 = new MoveBy(1, fzPoint(250, 0));
    ActionInterval *move2 = new MoveBy(1, fzPoint(0, 50));
    ActionInterval *seq = new Sequence(move1,
                                       move2, 
                                       move1->reverse(), NULL);
    
    ActionInterval *action = new Sequence(seq,
                                          seq->reverse(), NULL);

	grossini->runAction(action);
}
Exemplo n.º 15
0
cocos2d::Node* ParticleComponentTest::createGameScene()
{
    Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/ParticleComponentTest/ParticleComponentTest.json");
	if (node == nullptr)
	{
		return nullptr;
	}

	ComRender* Particle = static_cast<ComRender*>(node->getChildByTag(10020)->getComponent("CCParticleSystemQuad"));
	ActionInterval*  jump = JumpBy::create(5, Point(-500,0), 50, 4);
	FiniteTimeAction*  action = Sequence::create( jump, jump->reverse(), nullptr);
	Particle->getNode()->runAction(action);
    return node;
}
Exemplo n.º 16
0
ActionRotate::ActionRotate()
: ActionBase("Rotate", NULL)
{
    ActionInterval *actionTo = new RotateTo(2, 45);
    ActionInterval *actionTo2 = new RotateTo(2, -45);
    ActionInterval *actionTo0 = new RotateTo(2, 0);
    
    ActionInterval *actionBy = new RotateBy(2, 360);
    ActionInterval *actionByBack = actionBy->reverse();
    
    tamara->runAction(new Sequence(actionTo, actionTo0, NULL));
    grossini->runAction(new Sequence(actionBy, actionByBack, NULL));
    kathia->runAction(new Sequence(actionTo2, actionTo0->copy(), NULL));
}
////////////////////////////////////////////////////////
//
// For test functions
//
////////////////////////////////////////////////////////
void performanceActions(Sprite* pSprite)
{
    Size size = Director::sharedDirector()->getWinSize();
    pSprite->setPosition(ccp((rand() % (int)size.width), (rand() % (int)size.height)));

    float period = 0.5f + (rand() % 1000) / 500.0f;
    RotateBy* rot = RotateBy::create(period, 360.0f * CCRANDOM_0_1());
    ActionInterval* rot_back = rot->reverse();
    Action *permanentRotation = RepeatForever::create(Sequence::create(rot, rot_back, NULL));
    pSprite->runAction(permanentRotation);

    float growDuration = 0.5f + (rand() % 1000) / 500.0f;
    ActionInterval *grow = ScaleBy::create(growDuration, 0.5f, 0.5f);
    Action *permanentScaleLoop = RepeatForever::create(Sequence::create(grow, grow->reverse(), NULL));
    pSprite->runAction(permanentScaleLoop);
}
Exemplo n.º 18
0
void EnemyFlower::launchEnemy()
{
	enemyBody->runAction(RepeatForever::create(AnimationManager::getInstance()->createAnimate(eAniflower)));
	Point pos = this->getPosition();	
	pos.y -= bodySize.height;
	startPos = pos;
	this->runAction(Place::create(pos));

	ActionInterval *pMoveBy = MoveBy::create(1.0f, Point(0.0f, bodySize.height));
	ActionInterval *pDelay = DelayTime::create(1.0f);
	ActionInterval *pMoveByBack = pMoveBy->reverse();
	ActionInterval *pDelay2 = DelayTime::create(2.0f);
	this->runAction(RepeatForever::create(
		(ActionInterval*)Sequence::create(pMoveBy, pDelay, pMoveByBack, pDelay2, NULL)));

	this->scheduleUpdate();
}
Exemplo n.º 19
0
bool BirdSprite::createBird(){
	this->createBirdByRandom();
	if(Sprite::initWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName(this->birdName))) {
		// init idle status
		//create the bird animation
		Animation* animation = this->createAnimation(this->birdNameFormat.c_str(), 3, 10);
		Animate* animate = Animate::create(animation);
		this->idleAction = RepeatForever::create(animate);

		// create the swing action
		ActionInterval *up = CCMoveBy::create(0.4f,Point(0, 8));
		ActionInterval *upBack= up->reverse();
		this->swingAction = RepeatForever::create(Sequence::create(up, upBack, NULL));
		return true;
	}else {
		return false;
	}
}
Exemplo n.º 20
0
bool BirdSprite::createBird()
{
	this->createBirdByRandom();
	if (Sprite::initWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName(this->birdName)))
	{
		Animation *pAnimation = this->createAnimation(this->birdNameFormat.c_str(), 3, 10);
		Animate *pAnimate = Animate::create(pAnimation);
		this->idleAction = RepeatForever::create(pAnimate);

		//Create the swing action
		ActionInterval *pUp = CCMoveBy::create(0.4f, Point(0, 8));
		ActionInterval *pUpBack =pUp->reverse();
		this->swingAction = RepeatForever::create(Sequence::create(pUp, pUpBack, NULL));
		return true;
	}

	return false;
}
Exemplo n.º 21
0
Sprite* BirdSprite::createBird()
{
	this->createBirdByRandom();
	Sprite *birdSprite = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName(this->birdName));
	if (birdSprite)
	{
		Animation *animation = this->createAnimation(this->birdNameFormat.c_str(), 3, 10);
		Animate *animate = Animate::create(animation);
		this->idleAction = RepeatForever::create(animate);

		ActionInterval *up = MoveBy::create(0.4f, Point(0, 8));
		ActionInterval *upBack = up->reverse();
		this->swingAction = RepeatForever::create(Sequence::create(up, upBack, NULL));
		return birdSprite;
	}
	else {
		return NULL;
	}
}
Exemplo n.º 22
0
void TSkewBy::done()
{
	do 
	{
		Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
		CC_BREAK_IF(node == nullptr);
		ActionInterval*  actionBy = SkewBy::create(_duration, _skew.x, _skew.y);
		CC_BREAK_IF(actionBy == nullptr);
		if (_reverse == true)
		{
			ActionInterval*  actionByBack = actionBy->reverse();
			node->runAction(Sequence::create(actionBy, actionByBack, nullptr));
		}
		else
		{
			node->runAction(actionBy);
		}
	} while (0);
}
Exemplo n.º 23
0
void ScenarioTest::addNewSprites(int num)
{
    auto s = Director::getInstance()->getVisibleSize();
    auto origin = Director::getInstance()->getVisibleOrigin();

    for (int i = 0; i < num; ++i) {
        int idx = (int)(CCRANDOM_0_1() * 1400.0f / 100.0f);
        int x = (idx%5) * 85;
        int y = (idx/5) * 121;

        auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(x,y,85,121) );
        addChild( sprite );
        
        float randomx = CCRANDOM_0_1();
        float randomy = CCRANDOM_0_1();
        sprite->setPosition(origin + Vec2(randomx * s.width, randomy * s.height));
        
        ActionInterval* action;
        float random = CCRANDOM_0_1();
        
        if( random < 0.20 )
            action = ScaleBy::create(3, 2);
        else if(random < 0.40)
            action = RotateBy::create(3, 360);
        else if( random < 0.60)
            action = Blink::create(1, 3);
        else if( random < 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, nullptr );
        
        sprite->runAction( RepeatForever::create(seq) );

        _spriteArray.pushBack(sprite);
    }

    char str[20] = {0};
    sprintf(str, "Sprites : %d", (int)_spriteArray.size());
    _spriteLabel->setString(str);
}
Exemplo n.º 24
0
void LoadingLayer::initProgress()
{
	Size ws = Director::getInstance()->getWinSize();
	//m_loadProgress = Label::create("0%","",50);
	//m_loadProgress->setPosition(ws.width*0.5, ws.height*0.3);
	//addChild(m_loadProgress,1);

	auto load = Sprite::create("loadRes/imgLoading.png");
	load->setPosition(ws.width*0.5, ws.height*0.25);
	addChild(load);

	Sprite* barBg = Sprite::create("loadRes/imgProgressBg.png");
	barBg->setPosition(ws.width*0.5, ws.height*0.3);
	addChild(barBg);

	Sprite* sp = Sprite::create("loadRes/imgProgress.png");
	m_BloodBar = ProgressTimer::create(sp);
	m_BloodBar->setType(kCCProgressTimerTypeBar);  
	m_BloodBar->setBarChangeRate(Vec2(1,0));
	m_BloodBar->setPercentage(20);
	m_BloodBar->setMidpoint(ccp(0,0.5));
	m_BloodBar->setPosition(ccp(barBg->getContentSize().width*0.5,barBg->getContentSize().height*0.5));
	barBg->addChild(m_BloodBar);
	barBg->setScaleY(0.9);

	m_CurProgress = Sprite::create("loadRes/imgCurPr.png");
	m_CurProgress->setPosition(ccp(20,barBg->getContentSize().height*0.45));
	barBg->addChild(m_CurProgress);

	auto parcile = ParticleSystemQuad::create("particla/LoadBar/LoadBar.plist");
	parcile->setPosition( Vec2(9,15) );
	m_CurProgress->addChild( parcile );

	ActionInterval* tint = TintBy::create(0.3f,0,0,-255);
	ActionInterval* ease = EaseCircleActionInOut::create(tint);
	ActionInterval* back = ease->reverse();
	ActionInterval* seq = Sequence::create(tint, back, nullptr);
	ActionInterval* rep = RepeatForever::create(seq);
	//m_BloodBar->runAction(rep);

}
void MotionStreakTest1::onEnter()
{
    MotionStreakTest::onEnter();

    Size s = Director::getInstance()->getWinSize();
  
    // the root object just rotates around
    _root = Sprite::create(s_pathR1);
    addChild(_root, 1);
    _root->setPosition(Point(s.width/2, s.height/2));
  
    // the target object is offset from root, and the streak is moved to follow it
    _target = Sprite::create(s_pathR1);
    _root->addChild(_target);
    _target->setPosition(Point(s.width/4, 0));

    // create the streak object and add it to the scene
    streak = MotionStreak::create(2, 3, 32, Color3B::GREEN, s_streak);
    addChild(streak);
    // schedule an update on each frame so we can syncronize the streak with the target
    schedule(schedule_selector(MotionStreakTest1::onUpdate));
  
    ActionInterval* a1 = RotateBy::create(2, 360);

    Action* action1 = RepeatForever::create(a1);
    ActionInterval* motion = MoveBy::create(2, Point(100,0) );
    _root->runAction( RepeatForever::create(Sequence::create(motion, motion->reverse(), NULL) ) );
    _root->runAction( action1 );

    ActionInterval *colorAction = RepeatForever::create(Sequence::create(
        TintTo::create(0.2f, 255, 0, 0),
        TintTo::create(0.2f, 0, 255, 0),
        TintTo::create(0.2f, 0, 0, 255),
        TintTo::create(0.2f, 0, 255, 255),
        TintTo::create(0.2f, 255, 255, 0),
        TintTo::create(0.2f, 255, 0, 255),
        TintTo::create(0.2f, 255, 255, 255),
        NULL));

    streak->runAction(colorAction);
}
Exemplo n.º 26
0
void Sprite3DBasicTest::addNewSpriteWithCoords(Vec2 p)
{
    //int idx = (int)(CCRANDOM_0_1() * 1400.0f / 100.0f);
    //int x = (idx%5) * 85;
    //int y = (idx/5) * 121;
    
//    //option 1: load a obj that contain the texture in it
//    auto sprite = Sprite3D::create("sprite3dTest/scene01.obj");
    
    //option 2: load obj and assign the texture
    auto sprite = Sprite3D::create("Sprite3DTest/boss1.obj");
    sprite->setScale(3.f);
    sprite->setTexture("Sprite3DTest/boss.png");
    
    //
    //sprite->setEffect(cocos2d::EFFECT_OUTLINE);
    
    //add to scene
    addChild( sprite );
    
    sprite->setPosition( Vec2( p.x, p.y) );
    
    ActionInterval* action;
    float random = CCRANDOM_0_1();
    
    if( random < 0.20 )
        action = ScaleBy::create(3, 2);
    else if(random < 0.40)
        action = RotateBy::create(3, 360);
    else if( random < 0.60)
        action = Blink::create(1, 3);
    else if( random < 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) );
}
Exemplo n.º 27
0
void Sprite3DEffectTest::addNewSpriteWithCoords(Vec2 p)
{
    //option 2: load obj and assign the texture
    auto sprite = EffectSprite3D::createFromObjFileAndTexture("Sprite3DTest/boss1.obj", "Sprite3DTest/boss.png");
    Effect3DOutline* effect = Effect3DOutline::create();
    sprite->addEffect(effect, -1);
    effect->setOutlineColor(Vec3(1,0,0));
    effect->setOutlineWidth(0.01f);
    
    Effect3DOutline* effect2 = Effect3DOutline::create();
    sprite->addEffect(effect2, -2);
    effect2->setOutlineWidth(0.02f);
    effect2->setOutlineColor(Vec3(1,1,0));
    //sprite->setEffect3D(effect);
    sprite->setScale(6.f);
    
    //add to scene
    addChild( sprite );
    
    sprite->setPosition( Vec2( p.x, p.y) );
    
    ActionInterval* action;
    float random = CCRANDOM_0_1();
    
    if( random < 0.20 )
        action = ScaleBy::create(3, 2);
    else if(random < 0.40)
        action = RotateBy::create(3, 360);
    else if( random < 0.60)
        action = Blink::create(1, 3);
    else if( random < 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, nullptr );
    
    sprite->runAction( RepeatForever::create(seq) );
}
Exemplo n.º 28
0
ActionBezier::ActionBezier()
: ActionBase("Bezier", NULL)
{

	fzSize s = Director::Instance().getCanvasSize();
    
    
	// sprite 1
	fzBezierConfig bezier;
	bezier.controlPoint_1 = fzPoint(0, s.height/2);
	bezier.controlPoint_2 = fzPoint(300, -s.height/2);
	bezier.endPosition = fzPoint(300,100);
    
	ActionInterval *bezierForward = new BezierBy(3, bezier);
    ActionInterval *bezierBack = bezierForward->reverse();
	ActionInterval *seq = new Sequence(bezierForward, bezierBack, NULL);
    Action *rep = new RepeatForever(seq);
    
    
	// sprite 2
    tamara->setPosition(80, 160);
	fzBezierConfig bezier2;
	bezier2.controlPoint_1 = fzPoint(100, s.height/2);
	bezier2.controlPoint_2 = fzPoint(200, -s.height/2);
	bezier2.endPosition = fzPoint(240,160);
    ActionInterval *bezierTo1 = new BezierTo(2, bezier2);
    
    
	// sprite 3
	kathia->setPosition(400,160);
    ActionInterval *bezierTo2 = new BezierTo(2, bezier2);
    
    
    grossini->runAction(rep);
    tamara->runAction(bezierTo1);
    kathia->runAction(bezierTo2);
}
Exemplo n.º 29
0
bool WelComeLayer::init(){

    if (!Layer::init()) {
        return false;
    }
    auto visibleSize = Director::getInstance()->getVisibleSize();
    auto origin = Director::getInstance()->getVisibleOrigin();
    
    background = ImgLoader::getInstance()->getSpriteFramesByName("deepocean_background_strip.png");
    background->setPosition(visibleSize.width/2 + origin.x,visibleSize.height/2 + origin.y);
    background->setScale(visibleSize.width/background->getContentSize().width, visibleSize.height/background->getContentSize().height);
    this->addChild(background,0);
    
    Sprite * wreckboard = ImgLoader::getInstance()->getSpriteFramesByName("deepocean_background_wreck1.png");
    wreckboard->setPosition(wreckboard->getContentSize().width/4 + visibleSize.width/2,visibleSize.height/2 + origin.y);
    wreckboard->setScale(1.5, visibleSize.height/wreckboard->getContentSize().height);
    this->addChild(wreckboard,1);
    
    shinei = ImgLoader::getInstance()->getSpriteFramesByName("mainMenuBackground.png");
    shinei->setPosition(visibleSize.width/2,visibleSize.height/2);
    shinei->setScale(visibleSize.width/shinei->getContentSize().width, visibleSize.height/shinei->getContentSize().height);
    this->addChild(shinei,3);
    
    Sprite * labellogo = ImgLoader::getInstance()->getSpriteFramesByName("submarine_logo1.png");
    labellogo->setPosition(shinei->getContentSize().width/9, visibleSize.height/2 + origin.y);
    labellogo->setScale(visibleSize.width/shinei->getContentSize().width , visibleSize.height/shinei->getContentSize().height);
    this->addChild(labellogo,2);
    
    this->sand = Sprite::createWithSpriteFrameName("deepocean_foreground_sand1.png");
    this->sand->setPosition(this->sand->getContentSize().width-10.0f,origin.y + this->sand->getContentSize().height/2);
    this->addChild(this->sand,2);
    
    Sprite * scoreboard = ImgLoader::getInstance()->getSpriteFramesByName("menu_best.png");
    scoreboard->setPosition(visibleSize.width/2-scoreboard->getContentSize().width/2,150);
    this->addChild(scoreboard,4);

    this->plane = ImgLoader::getInstance()->getSpriteFramesByName("submarine_mockup_sub.png");
    this->plane->setRotation(-10);
    ActionInterval * up = MoveBy::create(0.4f, Point(0,8));
    ActionInterval * upBack = up->reverse();
    Action *swingAction = RepeatForever::create(Sequence::create(up,upBack, NULL));
    this->plane->runAction(swingAction);
    this->plane->setPosition(Point(origin.x +this->plane->getContentSize().width/2 , origin.y + 100));
    this->addChild(this->plane,5);
    
    this->labelStart = Label::createWithTTF("click here to start", "fonts/Marker Felt.ttf", 25);
    this->labelStart->setPosition(visibleSize.width/2,visibleSize.height/2);
    ActionInterval *scale = ScaleTo::create(2, 2.5);
    ActionInterval *scaleback = ScaleTo::create(2, 1.5);
    Action * action = RepeatForever::create(Sequence::create(scale,scaleback,NULL));
    this->labelStart->runAction(action);
    this->addChild(this->labelStart,6);
    
    //this->setTouchEnabled(true);
    EventDispatcher* eventDispatcher = Director::getInstance()->getEventDispatcher();
    listener= EventListenerTouchOneByOne::create();
    //listener->setSwallowTouches(true);
    listener->onTouchBegan = CC_CALLBACK_2(WelComeLayer::CheckTouchLabelStart,this);
    eventDispatcher->addEventListenerWithSceneGraphPriority(listener,this);
    
    return true;
}
Exemplo n.º 30
0
//处理碰撞土块
void TileSprite::handleContact(MarioSprite * pMario)
{
	//无效土块判断
	if (m_eTileType == TSType_Invalid)
		return;

	Vec2 pos = getPosition();
	bool bMarioTumble = (pMario->getMarioStatus() == MarioSt_LTumble || pMario->getMarioStatus() == MarioSt_RTumble);	//是否翻跟头
	m_bFinishHandleContact = false;

	//播放碰撞音效
	if (!bMarioTumble)
	{
		if (m_eTileType == TSType_Null && pMario->getMarioLevel() > 1)
			playEffect(Effect_DestroyTile);
		else
			playEffect(Effect_JackSolid);
	}

	if (m_eTileType == TSType_Null)	//空土块
	{
		if (pMario->getMarioLevel() > 1)	//正常马里奥的碰撞
		{
			GameScene * gameScene = GameScene::getInstance();
			Sprite * broken1 = Sprite::createWithSpriteFrameName("tile/broken_tile1.png");
			broken1->setPosition(Vec2(pos.x - 10, pos.y + 10));
			broken1->setCameraMask(2);
			gameScene->addChild(broken1, 10);

			Sprite * broken2 = Sprite::createWithSpriteFrameName("tile/broken_tile2.png");
			broken2->setPosition(pos);
			broken2->setCameraMask(2);
			gameScene->addChild(broken2, 10);

			Sprite * broken3 = Sprite::createWithSpriteFrameName("tile/broken_tile3.png");
			broken3->setPosition(Vec2(pos.x + 10, pos.y - 20));
			broken3->setCameraMask(2);
			gameScene->addChild(broken3, 10);

			broken1->runAction(Sequence::create(JumpTo::create(bMarioTumble ? 0.5f : 1.0f, Vec2(pos.x - 350, -50.0f), bMarioTumble ? 150 : 300.0f, 1),
				CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, broken1)), nullptr));

			broken2->runAction(Sequence::create(JumpTo::create(bMarioTumble ? 0.5f : 1.0f, Vec2(pos.x - 50.0f, -50.0f), bMarioTumble ? 150 : 300.0f, 1),
				CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, broken2)), nullptr));

			broken3->runAction(Sequence::create(JumpTo::create(bMarioTumble ? 0.5f : 1.0f, Vec2(pos.x + 390.0f, -50.0f), bMarioTumble ? 150 : 300.0f, 1),
				CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, broken3)), nullptr));

			this->removeFromParent();
		}
		else	//缩小版马里奥的碰撞
		{
			//设置基础动作
			ActionInterval * baseAction = Spawn::create(
				MoveBy::create(0.1f, Vec2(0.0f, bMarioTumble ? -20.0f : 20.0f)),
				CCScaleBy::create(0.1f, 1.3f),
				nullptr);

			this->runAction(Sequence::create(
				baseAction, baseAction->reverse(),
				CallFunc::create(CC_CALLBACK_0(TileSprite::finishHandleContact, this)),
				nullptr));
		}
	}
	else if (m_eTileType == TSType_Coin)	//金币土块
	{
		if (m_nCoinCount <= 0)
		{
			setInvalid();
			return;
		}

		//设置基础动作
		ActionInterval * baseAction = Spawn::create(MoveBy::create(0.1f, Vec2(0.0f, bMarioTumble ? -20.0f : 20.0f)),
			CCScaleBy::create(0.1f, 1.3f), nullptr);

		//根据金币数目设置土块动作
		if (m_nCoinCount == 1)
		{
			this->runAction(Sequence::create(
				baseAction, baseAction->reverse(),
				CallFunc::create(CC_CALLBACK_0(TileSprite::setInvalid, this)),
				CallFunc::create(CC_CALLBACK_0(TileSprite::finishHandleContact, this)),
				nullptr));
		}
		else if (m_nCoinCount > 1)
		{
			this->runAction(Sequence::create(
				baseAction, baseAction->reverse(),
				CallFunc::create(CC_CALLBACK_0(TileSprite::finishHandleContact, this)),
				nullptr));
		}
		--m_nCoinCount;
		//设置金币动作
		Sprite * pCoin = Sprite::createWithSpriteFrameName("coin/coin1.png");
		Size size = getContentSize();
		pCoin->setPosition(Vec2(size.width / 2, size.height / 2));
		pCoin->setCameraMask(2);
		this->addChild(pCoin, -1);

		Animation * pAnimation = AnimationCache::getInstance()->getAnimation("fastCoin");
		pCoin->runAction(Animate::create(pAnimation));
		ActionInterval * moveAction = nullptr;
		if (bMarioTumble)
			moveAction = MoveBy::create(0.3f, Vec2(0.0f, -100.0f));
		else
			moveAction = JumpBy::create(0.7f, Vec2(0.0f, 50.0f), 100.0f, 1);
		pCoin->runAction(Sequence::create(moveAction,
			CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, pCoin)),
			CallFunc::create(CC_CALLBACK_0(TileSprite::addCoinCount, this)), nullptr));
		playEffect(Effect_GetCoin);
	}
	else if (m_eTileType == TSType_Swamm)
	{
		//设置基础动作
		ActionInterval * baseAction = Spawn::create(MoveBy::create(0.1f, Vec2(0.0f, bMarioTumble ? -20.0f : 20.0f)),
			CCScaleBy::create(0.1f, 1.3f), nullptr);

		this->runAction(Sequence::create(baseAction, baseAction->reverse(),
			CallFunc::create(CC_CALLBACK_0(TileSprite::setInvalid, this)),
			CallFunc::create(CC_CALLBACK_0(TileSprite::finishHandleContact, this)),
			CallFunc::create(CC_CALLBACK_0(TileSprite::addSwammSprite, this, bMarioTumble)), nullptr));
		playEffect(Effect_SwammShow);
	}

	if (!bMarioTumble)
	{
		//执行AABB检验,判断是否在土块上面有怪兽、是否新一轮跟头碰撞
		Size size = getContentSize();
		float fPtm = getPTMRatio();
		b2AABB aabb;
		aabb.lowerBound.Set((pos.x - size.width / 2) / fPtm, (pos.y - size.height / 2) / fPtm);
		aabb.upperBound.Set((pos.x + size.width / 2) / fPtm, (pos.y + (size.height) / 2 + 5) / fPtm);
		TileQueryCallBack tileCallBack(this);
		GameScene::getInstance()->getWorld()->QueryAABB(&tileCallBack, aabb);
	}
}