更新 Cocos2d 中的标签值

2024-08-11移动开发问题
9

本文介绍了更新 Cocos2d 中的标签值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在 cocos2d 中制作游戏,在更新分数时,旧的分数值会出现在标签上,而新的值会被覆盖.我正在使用以下代码来显示分数,

I am making a game in cocos2d , In that while updating score the old score values get on the label and the new value get overwritten. I m using following code to display the score,

LblScore = [CCLabel labelWithString:[NSString stringWithFormat:@"%d",score]
                         dimensions:CGSizeMake(100, 300) 
                          alignment:UITextAlignmentCenter  
                           fontName:@"Arial" 
                           fontSize:32.0];

因为这个分数值没有显示出来,所有的东西都堆积起来了,如果有人知道如何更新新分数?

Because of this the score value are not shown and all things get massed up, If any one having idea how to update new score?

推荐答案

我的问题的解决方案是,我必须在 -(id)init 方法中定义标签声明,在任何地方提供的值上不会覆盖值.

The Solution for my problem is , I must have to define the label declaration in the -(id)init method, there on the value provided from any where there will be no overwriting of the values.

我已经尝试过了,它正在工作,但仍然感谢所有为我提供帮助的人

I've tried it and it's working, But still thanks to all who provided me a help

这篇关于更新 Cocos2d 中的标签值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

如何将 32 位 PNG 转换为 RGB565?
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)...
2024-08-12 移动开发问题
21

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7