[self classmethod]
スーパークラスで使用し、それを子クラスで使用 cocos2d に基づいて iPhone ゲームを作成しています。私がこれまでに見た多くのゲームでは、ユーザーのキャラクターが死ぬか消えるとシーンが再開されます。簡単に実行できますが、各子クラスに実装する場合は何らかの処理が必要です。
[[CCDirector sharedDirector] replacescene:[childclass scene]];
でも親クラスに実装できれば1回で済む。私は推測する。だから私は親クラスで試し[self scene]
ましたが、うまくいきません。
親クラスでこれを行うにはどうすればよいですか?
追加された
@interface Parent : CCLayer {}
+(CCScene*)シーン;
-(無効)死んだ;
@終わり
@implementation 親
...
+(CCScene*)シーン{
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
Parent *layer = [Parent node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
...
-(ボイド)デッド {
// キャラクターの死後に呼び出される
[[CCDirector sharedDirector] replacescene:[自分のシーン]]; //これにより、「親は「シーン」に応答しない可能性があります」というエラーが発生します
}
@interface Child1 : 親 {}
+(CCScene*)シーン;
@終わり
@implementation 親
...
+(CCScene*)シーン{
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
Child *layer = [Child node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
...
@終わり
Child1 は Parent の子クラスなので、dead メソッドの実装は必要ないと思いますが、動作しません。そして、Child2、Child3...も。
デッドメソッドを Child1 に移動し、その自己を変更すると機能します -> Child1
私の質問を理解できない場合は、お知らせください。返信ありがとうございます。