cocos2d:LabelAtlas文本对齐? [英] cocos2d: LabelAtlas text alignment?

查看:345
本文介绍了cocos2d:LabelAtlas文本对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在cocos2d 0.7.1中有一种方法来指定LabelAtlas中的文本对齐方式?



我使用LabelAtlas作为分数



我可以实现代码来检测和移动LabelAtlas,但是有一种方法

解决方案

感谢您使用cocos2d为我做这件事。



您可以使用 anchorPosition 属性更改位置定义的位置。例如;在我的游戏中,我把 scoreLabel 放在屏幕的右下角。为了确保它始终可见,我将 anchorPosition 设置为标签的右下角,然后设置其位置

  [scoreLabel setAnchorPoint:ccp(1,0)]; 
[scoreLabel setPosition:ccp(480,0)];

如果您希望它位于屏幕的右上角,

  [scoreLabel setAnchorPoint:ccp(1,1)]; 
[scoreLabel setPosition:ccp(480,320)];


Is there a way in cocos2d 0.7.1 to specify the text alignment in a LabelAtlas?

I'm using a LabelAtlas for a score (displayed in the upper right corner) but when the score goes above 10, the second digit is cut off.

I can implement code to detect that and move the LabelAtlas, but is there a way to have cocos2d do it for me?

Thanks.

解决方案

While that works, you'll have the same problem if the score goes above 1000.

You can use the anchorPosition property to change where the position is defined. For example; in my game I place the scoreLabel in the lower right hand corner of the screen. To ensure it is always visible I set anchorPosition to be the lower right hand corner of the label and then set its position where I want the lower right hand corner of the label to be.

[scoreLabel setAnchorPoint:ccp(1, 0)];
[scoreLabel setPosition:ccp(480, 0)];

If you want it positioned in the upper right hand corner of the screen then you can similarly use the following code to define the anchor as the upper right corner.

[scoreLabel setAnchorPoint:ccp(1, 1)];
[scoreLabel setPosition:ccp(480, 320)];

这篇关于cocos2d:LabelAtlas文本对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆