●sprintf
- 메모리에 출력한다.
- sprintf(문자배열명, "출력문자와 자료형(ex.%d)", 입력 데이터);
●예제
- HelloWorldScene.cpp
#include "HelloWorldScene.h" using namespace cocos2d; CCScene* HelloWorld::scene() { CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create(); scene->addChild(layer); return scene; } bool HelloWorld::init() { if ( !CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)) ) { return false; } //////////////////////// //레이블 생성 및 초기화 CCLabelTTF *pLabel=CCLabelTTF::create("score:0", "Thonburi", 30); //레이블 위치 지정 pLabel->setPosition(ccp(240,180)); //레이블 색 지정 pLabel->setColor(ccc3(0,0,0)); //레이블의 투명도 지정 pLabel->setOpacity(100.0); //레이어에 레이블 객체 추가 this->addChild(pLabel); char coinScore[100] = {0}; int score=0; for(int i=0; i<100;i++){ score++; sprintf(coinScore, "score: %d",score); CCLog("score:%d", score);
pLabel->setString(coinScore); }
return true; } |
'프로그래밍 > cocos2d-x' 카테고리의 다른 글
cocos2d-x TestCpp 예제로 공부하기 (0) | 2013.06.09 |
---|---|
cocos2d-x 게임 중 일시정지하고 팝업창 띄우기(pause, resume) (0) | 2013.06.09 |
cocos2d-x 간단한 액션 게임 예제3 (0) | 2013.06.09 |
cocos2d-x 간단한 액션 게임 예제2 (0) | 2013.06.09 |
cocos2d-x 간단한 액션 게임 예제1 (0) | 2013.06.08 |
댓글