微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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)

看看这些是否有帮助!

原文地址:https://www.jb51.cc/c/115663.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐