0
votes

I am working on an iOS game using Sprite Kit.

I recently added an SKSpriteNode into my scene and did NOT create a physics body for it. However, when I build and run, when the player's character(which does have a physics body) moves into the SKSpriteNode, it spins and moves away, like it has a physics body -but I didn't create one for the SKSpriteNode.

Even if I type

sprite.physicsBody = nil;

it still behaves like it's part of the simulation.

I wondered if a physics body is created automatically when you make an SKSpriteNode, but I looked at the documentation and searched it on Google and couldn't find anything to suggest that is the case.

Any help or suggestions would be much appreciated.

This is the code I used to create the sprite (the one that should not be affected by the simulation)

-(void)addSprite
{
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"image"];
sprite.position = CGPointMake(40, 30);
sprite.zPosition = 30;
sprite.name = @"spriteName";

[self addChild:sprite];
 }

In another part of the project I have

[self addSprite];

to call the method.

1
Post the code how you create said sprite.LearnCocos2D
@LearnCocos2D I have added the code I used to create the sprite in an editOLZ1
hmmm nothing unusual. You may want to get one of the "physics debug draw" libs that show you where the body shapes are. Maybe you have some other shape that's sized incorrectly or a static shape that wasn't created in counter-clockwise winding.LearnCocos2D
check if your sprite node is not added to a node that has a physical body.Nicolas Manzini

1 Answers

2
votes

Yes every SKSpriteNode comes with a physics body. Its best to change the physics body's properties instead of getting rid of it altogether. If you want your sprite to be on screen and not interact with any other sprite nodes, do the following:

sprite.physicsBody.dynamic = NO;
sprite.physicsBody.collisionBitMask = 0x0;
sprite.physicsBody.contactTestBitMask = 0x0;