根本的な何かが欠けているのかもしれません。Dude という CCSprite を継承するクラスを作成しました。私のレイヤーにオブジェクト dude を追加すると、正しく機能します。画面に表示されます。画面に触れるまで、すべてがうまくいきます。どういうわけか、私のクラス Dude のメソッド「Jump」に到達できません。
私が得るエラーは次のとおりです。
-[CCSprite Jump::]: 認識されないセレクターがインスタンス 0xf4611a0 2012-05-18 10:20:40.870 bitman[1732:10a03] に送信されました]: 認識されないセレクターがインスタンス 0xf4611a0 に送信されました'
誰かが私を正しい方向に向けることができますか? エラーが [Dude Jump::] ではなく [CCSprite Jump::] と表示されるのはなぜですか? 私が見逃しているのは何ですか?
次のようなレイヤー設定があります(関連するコードのみ):
#import "GameplayLayer.h"
#import "Dude.h"
@implementation GameplayLayer
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
GameplayLayer *layer = [GameplayLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
-(id)init{
self=[super init];
if(self!=nil){
dude=[[Dude alloc]init] ;
dude.position=ccp(screenSize.width/2,screenSize.height/2);
[self addChild:dude];
fJumpHight=screenSize.height/3;
fJumpTime=.2f;
}
return self;
}
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority: swallowsTouches:YES];
}
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
[dude Jump:40:3];
return YES;
}
@end
次のようにクラス Dude をセットアップします。
#import "CCSprite.h"
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface Dude : CCSprite
-(void) Jump:(float)fHight:(float)fTime;
@end
男.m:
#import "Dude.h"
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@implementation Dude
-(id)init{
self=[super init];
if(self!=nil){
CGSize screenSize =[CCDirector sharedDirector].winSize;
self=[[CCSprite spriteWithFile:@"something.png"]retain];
self.position=ccp(screenSize.width/2,screenSize.height*0.333f);
}
return self;
}
-(void) Jump:(float)fHight:(float)fTime{
NSLog(@"JUMP!");
//Jump actions
}
@end