Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i move continuos enemy sprite top to bottom???
    text
    copied!<p>Here is some problem which I can not understand... I want to move one enemy sprite top to bottom but enemy sprite is in different class and can not move it.</p> <p>Here is code of add sprite in GameScene through Enemyscene This is code of Enemy.m</p> <pre><code>#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; } </code></pre> <p>And I want to move this Enemy sprite into GameScene layer and here is the code GameScene.m</p> <pre><code>#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 </code></pre> <p>Please help me i am new in cocos2d game development... when i am run this code in simulator than it gives on error </p> <p>this code gives EXC_BAD_ACCESS</p> <pre><code> -(void) update: (ccTime) dt { if( elapsed == - 1) elapsed = 0; else elapsed += dt; if( elapsed &gt;= interval ) { impMethod(target, selector, elapsed); //this code gives EXC_BAD_ACCESS elapsed = 0; } } </code></pre> <p>Please Help me.... Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload