지정한 시간에 지정된 투명도로 변경해주는 액션기능 (FadeTo)



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
#include "test126.hpp"
 
USING_NS_CC;
 
Scene* Test126::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test126::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test126::init()
{
    if ( !Layer::init())
    {
        return false;
    }
    
    
    auto sprite = Sprite::create("testimage.png");
    sprite->setPosition(Point(100,100));
    this->addChild(sprite);
    
    
    //FadeTo::create(액션시간, 투명도) : 지정한 시간에 지정한 투명도로 변환한다
    auto action = FadeTo::create(3.0128);
    sprite->runAction(action);
    
    
    
    return true;
}
 
cs



결과

testimage가 3초 후에 투명도 128로 변환한다



서서히 투명, 불투명하게하는 액션기능 (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는 서서히 불투명해진다



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는 보이게된다



깜박이게 하는 액션기능 (Blink)



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
#include "test122.hpp"
 
USING_NS_CC;
 
Scene* Test122::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test122::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test122::init()
{
    if ( !Layer::init())
    {
        return false;
    }
    
    
    auto sprite = Sprite::create("testimage.png");
    sprite->setPosition(Point(100,100));
    this->addChild(sprite);
 
    
    //Blink::create(액션기간, 깜박이는 횟수) : 객체 깜박이게 설정
    auto blinkAction = Blink::create(3.010);  //3초동안 스프라이트 객체를 10번 깜박임
    sprite->runAction(blinkAction);
    
    
    return true;
}
 
cs



결과

3초동안 10번 깜박인다



보이게, 보이지 않게하는 액션기능 (Show, Hide)



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
#include "test120.hpp"
 
USING_NS_CC;
 
Scene* Test120::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test120::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test120::init()
{
    if ( !Layer::init())
    {
        return false;
    }
    
    
    auto spriteShow = Sprite::create("testimage.png");
    spriteShow->setPosition(Point(100,100));
    spriteShow->setVisible(true);  //보이게 설정
 
    auto spriteHide = Sprite::create("testimage2.png");
    spriteHide->setPosition(Point(200,200));
    spriteHide->setVisible(false);   //보이지 않게 설정
 
    this->addChild(spriteShow);
    this->addChild(spriteHide);
    
    
    //Show::create() : 보이게 설정
    auto actionHide = Hide::create();
    spriteShow->runAction(actionHide);  //보이다 -> 보이지 않게 설정
 
    //Hide::create() : 보이지 않게 설정
    auto actionShow = Show::create();
    spriteHide->runAction(actionShow);  //안보이다 -> 보이게 설정
    
        
    return true;
}
 
cs



결과

testimage1은 보이지 않고 testimage2는 보인다




error LNK2019: _cvReleaseImage 외부 기호(참조 위치: _main 함수)에서 확인하지 못했습니다.



라이브러리 링크시 컴퓨터 사양(32bit or 64bit)이 아닌 프로젝트 빌드 설정에 맞추어야 한다.


x64용 라이브러리를 x86 설정에서 링크시켰기 때문에 발생한 문제였다.



해결


회전하는 액션기능 (RotateBy)



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
#include "test118.hpp"
 
USING_NS_CC;
 
Scene* Test118::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test118::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test118::init()
{
    if ( !Layer::init())
    {
        return false;
    }
    
    
    auto sprite = Sprite::create("testimage.png");
    sprite->setPosition(Point(100,100));
    this->addChild(sprite);
    
    
    //RotateBy(액션시간, 회전각도)
    //RotateTo : 입력한 각도로 가장 빠르게 회전, RotateBy : +는 시계방향 -는 반시계방향으로 지정한 값만큼 회전
    auto action = RotateBy::create(2.0450);   //시계방향으로 450도 회전
    sprite->runAction(action);
    
    
    return true;
}
 
cs



결과



크기 변경하는 액션기능 (ScaleTo)



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 "test116.hpp"
 
USING_NS_CC;
 
Scene* Test116::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test116::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test116::init()
{
    if ( !Layer::init())
    {
        return false;
    }
    
    
    auto sprite = Sprite::create("ball.png");   //스프라이트 이미지 객체 생성
    sprite->setPosition(Point(100,100));    //스프라이트 위치 지정
    sprite->setScale(2);    //크기지정(2배 확대)
    this->addChild(sprite); //레이어에 추가
    
    
    //ScaleTo::create(액션시간, 크기)
    //ScaleBy : 현재크기 기준(8배 확대), ScaleTo : 지정한크기 기준(3배 확대)
    auto action = ScaleBy::create(23);
    sprite->runAction(action);
    
    
    
    
    return true;
}
 
cs



결과

이미지가 8배로 확대된다



위치 변경하는 액셔기능 (Place)

Place : 액션들을 순차적으로 조합하는 과정에서 중간에 위치를 변경하고 싶을때



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
#include "test114.hpp"
 
USING_NS_CC;
 
Scene* Test114::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test114::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test114::init()
{
    if ( !Layer::init())
    {
        return false;
    }
    
    
    auto sprite = Sprite::create("ball.png");   //스프라이트 이미지 객체 생성
    sprite->setPosition(Point(100,100));    //스프라이트 위치 지정
    this->addChild(sprite); //레이어에 추가
    
    
    //Place : 액션들을 순차적으로 조합하는 과정에서 중간에 위치를 변경하고 싶을때
    //Place::create(위치지정)
    auto action = Place::create(Point(200,200));
    sprite->runAction(action);  //액션추가
    
    
    return true;
}
 
cs




베지어 액션기능 (BezierTo)



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
#include "test112.hpp"
 
USING_NS_CC;
 
Scene* Test112::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test112::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test112::init()
{
    if ( !Layer::init())
    {
        return false;
    }
    
    
    auto sprite = Sprite::create("ball.png");   //스프라이트 이미지 객체
    sprite->setPosition(Point(50,50));  //위치 지정
    this->addChild(sprite); //레이어에 추가
    
    
    //베지어 곡선의 설정
    ccBezierConfig config;
    config.controlPoint_1 = Point(200,250); //제어점 설정
    config.controlPoint_2 = Point(400,150); //제어점 설정
    config.endPosition = Point(450,50); //도착점 설정
    
    //BezierTo::create(액션시간 , 설정)
    auto action = BezierTo::create(3.0f, config);   //베지어 액션 생성
    sprite->runAction(action);  //노드에 액션 설정
        
    
    return true;
}
cs


+ Recent posts