0

I am running into a problem with my SKView where I am trying to create the illusion of a black circle closing in on my character and then the black circle opening up of the character in a new location. After looking stuff up it appears to be called an oval iris transition. My ViewController looks like this:

import UIKit
import SceneKit
import SpriteKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let scene = GameScene(size: view.bounds.size)
        let skView = view as! SKView
        skView.showsFPS = true
        skView.showsNodeCount = true
        skView.ignoresSiblingOrder = true
        scene.scaleMode = .ResizeFill
        skView.presentScene(scene)
    }

    override func prefersStatusBarHidden() -> Bool {
        return true
    }
}

I think this code is working fine, but when I create the GameScene the problems start. I will only show the important parts of the class, since it gets pretty extensive.

//View Did Load
override func didMoveToView(view: SKView) {

    let backgroundImage = SKSpriteNode(imageNamed: "ground")
    backgroundImage.size = self.scene!.size
    backgroundImage.zPosition = -1
    backgroundImage.position = CGPoint(x: frame.size.width/2, y: frame.size.height/2)
    backgroundImage.zPosition = -1
    addChild(backgroundImage)

    moveJoystick = SKView(frame: CGRect(x: 0, y: size.height - size.width * 0.2, width: size.width * 0.2, height: size.width * 0.2))
    moveJoystick.layer.backgroundColor = SKColor.blackColor().CGColor
    moveJoystick.layer.borderColor = SKColor.blueColor().CGColor
    moveJoystick.layer.borderWidth = 25
    moveJoystick.alpha = 1
    self.view?.addSubview(moveJoystick)

    attackJoystick = SKView(frame: CGRect(x: size.width * 0.8, y: size.height - size.width * 0.2, width: size.width * 0.2, height: size.width * 0.2))
    attackJoystick.backgroundColor = UIColor.redColor()
    attackJoystick.alpha = 0.25
    self.view?.addSubview(attackJoystick)
}

This code ends up creating two views. The moveJoystick view has a blue outline and a grey/white interior. The attackJoystick has a faint grey/white interior because of the the alpha. This shows that only the borderColor property is correctly changing.

QUESTION: I am wondering if there is anyway to change the background color of my SKViews?

  • Question : Why do you use [SKView](https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKView/) to create `attackJoystick` and `moveJoystick`? :) SKView is not meant to be used like that. Please read the docs about its usage. You should use `SKSpriteNode` for your joysticks. – Whirlwind Apr 11 '16 at 02:09
  • I am using them to check whether a touch occurs inside them. Just starting to learn it. They are used at displays, the user doesn't interact with them right now. I am just wondering about the colors with SKViews. – Garrett Haufschild Apr 11 '16 at 13:22
  • You are going in a very wrong direction. Those are meant to render scene's content. What you want is a `SKSpriteNode` or its subclass. Those are perfect for buttons. Look at both answers here http://stackoverflow.com/questions/36465372/how-do-i-detect-wich-skspritenode-has-been-touched/36524132#36524132 Those are ways to detect if buttons are touched. Also follow the link to rakeshbs's answer. It is worth of reading. – Whirlwind Apr 11 '16 at 13:26
  • Thank you I started reading up on the SKViews and SKSprite Nodes because of you and I have realized my error. I will definitely check out the link. – Garrett Haufschild Apr 11 '16 at 14:12

0 Answers0