Reputation: 523
I'm working on an iOS game and I want the clowns to spawn outside of the scene, then make their way down. What I had in mind was to create them all, and place them 360 pixels apart on the non-visible scene.
Like this:
SKSpriteNode *clown = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:@"clown.png"] size:CGSizeMake(40, 40)];
RandomPosition = arc4random() %248;
RandomPosition = RandomPosition + 34;
clown.position = CGPointMake (RandomPosition, self.frame.size.height + 360);
clown.zPosition = 1.0;
clown.name = @"clown";
[self addChild:clown .png];
Note the first clown is placed 360px above the top of the scene. I wanted to do this for 9 clowns, so the second one would be 720px above the scene, 3rd 1080px, etc... But before I even got to that I noticed that this one wasn't even working. If I set the 360 to 40 it works, but no value higher than that? Why is this. How can I fix this code to work? Is there a more efficient way of doing what I'm trying to do?
Perhaps theres a way to do it with an array?
Heres the scrolling method incase anyone needs it:
[self enumerateChildNodesWithName:@"clown" usingBlock:^(SKNode *node, BOOL *stop) {
SKSpriteNode *mercury = (SKSpriteNode *)node;
CGPoint debVelocity = CGPointMake(0, -DEB_VELOCITY);
CGPoint amtToMove = CGPointMultiplyScalar(debVelocity,_dt);
clown.position = CGPointAdd(amtToMove, clown.position);
if (clown.position.y > self.frame.size.height + 40) {
[clown removeFromParent];
}
}];
Thanks.
Upvotes: 1
Views: 68
Reputation: 34829
Umm, these lines would seem to be a problem for clowns more than 40 pixels above the frame.
if (clown.position.y > self.frame.size.height + 40) {
[clown removeFromParent];
Upvotes: 2