본문 바로가기

카테고리 없음

[cocos2d-x]응용액션 (반복액션)

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "HelloWorldScene.h"
 
Scene* HelloWorld::createScene()
{
    auto scene = Scene::create();
 
    auto layer = HelloWorld::create();
    scene->addChild(layer);
 
    return scene;
}
 
bool HelloWorld::init()
{
    if (!Layer::init())
    {
        return false;
    }
 
    auto spr = Sprite::create("ball.png");
    spr->setPosition(Point(100100));
    this->addChild(spr);
 
    auto action_0 = MoveBy::create(1.0, Point(200100));
//(100,100)위치에 있던 스프라이트를 (200,100)으로 이동시킵니다.
    auto action_1 = action_0->reverse();
//리버스 액션을 통해 되돌아 갑니다.
    auto action_2 = Sequence::create(action_0, action_1, NULL);
    auto action_3 = Repeat::create(action_2, 5);
//위 액션을 5번 반복합니다 숫자를 입력하지 않을 경우 무한반복!
    spr->runAction(action_3);
 
    return true;
}
cs