私の GameScene.m ファイル:
#import "GameScene.h"
// Needed to obtain the Navigation Controller
#import "AppDelegate.h"
#pragma mark - GameScene
// GameScene implementation
@implementation GameScene
// on "init" you need to initialize your instance
-(id) init
{
self = [super init];
if (self != nil)
{
[self addChild:[GameLayer node]];
}
return self;
}
- (void) dealloc
{
[super dealloc];
}
@end
@implementation GameLayer
@synthesize hero;
-(id) init
{
if( (self=[super init] ))
{
hero = [[Hero alloc] initWithGame:self];
}
return self;
}
-(void) dealloc
{
[super dealloc];
}
@end
私の GameScene.h ファイル:
#import <GameKit/GameKit.h>
// When you import this file, you import all the cocos2d classes
#import "cocos2d.h"
// GameScene
@interface GameScene : CCScene
{
}
@end
@class Hero;
@interface GameLayer : CCLayer
{
Hero * _hero;
NSMutableArray * _bullets;
bool _playerFiring;
NSMutableArray * _enemies;
float _lastTimeEnemyLaunched;
float _enemyInterval;
int _score;
int _lives;
int _bombs;
int _level;
}
@property (nonatomic,retain) Hero * hero;
@property (nonatomic,readwrite) bool playerFiring;
@property (nonatomic,readwrite) float lastTimeEnemyLaunched;
@property (nonatomic,readwrite) float enemyInterval;
@property (nonatomic,retain) NSMutableArray * enemies;
@property (nonatomic,retain) NSMutableArray * bullets;
@property (assign,readwrite) int score;
@property (assign,readwrite) int lives;
@property (assign,readwrite) int bombs;
@property (assign,readwrite) int level;
@end
私の Hero.h ファイル:
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "GameScene.h"
@class GameLayer;
@interface Hero : CCNode
{
CCSprite * mySprite;
GameLayer * theGame;
float _lastTimeFired;
float _fireInterval;
float _firingSpeed;
float _movementSpeed;
}
@property (nonatomic,retain) CCSprite * mySprite;
@property (nonatomic,retain) GameLayer * theGame;
@property (nonatomic,readwrite) float lastTimeFired;
@property (nonatomic,readwrite) float fireInterval;
@property (nonatomic,readwrite) float firingSpeed;
@property (nonatomic,readwrite) float movementSpeed;
@end
そして私の Hero.m ファイル:
#import "Hero.h"
@implementation Hero
@synthesize theGame,mySprite;
-(id) initWithGame:(GameLayer *)game
{
self = [super init];
if(self != nil)
{
// ask director for the window size
CGSize size = [[CCDirector sharedDirector] winSize];
self.theGame = game;
mySprite = [CCSprite spriteWithFile:@"hero.png"];
[theGame addChild:mySprite z:2];
[mySprite setPosition:ccp(size.width/2,50)];
self.lastTimeFired = 0;
self.fireInterval = 3;
self.firingSpeed = 10;
self.movementSpeed = 5;
}
return self;
}
-(void) dealloc
{
[super dealloc];
}
@end
そして、ここに私の問題があります:私は2つの警告を受け取ります.
「-(id) initWithGame:(GameLayer *)game」行を Hero.h インターフェイスに追加しようとしましたが、機能しません。その行を追加しようとしましたが、- の代わりに + を使用しましたが、何もありません。
ヒーローが画面に表示されずに終わります。この問題を解決する方法を知っている人はいますか (最新バージョンの Xcode を使用しています)。