서서히 투명, 불투명하게하는 액션기능 (FadeIn, FadeOut)



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
43
44
45
46
47
48
#include "test124.hpp"
 
USING_NS_CC;
 
Scene* Test124::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test124::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test124::init()
{
    if ( !Layer::init())
    {
        return false;
    }
    
    
    auto spriteFadeIn = Sprite::create("testimage.png");
    spriteFadeIn->setPosition(Point(100,100));
    spriteFadeIn->setOpacity(0);  //투명도를 0으로 안보이게 설정
    this->addChild(spriteFadeIn);
    
    auto spriteFadeOut = Sprite::create("testimage2.png");
    spriteFadeOut->setPosition(Point(200,200));
    spriteFadeOut->setOpacity(255);  //투명도를 255으로 보이게 설정
    this->addChild(spriteFadeOut);
    
    
    
    //FadeIn : 지정된 시간동안 투명도를 0->255로 변환 , FadeOut : 지정된 시간동안 투명도를 255->0으로 변환
    //FadeIn::create(액션시간) , FadeOut::create(액션시간)
    auto actionFadeIn = FadeIn::create(3.0);
    auto actionFadeOut = FadeOut::create(3.0);
    spriteFadeIn->runAction(actionFadeIn);  //투명도 0에서 3초동안 255로 변환
    spriteFadeOut->runAction(actionFadeOut);//투명도 255에서 3초동안 0으로 변환
    //ps. visible의 값과는 상관없다
    
    
    
    return true;
}
 
cs



결과

testimage는 서서히 투명해지고 testimage2는 서서히 불투명해진다



+ Recent posts