#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
above is @interface person.h
#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
above is my person.m, however method named walk is empty
#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
this is my another class, person is the subclass of CCSprite, 256Deathes is the subclass of CCSence i am learnning cocos2s-iphone, these code throw a error "signal SIGABRT", and i don't know why, cann't find the reason if delete the code "[personA walk]", it will be OK, so "[personA walk]" must be the reason, anyone can help me?thanks! 《---------------------------------------------------------------------------》 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)
above is the error message, and walk method walk is in the person.h, any help, thanks
Your problem is the initWithPicture
method of Person
. It does not return a Person
object but a CCSprite
object. Then, when you call walk
, it tells you that a CCSprite
doesn't know how to do that.
Create a real Person
object as self
and return that.