这是一些我无法理解的问题...... 我想将一个敌人的精灵从上到下移动,但是敌人的精灵在不同的级别并且不能移动它。
这是通过Enemyscene在GameScene中添加精灵的代码 这是Enemy.m的代码
#import "Enemy.h"
#import "GameScene.h"
@implementation Enemy
@synthesize theGame,newSprite,lastTimeFired,firingSpeed,fireInterval,movementSpeed,launched,hp,maxHp;
-(id)initWithGame:(GameLayer *)game
{
self=[super init];
if(self !=nil)
{
CGSize size=[[CCDirector sharedDirector]winSize];
self.theGame=game;
self.lastTimeFired=0;
NSLog(@"Enemy INIT ");
int random=arc4random()%3+1;
newSprite=[CCSprite spriteWithFile:[NSString stringWithFormat:@"enemy%d.png",random]];
newSprite.position=ccp(100,200);
[theGame addChild:newSprite];
switch (random)
{
case 1:
movementSpeed=5;
fireInterval=-1;
break;
case 2:
movementSpeed=10;
fireInterval=-1;
break;
case 3:
movementSpeed=7;
fireInterval=-1;
break;
case 4:
movementSpeed=3;
fireInterval=-1;
break;
default:
movementSpeed=5;
fireInterval=-1;
break;
}
}
return self;
}
我想把这个Enemy sprite移动到GameScene层,这里是代码 GameScene.m
#import "GameScene.h"
#import "Hero.h"
#import "Enemy.h"
#define STARTING_LIVES 3;
@implementation GameScene
-(id) init
{
self =[super init];
if(self !=nil)
{
[self addChild:[GameLayer node]];
}
return self;
}
-(void) dealloc
{
[super dealloc];
}
@end
@implementation GameLayer
-(id)init
{
if(self=[super init])
{
Hero *hero=[[Hero alloc]initWithGame:self];
Enemy *e=[[Enemy alloc]initWithGame:self];
lastTimeEnemyLaunched=0;
enemyInterval=20;
lives=3;
[self schedule:@selector(doThis)];
NSLog(@"After Schedule");
}
return self;
}
-(void)doThis
{
Enemy *e;
[e update];
}
@end
请帮助我,我是cocos2d游戏开发的新手...... 当我在模拟器中运行此代码而不是错误时给出
此代码提供EXC_BAD_ACCESS
-(void) update: (ccTime) dt
{
if( elapsed == - 1)
elapsed = 0;
else
elapsed += dt;
if( elapsed >= interval ) {
impMethod(target, selector, elapsed); //this code gives EXC_BAD_ACCESS
elapsed = 0;
}
}
请帮帮我.... 感谢