2016-12-25 57 views
-1
#import <Foundation/Foundation.h> 
#import "cocos2d.h" 

// ----------------------------------------------------------------- 

@interface Person : CCSprite 
{ 
} 
@property NSString * actions; 

@property NSString* name; 

@property NSString* status; 

+ (instancetype)initWithPicture: (NSString *) pic; 

-(void)walk; 
// ----------------------------------------------------------------- 

@end 

以上是@interface person.h当在另一个班级中使用[人物散步]时,抛出“singare SIGABRT”,任何人都可以帮助我?我只是之学的Xcode

#import "Person.h" 
@implementation Person 
+ (id)initWithPicture: (NSString *) pic 
{ 
    CCSpriteFrameCache* spriteFrameCache = [CCSpriteFrameCache sharedSpriteFrameCache]; 
    CCSpriteFrame * bgSpriteFrame = [spriteFrameCache spriteFrameByName:pic]; 
    CCSprite * personSprite = [CCSprite spriteWithSpriteFrame:bgSpriteFrame]; 
    personSprite.anchorPoint = ccp(0, 0); 
    return personSprite; 
} 

-(void)walk 
{}@end 

以上是我person.m,但是方法命名走的是空

 #import "Person.h" 
     // ----------------------------------------------------------------- 
     CCSpriteBatchNode* batchNode; 
     Person * personA; 

     @implementation _256Deathes 
     { 
     } 
     - (instancetype)init 
     {  
    if ((self = [super init])) 
      { 
       NSAssert(self, @"Whoops"); 

       CCSpriteFrameCache* spriteFrameCache = [CCSpriteFrameCache sharedSpriteFrameCache]; 
       [spriteFrameCache addSpriteFramesWithFile:@"256Deathes.plist"]; 
       batchNode = [CCSpriteBatchNode batchNodeWithFile:@"256Deathes.png"]; 
       batchNode.position = CGPointZero; 
       [self addChild:batchNode]; 
       BackGround * bgSprite01 = [BackGround initWithPicture:@"earthA.png"]; 
       bgSprite01.position = ccp(0, 0); 
       [batchNode addChild:bgSprite01 z:0 name:@"bgSpriteA"]; 
       BackGround * bgSprite02 = [BackGround initWithPicture:@"earthA.png"]; 
       [batchNode addChild:bgSprite02 z:0 name:@"bgSpriteB"]; 
         } 
     return self; 
     } 

     - (void)onEnter 
     { 
      [super onEnter]; 
      //updateSprite per 0.2s 
      [self schedule:@selector(updateSprite) interval:0.02]; 
      //add person 
      personA = [Person initWithPicture:@"personA/personAWalk0.png"]; 
      personA.position = ccp(100,100); 
      [batchNode addChild:personA z:0 name:@"personA01"]; 
      //add person walk animate 
      [personA walk]; 
     } 
-(void) updateSprite 
{ 
    [self updateBackGround01]; 
} 

-(void) updateBackGround01 
{ 
    BackGround *sprite; 
    for(sprite in [batchNode children]) 
    { 
      double nextX = sprite.contentSize.width-2; 
      if(sprite.position.x <= (-nextX)) 
      { 
       sprite.position = ccp(nextX, 0); 
      } 
    } 

} 
// ----------------------------------------------------------------- 

@end 

这是我的另一个类, person是CCSprite的子类,256Deathes是CCSence的子类 我正在学习cocos2s-iphone,这些代码会抛出一个错误“signal SIGABRT”,我不知道为什么,找不到原因 如果删除了代码“[个人沃尔玛k]“,那样会好的,所以”[personA walk]“一定是原因,任何人都可以帮助我?谢谢! “------------------------------------------------ ---------------------------“ enter image description here

2016-12-25 22:02:40.786772 256deathes[6797:181749] subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:40.787820 256deathes[6797:181749] subsystem: com.apple.UIKit, category: HIDEventIncoming, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:40.800940 256deathes[6797:181734] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0 
2016-12-25 22:02:40.816385 256deathes[6797:181672] subsystem: com.apple.UIKit, category: StatusBar, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 
cocos2d: Cocos2D-Swift version 3.4.9-RC1 
cocos2d: compiled with Profiling Support: NO 
cocos2d: OS version: 10.0 (0x0a000000) 
cocos2d: 64 bit runtime 
cocos2d: Multi-threaded rendering: 0 
cocos2d: OpenGL Rendering enabled.cocos2d: GL_VENDOR: Apple Inc. 
cocos2d: GL_RENDERER: Apple Software Renderer 
cocos2d: GL_VERSION: OpenGL ES 2.0 APPLE-12.4.2 
cocos2d: GLSL_VERSION: OpenGL ES GLSL ES 1.00 
cocos2d: GL_MAX_TEXTURE_SIZE: 4096 
cocos2d: GL_MAX_TEXTURE_UNITS: 8 
cocos2d: GL_MAX_SAMPLES: 4 
cocos2d: GL supports PVRTC: YES 
cocos2d: GL supports BGRA8888 textures: YES 
cocos2d: GL supports NPOT textures: YES 
cocos2d: GL supports discard_framebuffer: YES 
cocos2d: GL supports shareable VAO: NO 
cocos2d: CCGraphicsBufferClass: CCGraphicsBufferGLUnsynchronized 
cocos2d: CCGraphicsBufferBindingsClass: CCGraphicsBufferBindingsGL 
cocos2d: CCRenderCommandDrawClass: CCRenderCommandDrawGL 
2016-12-25 22:02:40.874 256deathes[6797:181672] cocos2d: viewDidLoad 
cocos2d: Cocos2D-Swift version 3.4.9-RC1 
cocos2d: compiled with Profiling Support: NO 
cocos2d: OS version: 10.0 (0x0a000000) 
cocos2d: 64 bit runtime 
cocos2d: Multi-threaded rendering: 0 
cocos2d: OpenGL Rendering enabled.cocos2d: GL_VENDOR: Apple Inc. 
cocos2d: GL_RENDERER: Apple Software Renderer 
cocos2d: GL_VERSION: OpenGL ES 2.0 APPLE-12.4.2 
cocos2d: GLSL_VERSION: OpenGL ES GLSL ES 1.00 
cocos2d: GL_MAX_TEXTURE_SIZE: 4096 
cocos2d: GL_MAX_TEXTURE_UNITS: 8 
cocos2d: GL_MAX_SAMPLES: 4 
cocos2d: GL supports PVRTC: YES 
cocos2d: GL supports BGRA8888 textures: YES 
cocos2d: GL supports NPOT textures: YES 
cocos2d: GL supports discard_framebuffer: YES 
cocos2d: GL supports shareable VAO: NO 
cocos2d: CCGraphicsBufferClass: CCGraphicsBufferGLUnsynchronized 
cocos2d: CCGraphicsBufferBindingsClass: CCGraphicsBufferBindingsGL 
cocos2d: CCRenderCommandDrawClass: CCRenderCommandDrawGL 
2016-12-25 22:02:40.880794 256deathes[6797:181672] subsystem: com.apple.coreaudio, category: augraph, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:40.882862 256deathes[6797:181672] subsystem: com.apple.coreaudio, category: audiocomp, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:40.904777 256deathes[6797:181672] subsystem: com.apple.coreaudio, category: aurioc, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:40.906944 256deathes[6797:181672] subsystem: com.apple.coreaudio, category: aurios, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:40.908871 256deathes[6797:181759] subsystem: com.apple.coreaudio, category: aqiotime, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:40.909252 256deathes[6797:181759] subsystem: com.apple.coreaudio, category: aqme, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:40.911241 256deathes[6797:181759] subsystem: com.apple.coreaudio, category: AudioHAL_Client, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:40.925862 256deathes[6797:181759] subsystem: com.apple.coreaudio, category: central, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:41.031 256deathes[6797:181672] Error: -[IOSVersion init]: Cannot parse iOS version string "10.0" 
2016-12-25 22:02:41.037016 256deathes[6797:181672] subsystem: com.apple.coreaudio, category: 3dml, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:41.069 256deathes[6797:181672] cocos2d: animation started with frame interval: 60.00 
2016-12-25 22:02:41.070 256deathes[6797:181672] cocos2d: surface size: 1136x640 
2016-12-25 22:02:41.161 256deathes[6797:181672] cocos2d: surface size: 1136x640 
2016-12-25 22:02:41.164447 256deathes[6797:181672] subsystem: com.apple.BackBoardServices.fence, category: App, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0 
2016-12-25 22:02:41.166402 256deathes[6797:181672] subsystem: com.apple.UIKit, category: Touch, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:44.741523 256deathes[6797:181672] subsystem: com.apple.UIKit, category: Gesture, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:44.742786 256deathes[6797:181672] subsystem: com.apple.UIKit, category: GestureEnvironment, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:44.743157 256deathes[6797:181672] subsystem: com.apple.UIKit, category: GestureExclusion, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 
2016-12-25 22:02:44.884 256deathes[6797:181672] -[CCSprite walk]: unrecognized selector sent to instance 0x7f9b2363b0a0 
2016-12-25 22:02:44.902 256deathes[6797:181672] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CCSprite walk]: unrecognized selector sent to instance 0x7f9b2363b0a0' 
*** First throw call stack: 
(
    0 CoreFoundation      0x000000010318c34b __exceptionPreprocess + 171 
    1 libobjc.A.dylib      0x000000010237521e objc_exception_throw + 48 
    2 CoreFoundation      0x00000001031fbf34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 
    3 CoreFoundation      0x0000000103111c15 ___forwarding___ + 1013 
    4 CoreFoundation      0x0000000103111798 _CF_forwarding_prep_0 + 120 
    5 256deathes       0x0000000101b0ff11 -[_256Deathes onEnter] + 337 
    6 256deathes       0x0000000101a749f7 -[CCTransition startTransition:] + 135 
    7 256deathes       0x0000000101ad3ecc -[CCDirector replaceScene:withTransition:] + 108 
    8 256deathes       0x00000001019f8d75 -[IntroScene onSpinningClicked:] + 181 
    9 256deathes       0x0000000101a52ce7 __32-[CCControl setTarget:selector:]_block_invoke + 87 
    10 256deathes       0x0000000101a52dcd -[CCControl triggerAction] + 109 
    11 256deathes       0x0000000101a69cbc -[CCButton triggerAction] + 156 
    12 256deathes       0x0000000101a69b1c -[CCButton touchUpInside:withEvent:] + 172 
    13 256deathes       0x0000000101a53056 -[CCControl touchEnded:withEvent:] + 118 
    14 256deathes       0x0000000101af25ff -[CCResponderManager touchesEnded:withEvent:] + 623 
    15 256deathes       0x0000000101b1b9c8 -[CCGLView touchesEnded:withEvent:] + 312 
    16 UIKit        0x00000001042450d5 -[UIWindow _sendTouchesForEvent:] + 2747 
    17 UIKit        0x00000001042467c3 -[UIWindow sendEvent:] + 4011 
    18 UIKit        0x00000001041f3a33 -[UIApplication sendEvent:] + 371 
    19 UIKit        0x00000001049e5b6d __dispatchPreprocessedEventFromEventQueue + 3248 
    20 UIKit        0x00000001049de817 __handleEventQueue + 4879 
    21 CoreFoundation      0x0000000103131311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    22 CoreFoundation      0x000000010311659c __CFRunLoopDoSources0 + 556 
    23 CoreFoundation      0x0000000103115a86 __CFRunLoopRun + 918 
    24 CoreFoundation      0x0000000103115494 CFRunLoopRunSpecific + 420 
    25 GraphicsServices     0x0000000108653a6f GSEventRunModal + 161 
    26 UIKit        0x00000001041d5f34 UIApplicationMain + 159 
    27 256deathes       0x00000001019f8e31 main + 65 
    28 libdyld.dylib      0x0000000105b7268d start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

以上是错误消息,和步行方法步行处于person.h,任何帮助,谢谢

+2

请发布堆栈跟踪和完整的错误消息。你应该知道问题发生的确切路线,因为Xcode会显示这一点;如果它没有设置异常断点。 –

+0

首先想到的是改变你的'initWithPicture:'方法来返回'instancetype'而不是'id'。第二件事是确保你已经将'walk'方法放入'Person'类的'@ interface'中。没有更多的信息,不知道还有甚么可能。 – cjrieck

+0

感谢您的建议 –

回答

1

你的问题是initWithPicture方法Person。它不返回Person对象,而是返回CCSprite对象。然后,当你拨打walk时,它会告诉你一个CCSprite不知道该怎么做。

创建一个真实的Person对象作为self并返回。

+0

哦谢谢我认为你是对的,你提醒我,我已经看到了这本书。现在我在外面明天我会尝试,希望它有效。哈哈哈 –

相关问题