#spritekit

How to Display Image in SKShapeNode

by

I have been using SKShapeNode extensively to draw quick graphics by filling them with CGPaths for quick visual debugging and making prototypes. For example I can create procedural mountains quickly with SKShapeNode. In early times of spritekit SKShapeNode didn’t have way to render images on it. We have fillTexture available now that allows texture to fill the shape.


let shapeNode = SKShapeNode()
shapeNode.fillTexture = SKTexture(imageNamed: “testImage")

But, Our SKShapeNode is displaying nothing.

Why is that?

CONTINUE READING

AVAudioPlayer not playing any sound

by

The most common culprit causing AVAudioPlayer not playing sound is ARC. When my audio player's scope is just within a function ARC deallocates the memory before playing sound after function is called. Here is an example code:


func playSoundEffect(assetName: string?) {
    if let sound = assetName{
        if let asset = NSDataAsset(name:sound){
            
            do {
                // Use NSDataAsset's data property to access the audio file stored in Sound.
                let soundEffect = try AVAudioPlayer(data:asset.data, fileTypeHint:"wav")
                // Play the above sound file.
                soundEffect?.play()
            } catch let error as NSError {
                print(error.localizedDescription)
            }
        }
    }
}

CONTINUE READING

Use AVAudioPlayer to play sound effects

by

Right now I am at the stage where I am writing foundation to manage my sound effects and background music for my upcoming game. I found two most popular way to play sound effects in SpriteKit:

  • SKAction
  • AVAudioPlayer

After using both I found myself more flexible and comfortable with AVAudioPlayer for following reasons that I am grabbing from Apple’s documentation but it helds true:

Using an audio player you can:
  • Play sounds of any duration
  • Play sounds from files or memory buffers
  • Loop sounds
  • Play multiple sounds simultaneously, one sound per audio player, with precise synchronization
  • Control relative playback level, stereo positioning, and playback rate for each sound you are playing
  • Seek to a particular point in a sound file, which supports such application features as fast forward and rewind
  • Obtain data you can use for playback-level metering
CONTINUE READING

Blurry Pixel Font in SpriteKit bug

by

It's amazing how modern Pixel Art captures the true simplicity yet also expressing creative masterpieces. I find so much solace staring at the world presented by games like Stardew Valley and Kynseed.

In my spare time I am making 2d pixel art game for iOS and macOS for my hobby. I found a free pixel art font called PixelDigivolve to use it for my texts. There was this behaviour that caught my attention where font was being rendered very blurry. The edges were not sharp.

SpriteKit has filtering mode called nearest-neighbour for rendering textures.

CONTINUE READING

Recommended posts