2011-07-12 65 views
1

我使用下面的代碼:需要幫助,以解決簡單的cocos2d錯誤?

// Add the stuff from below! 
    CCSprite* background = [CCSprite spriteWithFile:@"background-1.png"]; 
    background.tag = 1; 
    background.anchorPoint = CGPointMake(0, 0); 
    [self addChild:background]; 


    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: 
    @"wave1.plist"]; 

    CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode 
             batchNodeWithFile:@"wave1.png"]; 
    [self addChild:spriteSheet]; 
    NSMutableArray *walkAnimFrames = [NSMutableArray array]; 
    for(int i = 1; i <= 8; ++i) { 
     [walkAnimFrames addObject: 
     [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: 
      [NSString stringWithFormat:@"wave-r-l-000%d.png", i]]]; 
     //wave-r-l-0001 
    } 

    CCAnimation *walkAnim = [CCAnimation 
          animationWithFrames:walkAnimFrames delay:0.1f]; 

    CGSize winSize = [CCDirector sharedDirector].winSize; 
    self.bear = [CCSprite spriteWithSpriteFrameName:@"bear1.png"];   
    _bear.position = ccp(winSize.width/2, winSize.height/2); 
    self.walkAction = [CCRepeatForever actionWithAction: 
         [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]]; 
    [_bear runAction:_walkAction]; 
    [spriteSheet addChild:_bear]; 

但不幸的是它提供了以下錯誤:

2011-07-12 09:43:33.471 TestBear[205:707] cocos2d: cocos2d v1.0.0-rc3 
2011-07-12 09:43:33.479 TestBear[205:707] cocos2d: Using Director Type:CCDirectorDisplayLink 
2011-07-12 09:43:33.650 TestBear[205:707] cocos2d: OS version: 4.3.1 (0x04030100) 
2011-07-12 09:43:33.654 TestBear[205:707] cocos2d: GL_VENDOR: Imagination Technologies 
2011-07-12 09:43:33.658 TestBear[205:707] cocos2d: GL_RENDERER: PowerVR SGX 535 
2011-07-12 09:43:33.661 TestBear[205:707] cocos2d: GL_VERSION: OpenGL ES-CM 1.1 IMGSGX535-58.6 
2011-07-12 09:43:33.667 TestBear[205:707] cocos2d: GL_MAX_TEXTURE_SIZE: 2048 
2011-07-12 09:43:33.670 TestBear[205:707] cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16 
2011-07-12 09:43:33.674 TestBear[205:707] cocos2d: GL_MAX_SAMPLES: 4 
2011-07-12 09:43:33.677 TestBear[205:707] cocos2d: GL supports PVRTC: YES 
2011-07-12 09:43:33.680 TestBear[205:707] cocos2d: GL supports BGRA8888 textures: YES 
2011-07-12 09:43:33.684 TestBear[205:707] cocos2d: GL supports NPOT textures: YES 
2011-07-12 09:43:33.687 TestBear[205:707] cocos2d: GL supports discard_framebuffer: YES 
2011-07-12 09:43:33.690 TestBear[205:707] cocos2d: compiled with NPOT support: NO 
2011-07-12 09:43:33.694 TestBear[205:707] cocos2d: compiled with VBO support in TextureAtlas : NO 
2011-07-12 09:43:33.697 TestBear[205:707] cocos2d: compiled with Affine Matrix transformation in CCNode : YES 
2011-07-12 09:43:33.700 TestBear[205:707] cocos2d: compiled with Profiling Support: NO 
2011-07-12 09:43:33.854 TestBear[205:707] cocos2d: CCSpriteFrameCache: Trying to use file 'wave1.png' as texture 
2011-07-12 09:43:33.905 TestBear[205:707] cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist 
2011-07-12 09:43:33.910 TestBear[205:707] cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist 
2011-07-12 09:43:33.914 TestBear[205:707] cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist 
2011-07-12 09:43:33.917 TestBear[205:707] cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist 
2011-07-12 09:43:33.921 TestBear[205:707] cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist 
2011-07-12 09:43:33.925 TestBear[205:707] cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist 
2011-07-12 09:43:33.928 TestBear[205:707] cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist 
2011-07-12 09:43:33.932 TestBear[205:707] cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist 
2011-07-12 09:43:33.935 TestBear[205:707] cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist 
2011-07-12 09:43:33.941 TestBear[205:707] cocos2d: CCSpriteFrameCache: Frame 'bear1.png' not found 
2011-07-12 09:43:33.946 TestBear[205:707] *** Assertion failure in -[CCSprite initWithSpriteFrame:], /Users/shahbazali/Documents/TestBear/libs/cocos2d/CCSprite.m:229 
2011-07-12 09:43:34.006 TestBear[205:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid spriteFrame for sprite' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x31fbe64f __exceptionPreprocess + 114 
    1 libobjc.A.dylib      0x31132c5d objc_exception_throw + 24 
    2 CoreFoundation      0x31fbe491 +[NSException raise:format:arguments:] + 68 
    3 Foundation       0x30c30573 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62 
    4 TestBear       0x0008cf08 -[CCSprite initWithSpriteFrame:] + 200 
    5 TestBear       0x0008bfcc +[CCSprite spriteWithSpriteFrame:] + 88 
    6 TestBear       0x0008c098 +[CCSprite spriteWithSpriteFrameName:] + 120 
    7 TestBear       0x00003f04 -[HelloWorldLayer init] + 744 
    8 TestBear       0x00067bf0 +[CCNode node] + 76 
    9 TestBear       0x000041e4 +[HelloWorldLayer scene] + 100 
    10 TestBear       0x00003530 -[TestBearAppDelegate applicationDidFinishLaunching:] + 1028 
    11 UIKit        0x322f885d -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 832 
    12 UIKit        0x322f2b65 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 272 
    13 UIKit        0x322c77d7 -[UIApplication handleEvent:withNewEvent:] + 1114 
    14 UIKit        0x322c7215 -[UIApplication sendEvent:] + 44 
    15 UIKit        0x322c6c53 _UIApplicationHandleEvent + 5090 
    16 GraphicsServices     0x304a6e77 PurpleEventCallback + 666 
    17 CoreFoundation      0x31f95a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26 
    18 CoreFoundation      0x31f9783f __CFRunLoopDoSource1 + 166 
    19 CoreFoundation      0x31f9860d __CFRunLoopRun + 520 
    20 CoreFoundation      0x31f28ec3 CFRunLoopRunSpecific + 230 
    21 CoreFoundation      0x31f28dcb CFRunLoopRunInMode + 58 
    22 UIKit        0x322f1d49 -[UIApplication _run] + 372 
    23 UIKit        0x322ef807 UIApplicationMain + 670 
    24 TestBear       0x000030b4 main + 100 
    25 TestBear       0x00003018 start + 52 
) 
terminate called after throwing an instance of 'NSException' 
Program received signal: 「SIGABRT」. 

請幫

+0

以下鏈接對您有幫助 - http://stackoverflow.com/questions/4322135/ccspriteframe-warning-anchorpoint-wont-work-as-expected-regenerate-the-plist –

回答

4

我知道這個題目是有點老,但它可能會幫助一些人。

誤差來源於此行:

self.bear = [CCSprite spriteWithSpriteFrameName:@"bear1.png"]; 

TestBear [205:707]的cocos2d:CCSpriteFrameCache:幀 'bear1.png' 未找到

這意味着CCSpriteFrameCache不containt sprime框架命名爲「bear1.png」。這裏只添加1個plist文件(「wave1.plist」),並且它不包含名爲「bear1.png」的sprime幀。因此,檢查你的plist文件並在必要時重新生成它。

另一個常見錯誤是如果您的精靈不在「spritesheet」中,則使用「spriteWithSpriteFrameName:」而不是「spriteWithFile:」。

我希望我能幫上忙。