visible의 값을 반대로 바꿔주는 액션기능 (ToggleVisibility)



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
41
42
#include "test123.hpp"
 
USING_NS_CC;
 
Scene* Test123::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test123::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test123::init()
{
    if ( !Layer::init())
    {
        return false;
    }
    
    
    auto spriteShow = Sprite::create("testimage.png");
    spriteShow->setPosition(Point(100,100));
    this->addChild(spriteShow);
    
    auto spriteHide = Sprite::create("testimage2.png");
    spriteHide->setPosition(Point(200,200));
    spriteHide->setVisible(false);  //안보이게 설정
    this->addChild(spriteHide);
    
    
    //ToggleVisibility::create() : visible의 값을 반대로 바꾼다
    auto action = ToggleVisibility::create();
    spriteShow->runAction(ToggleVisibility::create());  //보였다 -> 안보이게 바뀐다
    spriteHide->runAction(action);  //안보였다 -> 보이게 바뀐다
    
    
    return true;
}
 
cs



결과

visible이었던 testimage는 안보이고 invisible이었던 testimage2는 보이게된다



+ Recent posts