ios - 我的应用程序中出现 NSInvalidArgumentException 错误...任何擅长此的人请帮助我

标签 ios cocos2d-iphone objective-c-2.0

我正在尝试在我的游戏中添加不同的级别。玩游戏时分数会上升,达到一定分数后等级会发生变化。那是我的计划,但我写了一个像'spiderupdate:(cctime)delta'这样的代码,如你所见。我很确定这是问题,因为当我不把“如果”放在那里并且只使用一个级别时,它可以正常工作而不会崩溃。 谁能帮我弄清楚如何解决它。

错误是这样的'NSInvalidArgumentException',原因:'-[Play texture]: unrecognized selector sent to instance 0xf57da10'

Play 是我的类名,texture 应该是方法,但我没有任何名为 texture 的方法。

-(void) spidersUpdate:(ccTime)delta {
// Try to find a spider which isn't currently moving. 
for (int i = 0; i < 10; i++)
{
    int randomSpiderIndex = CCRANDOM_0_1() * [spiders count]; 
    CCSprite* spider = [spiders objectAtIndex:randomSpiderIndex];
    // If the spider isn't moving it won’t have any running actions.
    if ([spider numberOfRunningActions] == 0)
    {   
        if(currentScore<=30)
            [self level1:spider];
        else if(31<=currentScore<=60)
            [self level2:spider];
        else if (61<=currentScore<=90) {
            [self level3:spider];
        }
        else if (91<=currentScore<=120) {
            [self level4:spider];
        }
        else if (120<=currentScore) {
            [self level5:spider];
        }
        break;
        // Only one spider should start moving at a time.
        }

} 
}

-(void) level1:(CCSprite*)spider {
// Slowly increase the spider speed over time. 
numSpidersMoved++;
if (numSpidersMoved % 8 == 0 && spiderMoveDuration > 2.0f) {
    spiderMoveDuration -= 0.2f; }
CGPoint belowScreenPosition = CGPointMake(spider.position.x,
                                          -10);
CCMoveTo* move = [CCMoveTo actionWithDuration:spiderMoveDuration

                                     position:belowScreenPosition]; 
CCCallFuncN* callDidDrop =[CCCallFuncN actionWithTarget:self selector:@selector(spiderDidDrop:)];
CCSequence* sequence = [CCSequence actions:move, callDidDrop, nil];
if ([spider runAction:sequence])
{
    currentScore++;
}

}

-(void) level2:(CCSprite*)spider
{
numSpidersMoved++;
if (numSpidersMoved % 8 == 0 && spiderMoveDuration > 2.0f) {
    spiderMoveDuration -= 0.2f; }

// Slowly increase the spider speed over time. 
CGPoint belowScreenPosition = CGPointMake(spider.position.x,
                                          -10);
CCMoveTo* move = [CCMoveTo actionWithDuration:spiderMoveDuration position:belowScreenPosition];
CCActionEase*esay=[CCEaseExponentialIn actionWithAction:move];
CCCallFuncN* callDidDrop =[CCCallFuncN actionWithTarget:self selector:@selector(spiderDidDrop:)];
CCSequence* sequence = [CCSequence actions:esay, callDidDrop, nil];
if ([spider runAction:sequence])
{
    currentScore++;
}
}
-(void) level3:(CCSprite*)spider
{
numSpidersMoved++;
if (numSpidersMoved % 8 == 0 && spiderMoveDuration > 2.0f) {
    spiderMoveDuration -= 0.2f; }

// Slowly increase the spider speed over time. 
CGPoint belowScreenPosition = CGPointMake(spider.position.x,
                                          -10);
CCMoveTo* move = [CCMoveTo actionWithDuration:spiderMoveDuration position:belowScreenPosition];
CCActionEase*esay=[CCEaseExponentialInOut actionWithAction:move];
CCCallFuncN* callDidDrop =[CCCallFuncN actionWithTarget:self selector:@selector(spiderDidDrop:)];
CCSequence* sequence = [CCSequence actions:esay, callDidDrop, nil];
if ([spider runAction:sequence])
{
    currentScore++;
    }
}

-(void) level4:(CCSprite*)spider
{
numSpidersMoved++;
if (numSpidersMoved % 8 == 0 && spiderMoveDuration > 2.0f) {
    spiderMoveDuration -= 0.2f; }

// Slowly increase the spider speed over time. 
CGPoint belowScreenPosition = CGPointMake(spider.position.x,
                                          -10);
CCMoveTo* move = [CCMoveTo actionWithDuration:spiderMoveDuration position:belowScreenPosition];
CCActionEase*esay=[CCEaseExponentialOut actionWithAction:move];
CCCallFuncN* callDidDrop =[CCCallFuncN actionWithTarget:self selector:@selector(spiderDidDrop:)];
CCSequence* sequence = [CCSequence actions:esay, callDidDrop, nil];
if ([spider runAction:sequence])
{
    currentScore++;
}
}
-(void) level5:(CCSprite *)spider
{   numSpidersMoved++;
ccTime delayTime=2.5f;
if (numSpidersMoved %8 == 0 && delayTime>1.0f)
{
    delayTime-=0.2f;
}
CGPoint dropALittleBit= CGPointMake(spider.position.x, 350);
CGPoint belowScreenPosition= CGPointMake(spider.position.x, -10);
CCMoveTo*move =[CCMoveTo actionWithDuration:0.8 position:dropALittleBit];
CCDelayTime*delay=[CCDelayTime actionWithDuration:delayTime];
CCMoveTo*drop=[CCMoveTo actionWithDuration:0.3f position:belowScreenPosition];
CCCallFuncN*callDidDrop=[CCCallFuncN actionWithTarget:self selector:@selector(spiderDidDrop:)];
   if ([spider runAction:[CCSequence actions:move,delay,drop,callDidDrop, nil]])
{
   currentScore++;
}
}
-(void) spiderDidDrop:(id)sender {
// Make sure sender is actually of the right class.
NSAssert([sender isKindOfClass:[CCSprite class]], @"sender is not a CCSprite!"); 
CCSprite* spider = (CCSprite*)sender;
// move the spider back up outside the top of the screen
CGPoint pos = spider.position;
CGSize screenSize = [[CCDirector sharedDirector] winSize];
pos.y = screenSize.height + [spider texture].contentSize.height; 
spider.position = pos;
}

最佳答案

这是一个链接 http://www.cocos2d-iphone.org/api-ref/0.99.0/interface_c_c_sprite.html 这告诉 CCCsprite 的属性,你可以看到没有属性作为纹理,所以如果你想的话,检查并使用 textureRect 属性。

希望对你有帮助

关于ios - 我的应用程序中出现 NSInvalidArgumentException 错误...任何擅长此的人请帮助我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9980715/

相关文章:

ios - Swift ios 不确定如何在使用 Storyboard id 时将导航栏添加到 Storyboard 中的 VC

iOS MapKit 通过 didUpdateUserLocation 崩溃 - 困惑

iphone - cocos2d 中的光流

iphone - 应用程序针对 Facebook 登录配置错误 IOS Facebook 应用程序已安装

ios - "How To Make a Tile-Based Game with Cocos2D 2.X"使用cocos2d V3制作本教程

audio - Cocos2d - SimpleAudioEngine - iPhone 上没有播放声音

iphone - 所以 "lame"- 如何从 float = 0.39824702 只是 float = 0.398?

cocoa - 数据源和 NSTableView

iphone - 返回 ImageView 数组(iPhone)?

iphone - iOS 推送通知 - 在没有警报的情况下更新角标(Badge)?