Game !

 

 

cocos로 작업할 때,

텍스트를 출력하는 CharMap 함수는 게임에서 많이 사용된다

왜냐하면 숫자를 이미지로 만들어서 출력해야하기 때문이다.

 

 

 

기본형

Label::createWithCharMap(cocos2d::Texture2D* texture, int itemWidth, int itemHeight, int startCharMap)

 

매개변수 순서

이미지파일 이름.확장자 / 너비 / 높이 / 아스키코드값

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
bool HelloJudai::init()
{
    if(!LayerColor::initWithColor(Color4B::WHITE))
    {
        return false;
    }
 
    auto label = Label::createWithCharMap("number.png"334548);
 
    int score = 100;
 
    label->setString(StringUtils::format("%d", score));
    label->setPosition(Vec2(200,300));
    label->setTag(1); //레이어 출력순서 결정 this->addChild(label,1);과같음
    this->addChild(label);
 
 
    score += 10;
    //레이어 출력순서 결정
    auto scoreLabel = (Label*)this->getChildByTag(1);
    scoreLabel->setString(StringUtils::format("%d", score));
 
    return true;
}
 
cs

 

 

createWithCharMap("폰트이미지.png", 출력너비, 출력높이, 아스키코드 값);

여기서 너비와 높이는 출력하고자 하는 이미지의 것을 말한다.

 

 

 

사진의 빨간색 박스 부분의 너비와 높이를 입력하면 된다.

 

 

더보기

cf.

이미지가 [$,0123456789] 로 되어있어 아스키코드와 순서가 맞지 않을 경우

0의 아스키코드 값 48의 2개 앞인 46(.)을 선언한다.

그리고 setString에서 ".100"을 입력하면 $100을 표시할 수 있다

 

 

 

출처:http://genieker.tistory.com/11