4

I hope we can figure out how to get around this interesting challenge with a game we are designing in an isometric style. Any help would be so awesome!

QUESTION

Is there a way to change the bounding box frame from a square to another shape? Maybe using a mask?

PROBLEM

Our problem is that we need our node's tappable area NOT to be square. Since we are tiling the nodes, their bounding boxes overlap each other, and we cannot accurately tap on the tile that we want. Hopefully our graphic below will show you what we are designing, our problem, and what our tappable area needs to be.

enter image description here

Is there a way to change this in Sprite Kit, or is it not possible with sort of isometric style?

Thanks again in a advance.

Lord Varlin
  • 834
  • 1
  • 8
  • 13
  • I'm very curious to see how this problem could be solved. An SKSpriteNode's frame is a readonly property, so there's no way to change it. A frame can never be anything besides a rectangle and can't be rotated. I think you will have to create a custom shaped button with UIBezierPaths and this great SKButton class: http://stackoverflow.com/questions/19082202/setting-up-buttons-in-skscene/19199748#19199748 – Ivan Lesko Mar 08 '14 at 05:22
  • I know this is late but I came up with a solution to a similar problem I was having. http://stackoverflow.com/questions/23051961/detecting-touches-in-a-triangular-grid-of-buttons/23052381#23052381 Essentially, create a subclass of SKSPriteNode and give it a UIBezierPath property the shape of the diamond. In your touchesBegan: method, do a check if the touch's position lands inside of the UIBezierPath property. Hope this helps someone out! – Ivan Lesko Apr 24 '14 at 03:59

2 Answers2

1

I have been deep down this path, I can say it is a LOT easier to implement your own hit detection than trying to force spritekit into doing what you're planning.

It's not THAT hard tough. Simply do a custom hittest function on your tiles and loop through them all on mouse down and test them all.

There's a pretty easy algorithm for testing your shape but in all fairness you can probably just test for the inner circle of the diamond shape, so simply test if the distance to the center of the sprite is < radius of click circle. Easy peasy.

Theis Egeberg
  • 2,556
  • 21
  • 30
0

The SKPhysicsBody can be created by path [SKPhysicsBody bodyWithEdgeLoopFromPath:(CGPath)]; You will have to tweak the path to get the shape you want, but if you are only using it for tiles, it should be fine.

Check if Node.PhysicsBody contains touchpoint.

If you require the method let me know.

Wharbio
  • 1,355
  • 10
  • 16