Hello, This is my class for my enemies:
+(id)SEnemy
{
return [[self alloc] initEnemy];
}
-(id)initEnemy
{
self = [super initWithFile:@"enemy2.png"];
if(self != nil)
{
body = cpBodyNew(50.0f, INFINITY);
shape = cpCircleShapeNew(body, 24.5f, cpvzero);
CPCCNODE_MEM_VARS_INIT(shape)
shape->e = 0.0;
shape->u = 0.7;
shape->data = self;
shape->collision_type = 3;
self.ignoreRotation = YES;
}
return self;
}
-(void) Move
{
id actionMove = [CCMoveBy actionWithDuration:3 position: cpv(10, 0)];
[self runAction:[CCRepeatForever actionWithAction:[CCSequence actions:actionMove, [actionMove reverse], nil]]];
//[self applyImpulse:ccp(-1000, 0)];
}
-(void) setPosition:(cpVect)pos
{
// Sync Chipmunk with sprite
[super setPosition:pos];
shape->body->p = pos;
}
@end
and this is in my gamelayer to setup my enemies:
enemy = [Enemy SEnemy];
enemy.position = cpv(x, y);
[smgr addShape:enemy.shape];
[self addChild:enemy];
[_enemies addObject:enemy];
where _enemies is a NSMutableArray. To move my enemies I call this in my gameloop:
for (cpCCSprite *target in _enemies)
{
[target Move];
}
However, by enemies jump all over the place as they move, I think they are fighting the gravity. I want them to use the gravity but also the actions to move them. Does anybody have a way to encapsulate enemies and make them move?