본문 바로가기

카테고리 없음

[cocos2d-x]Chapter2-2. HelloWorldScene 스프라이트 응용3

 

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
 
#include "HelloWorldScene.h"
 
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 spr = Sprite::create("Icon-57.png", Rect(0,0,30,30 ));
    //spr->setAnchorPoint(Point(0.5, 0.5));
    spr->setPosition(Point(100100));
    this->addChild(spr);
    
    this->setPosition(Point(200200));
//spr의 부모객체인 this의 좌표를 변경
 
    return true;
}
 
 
cs

 


실행 결과 


 


스프라이트(spr)의 부모인 this의 좌표에 변경되었고 spr은 this에 

종속되어 있기 때문에 실제로는 (300,300)으로 보이는 것