Wednesday, 21 August 2013

Placing sprites in back or front

Placing sprites in back or front

I understand the "z" function can be used to send sprites either backward
or forward, and in this case I am trying to place the stars in my game at
the very back. Below is my code, and the following is an example I picked
up online: [layer addChild:dog z:0];
- (void)addStar
{
SGGSprite * star = [[SGGSprite alloc] initWithFile:@"Star.png"
effect:self.effect];
[self.children addObject:star];
int minY = star.contentSize.height/2;
int maxY = 5000 - star.contentSize.height/2;
int rangeY = maxY - minY;
int actualY = (arc4random() % rangeY) + minY;
star.position = GLKVector2Make(480 + (star.contentSize.width/2), actualY);
int minVelocity = 10.0/4.0;
int maxVelocity = 200.0/2.0;
int rangeVelocity = maxVelocity - minVelocity;
int actualVelocity = (arc4random() % rangeVelocity) + minVelocity;
star.moveVelocity = GLKVector2Make(-actualVelocity, 0);
[self.stars addObject:star];
}

No comments:

Post a Comment