2013-06-03 2 views
2

나는 cocos2d-iOS 게임을 cocos2d-x Android로 이식하고 있고 cocos2d 게임 코드는 sizeWithFont 메서드를 가지고 있지만 Android에서는 사용할 방법이 없습니다. 그렇다면 Cocos2d-x를 Android 용으로 사용할 때 sizeWithFont를 대체하는 데 사용할 수있는 방법은 무엇입니까?sizeWithFont for Android

답변

1

불행하게도 Ant처럼은이 아이폰 OS의 특정 기능입니다, 당신은 그것의 앞에 UI 또는 NS 아무것도를 사용하지 않으려 고 말했다.

는 당신이

CCSize sizeWithFont(const char *string, const char *fontName, float fontSize) { 
    CCLabelTTF *label = CCLabelTTF::create(string, fontName, fontSize); 
    CCSize size = label->boundingBox().size; 
    delete label; 
    return size; 
} 
같은 함수를 만들 수

CCLabelTTF *label = CCLabelTTF::create("my text", "Arial", 48); 
CCLog("label size: %f,%f", timeLabel->boundingBox().size.width, timeLabel->boundingBox().size.height); 

글꼴과 크기의 텍스트의 경계를 계산하는 방법이 말했다되고

0

참조하는 방법은 [UIFont fontWithSize]이며 UIKit 메서드이며 Cocos2d와는 관련이 없습니다.

이것은 iOS의 기능이며 Cocos2d가 아니기 때문에 (UIKit을 사용하는 경우 다른 메뉴와 마찬가지로) Cocos2d-x 자체를 사용하여 메뉴를 제작해야합니다. .

여기 라벨 작업에 대한 튜토리얼이있다 :

http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Text_Labels#Creating-labels-Simple-way