Latest 0.2.0
Homepage https://github.com/Dan2552/SpriteKitSeeThrough
License MIT
Platforms ios 8.0
Frameworks UIKit, SpriteKit
Authors

Version
License
Platform

What it is

InvertedCircleMaskNode allows you to create a SpriteKit node that can act as an inverted circular mask. It can be used, for example, to be able to allow the player to see behind walls if your character is behind a wall.

This is possible by using an image of a transparent (alpha 0) circle within a rectangle of the size of the scene. Behind the scenes, this little library will pre-generate this image for you given a position and radius so you don’t have to create any assets manually.

Constants

It’s easier to understand if you see for yourself, so try out the included example app.

Usage

Setup

let cropNode = SKCropNode()

for wall in walls { cropNode.addChild(wall) }

let mask = InvertedCircleMaskNode(size: scene.size,
                                  circleCenter: position,
                                  circleRadius: radius)

cropNode.maskNode = mask

Repositioning and resizing

// Mask position and size
mask.position = CGPoint(...)
mask.rectangleCenter = CGPoint(...)
mask.size = CGSize(...)

// Circle position within mask
mask.circleCenter = CGPoint(...)

Note: because rendering the circle is the expensive part, by design there is no inbuilt way to change the radius of the circle on an initialized node. If you want a resizing mask, consider either scaling the node or initializing different sizes upfront.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

SpriteKitSeeThrough is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "SpriteKitSeeThrough"

Author

Daniel Inkpen, [email protected]

License

SpriteKitSeeThrough is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SpriteKitSeeThrough",
    "version": "0.2.0",
    "summary": "Inverted circular mask SpriteKit node",
    "description": "InvertedCircleMaskNode allows you to create a SpriteKit node that can act as an inverted circular mask. It can be used, for example, to be able to allow the player to see behind walls if your character is behind a wall.nnThis is possible by using an image of a transparent (alpha 0) circle within a rectangle of the size of the scene. Behind the scenes, this little library will pre-generate this image for you given a position and radius so you don't have to create any assets manually.",
    "homepage": "https://github.com/Dan2552/SpriteKitSeeThrough",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Daniel Inkpen": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Dan2552/SpriteKitSeeThrough.git",
        "tag": "0.2.0"
    },
    "social_media_url": "https://twitter.com/Dan2552",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "SpriteKitSeeThrough/Classes/**/*",
    "frameworks": [
        "UIKit",
        "SpriteKit"
    ],
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This