Zephyer
Zephyer

Reputation: 343

SpriteKit and Tiles - working with tiles that are not squares

I've been using JSTileMap to process TMX tile maps in my game, and so far, naturally - i used only square tiles (example in the image attached).

However, i wanted to use ramp-style tiles (also example in the image), which are triangles, and so far - i did not find a way for the game to treat them as triangles (the bounds given to the tiles are squared and obviously that doesnt fit a ramp-style tile).

How do i do this? is it possible with JSTileMap? any other external library? or it must involve specific attention of (as described in here , sort of)

Thanks!

tile example

Upvotes: 0

Views: 313

Answers (2)

jordi sala
jordi sala

Reputation: 1

This is my solution:

in a Gid example:

             case 455: //example gid code
                    //slide to left
                    node!.name = "rampLeft1"
                    let path: CGMutablePathRef = CGPathCreateMutable()
                    CGPathMoveToPoint(path, nil, 0 , 0 )
                    CGPathAddLineToPoint(path, nil, 64 , 64 )//tilesize 64x64
                    CGPathAddLineToPoint(path, nil, 64 , 0 )
                    CGPathAddLineToPoint(path, nil, 0 , 0 )
                    CGPathCloseSubpath(path)

                    //example view
                    var llshape = SKShapeNode(path: path)
                    llshape.position = node!.position
                    llshape.zPosition = 30
                    addChild(llshape)


                    node.physicsBody = SKPhysicsBody(polygonFromPath: path)
                    node.physicsBody?.dynamic = false
                    node.physicsBody?.allowsRotation=false
                    node.physicsBody?.affectedByGravity = false
                    node.physicsBody?.friction = 0.1

Upvotes: 0

CodeSmile
CodeSmile

Reputation: 64477

There are no "triangle" tiles in any tilebased renderer. The gray area in the image simply needs to be transparent. As for collision handling, that's something you need to handle in code based on the tile GID.

Upvotes: 2

Related Questions