objective-c – 如何在cocos2d中制作并正确更新进度条?

我有一个游戏,使用进度条告知玩家玩家的某些统计数据的级别.例如饥饿,当它从零开始并慢慢加起来达到最大值.当他吃东西时,饥饿减少了.

我尝试将其作为progressBar实现,但它的工作方式有误,因为条形图扩展了两种方式,我只需要将它扩展到一边.我也很难设置栏,因为它使用了动作.

一个简单的方法吗?

我有一个宠物类,它有饥饿感(0-100).我希望酒吧显示出饥饿感.

hungerBar = [CCSprite spriteWithFile:@"redbar.png"];
    cclabelTTF *hungerLabel = [cclabelTTF labelWithString:@"Hunger:" fontName:@"Helvetica" fontSize:25];
    [hungerLabel setColor:ccc3(255,255,255)];

//    CGPoint temp = ccp(250,300);
//    hungerBar.position = temp;
 //   [self addChild:hungerBar];
    CGPoint temp2 = ccp(250,320);
    [hungerLabel setPosition:temp2];
    [self addChild:hungerLabel];

    CCSprite *bar = [CCSprite spriteWithFile:@"redbar.png"];
    powerBar= [CCProgresstimer progressWithSprite:bar];
    powerBar.type = kCCProgresstimerTypeBar;
    powerBar.position = ccp(-30,-10);
    powerBar.anchorPoint = ccp(0,0);
    powerBar.percentage = 20; // (0 - 100)
    [hungerLabel addChild:powerBar];

添加了来源.

解决方法

在cocos2d 2.0之前,您应该能够使用CCProgresstimer类型:kCCProgresstimerTypeHorizo​​ntalBarLR.
CCProgresstimer* powerBar= [CCProgresstimer progressWithFile:@"fullbar.png"];
powerBar.type = kCCProgresstimerTypeHorizontalBarLR;
powerBar.percentage = 0; // (0 - 100)

要改变您的饥饿程度,只需设置栏的百分比属性即可.

编辑:

好吧,使用cocos2d 2.0,似乎这种类型不再可用.要获得从左到右的栏,您需要设置新的但有些令人困惑的中点和barChangeRate属性(cocos2D 2.0 documentation link):

CCProgresstimer* powerBar= [CCProgresstimer progressWithSprite:[CCSprite spriteWithFile:@"fullbar.png"]];
powerBar.type = kCCProgresstimerTypeBar;
powerBar.midpoint = ccp(0,0); // starts from left
powerBar.barChangeRate = ccp(1,0); // grow only in the "x"-horizontal direction
powerBar.percentage = 0; // (0 - 100)

看看这些是否有帮助!

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...