0
\$\begingroup\$

How can I set the radius or the hit range of a node initialized with a texture? Of course I can do that with increasing the size of it, but actually I want to do this without resizing the picture itself. This node is moving around the screen with a small speed. This is my code:

func addMonster() { let monster = SKSpriteNode(imageNamed: "MosquitoDrawed") monster.name = predatorNodeName monster.zPosition = 1 // monster.physicsBody = SKPhysicsBody(circleOfRadius: 50.0) monster.position = CGPoint(x: random(-10.0,max: -30.0), y: random(10.0, max:130.0)) addChild(monster) let actualDuration = 7.0 let actionMoveTo = SKAction.moveTo(CGPoint(x: random(500, max:800),y: random(1, max:800) ), duration: NSTimeInterval(actualDuration)) monster.runAction(actionMoveTo,withKey: "move") } 
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Have you tried to initialize your SKPhysicsBody with a rectangle of the size you want?

var node = SKSpriteNode(imageNamed: "node.png") node.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(width: 50, height: 50)) 

That way you can increase the size of the bounding box of your node without using a larger image.

More details in the docs.

Hope it helps!

\$\endgroup\$
4
  • \$\begingroup\$ Great ! I did change the PhysicsBody , but the hit range is still not affected. Also there's another bug that appeared after after this, the node goes up and down fast while moving. \$\endgroup\$ Commented Mar 9, 2016 at 16:27
  • \$\begingroup\$ Without seeing any code, it's a bit hard to help you. You should add it to your question ;) \$\endgroup\$ Commented Mar 9, 2016 at 16:31
  • \$\begingroup\$ Yes, you're right. I just updated my post. \$\endgroup\$ Commented Mar 9, 2016 at 16:33
  • \$\begingroup\$ You are talking about "hit range", but I can't see collision detection in your code. How did you test that the "hit range" was not affected? I suggest you to read the [docs about simulating physics](You should read [the docs] (developer.apple.com/library/ios/documentation/GraphicsAnimation/…) about simulating physics. ). It should give you pointers on what's missing. \$\endgroup\$ Commented Mar 9, 2016 at 16:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.