IT/- 프로그래밍

코코스 Cocos 기본 메서드 예제 (setOpacity , setScale , setRotation , setFlippedX)

혁준7519 2017. 1. 12. 09:19

Cocos 기본 메서드 예제

(setOpacity , setScale , setRotation , setFlippedX)



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "test71.h"
#include "SimpleAudioEngine.h"
 
USING_NS_CC;
 
Scene* Test71::createScene()
{
    auto scene = Scene::create();
    
    auto layer = Test71::create();
    scene->addChild(layer);
    
    return scene;
}
 
 
bool Test71::init()
{
    //레이어 색깔을 하얀색으로 한다
    //Color4B(r,g,b,a) : 색깔지정
    if ( !LayerColor::initWithColor(Color4B(255255255255)))
    {
        return false;
    }
    
    
    //화면의 크기 가져오기
    Size winSize = Director::getInstance()->getWinSize();
    
    //왼쪽 하단에 이미지
    auto spr1 = Sprite::create("testimage.png");
    spr1->setAnchorPoint(Point(0,0));
    spr1->setPosition(Point(0,0));
    this->addChild(spr1);
    
    //하단 가운데에 이미지
    auto spr2 = Sprite::create("testimage.png");
    spr2->setAnchorPoint(Point(0.5,0));
    spr2->setPosition(Point(winSize.width/2,0));
    /**
     setOpacity(0-255) : 0 - 투명 , 128 - 반투명 , 255 - 불투명
     */
    spr2->setOpacity(128);
    this->addChild(spr2);
 
    //하단 오른쪽에 2배하여 이미지
    auto spr3 = Sprite::create("testimage.png");
    spr3->setAnchorPoint(Point(1,0));
    spr3->setPosition(Point(winSize.width,0));
    /**
     setScale(비율) : 1> - 확대 , <1 - 축소
     */
    spr3->setScale(2.0);
    this->addChild(spr3);
 
    //가운데에 이미지
    auto spr4 = Sprite::create("testimage.png");
    spr4->setPosition(Point(winSize.width/2 , winSize.height/2));
    /**
     앵커포인트 기준으로 회전한다
     setRotation(각도) : z축 기준으로 회전
     setRotationX(각도) : x축 기준으로 회전
     setRotationY(각도) : y축 기준으로 회전
     */
    spr4->setRotation(90.0);
    this->addChild(spr4);
    
    //상단 가운데에 이미지
    auto spr5 = Sprite::create("testimage.png");
    spr5->setAnchorPoint(Point(0.5,1));
    spr5->setPosition(Point(winSize.width/2 , winSize.height));
    /**
     setFlippedX(true) : 좌우반전
     setFlippedY(true) : 상하반전
     */
    spr5->setFlippedY(true);
    this->addChild(spr5);
    
    return true;
}
cs



결과