Hello World 및 이미지 추가하기



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
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
 
USING_NS_CC;
 
Scene* HelloWorld::createScene()
{
    auto scene = Scene::create();
    
    auto layer = HelloWorld::create();
    scene->addChild(layer);
 
    return scene;
}
 
 
bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
 
 
    /**
        Hello World 출력하기
     */
    //Hello World 라벨객체
    auto label = Label::createWithTTF("Hello World""fonts/Marker Felt.ttf"24);
    //위치지정
    label->setPosition(Vec2(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - label->getContentSize().height));
 
    //레이어에 추가
    this->addChild(label, 1);
 
    
    /**
        Image 추가하기
     */
    //create("추가할 이미지 파일명")
    auto spr = Sprite::create("testimage.png");   //메모리 관리 Cocos에서 직접관리
    //Anchor Point 지정
    spr -> setAnchorPoint(Point(0.5,0.5));
    //이미지 위치 지정 (Anchor Point의 위치)
    spr -> setPosition(Point(100,100));
    //레이어에 추가
    this -> addChild(spr);
    //이미지의 가운데 위치가 100,100으로 지정
    
    
    return true;
}
cs



결과




+ Recent posts