I am making a game in sprite kit, for the iphone and i am a noob haha. Anyway, this is the code i have so far but instead of the poo appearing where i touch i want it to appear in a place of my choice.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
SKSpriteNode *poo = [SKSpriteNode spriteNodeWithImageNamed:@"poo"];
poo.position = location;
poo.zPosition = 5;
[poo setScale:0.2f];
//next line adds gravity to the poo.
poo.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:poo.size.width/2];
[self addChild:poo];
}
}
Just create a CGPoint
with a desired location and set it as a position:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint yourLocationOfChoice = CGPointMake(200.0f, 200.0f);
SKSpriteNode *poo = [SKSpriteNode spriteNodeWithImageNamed:@"poo"];
poo.position = yourLocationOfChoice;
...
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments