액션 반복하기 (Repeat)



c++)

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
32
33
34
35
36
37
38
39
40
#include "test134.hpp"
 
USING_NS_CC;
 
Scene* Test134::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test134::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test134::init()
{
    if ( !Layer::init())
    {
        return false;
    }
    
    
    auto sprite = Sprite::create("ball.png");
    sprite->setPosition(Point(100,100));
    this->addChild(sprite);
    
    
    auto action1 = MoveBy::create(1.0, Point(200,100));
    auto action2 = action1->reverse();
    auto sequenceAction = Sequence::create(action1, action2, NULL);
    //Repeat::create(반복할 액션, 반복 횟수) : 반복 횟수만큼 같은 액션을 반복한다
    //ps. 반복 횟수를 지정하지 않으면 무한반복 한다
    auto repeat = Repeat::create(sequenceAction, 5);
    sprite->runAction(repeat);
    
    
    return true;
}
 
cs



결과

(300,200)과 (100,100) 사이를 왔다갔다하는 액션을 5번 반복한다




+ Recent posts