【问题标题】:display different sprites randomly in cocos2d在 cocos2d 中随机显示不同的精灵
【发布时间】:2011-02-08 15:01:54
【问题描述】:

我正在尝试随机跳跃不同的精灵。

我有 5 个不同的精灵必须随机显示。要显示的一个精灵

我尝试了下面的代码,但它崩溃了:- 警告:“CCSprite”可能无法响应“+spriteWithName:”

NSString *Sprit;

    NSInteger rnd = arc4random() % 6;

    if (rnd == 1) {
        Sprit = @"Target.png";
    } else if (rnd == 2) {
        Sprit = @"3.png";
    }else if (rnd == 3) {
        Sprit = @"5.png";
    } else if (rnd == 4) {
        Sprit = @"8.png";
    } else if (rnd == 5) {
        Sprit = @"10.png";
    }  else {
        Sprit = @"13.png";
    }

    CCSprite *target = [CCSprite spriteWithName:Sprit];

target.position = ccp(winSize.height + (target.contentSize.height/4), actualX);
    [self addChild:target ];

【问题讨论】:

    标签: iphone objective-c random cocos2d-iphone


    【解决方案1】:

    您的意思是使用:

    CCSprite *target = [CCSprite spriteWithFile:Sprit];
    

    相反?注意它是 spriteWith*File*

    这里有一些关于 CCSprite 类的文档: http://www.cocos2d-x.org/embedded/cocos2d-x/d4/de7/classcocos2d_1_1_c_c_sprite.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多