Reputation: 1808
I am making a minimap in my game and I need two things to happen.
how can I achieve these things in swift?
Upvotes: 0
Views: 60
Reputation: 16827
Due to no code provided I am going to just talk about the techniques you need to use
To avoid overlaps, you want to useSKCropNode
to create a cropped region.
The idea behind it is really simple.
let cropNode = SKCropNode()
cropNode.maskNode = maskNode <---This is a black and white representation of what you expect the node to draw, where if alpha < .5 means do not draw, and alpha >= .5 means draw. I would start with an SKShapeNode to achieve said effect
cropNode.addChild(miniMap)
To keep the minimap relative to the player is also simple.
Lets say your map is 1024x1024 tiles, so your minimap is 1024x1024 points
Important, both anchor points need to be the same
You take the players position in the tile world, and divide the x by tile width, and the y by tile height, and that gets you the position in minimap world.
Just move the mini map to the negative position you just created (that is both -x and -y) and that will align your mini map to where your player is located.
Upvotes: 1