1
votes

Click ----> for pic :) This is my GameScene as of now, its hard coded and linked to a Global File of that holds scene data

  override func didMoveToView(view: SKView) {
      super.didMoveToView(view)   



    playButton.hidden = true

    let background = SKSpriteNode(imageNamed: "us-flag")

    background.position = CGPoint(x: size.width/2, y: size.height/2 )

    background.blendMode = .Replace
    background.zPosition = -1
    background.size = self.size

    addChild(background)

    gameOverButton = SKSpriteNode(imageNamed: "gameOver")
    gameOverButton.position = CGPoint(x: size.width / 2 , y: scene!.frame.height - 200)
    gameOverButton.zPosition = 3
    gameOverButton.xScale = 1.5
    gameOverButton.yScale = 1.5

    gameOverButton.hidden = true

    addChild(gameOverButton)

    gameScore = CustomSKLabel(fontNamed: "Chalkduster")
    gameScore.text = "Votes: 0"
    gameScore.position = CGPoint(x: Int((self.size.width - gameScore.frame.width )) , y: 22)
    gameScore.horizontalAlignmentMode = .Center
    gameScore.fontSize = 27
    gameScore.zPosition = 3
    gameScore.fontColor = SKColor.whiteColor()

    addChild(gameScore)



 /*   for i in 0 ..< 5 { createSlotAt(CGPoint(x: 160 + (i * 170), y: 410)) }
    for i in 0 ..< 4 { createSlotAt(CGPoint(x: 240 + (i * 170), y: 320)) }
    for i in 0 ..< 5 { createSlotAt(CGPoint(x: 160 + (i * 170), y: 230)) }
    for i in 0 ..< 4 { createSlotAt(CGPoint(x: 240 + (i * 170), y: 140)) }

    RunAfterDelay(1) { [unowned self] in
        self.createEnemy() */


    for i in 0 ..< 5 { createSlotAt(CGPoint(x: 680 + (i * 170), y: 535)) }
    for i in 0 ..< 4 { createSlotAt(CGPoint(x: 715 + (i * 170), y: 435)) }
    for i in 0 ..< 5 { createSlotAt(CGPoint(x: 680 + (i * 170), y: 335)) }
    for i in 0 ..< 4 { createSlotAt(CGPoint(x: 715 + (i * 170), y: 245)) }
    RunAfterDelay(1) { [unowned self] in
        self.createEnemy()

my game scene is hard coded all other scenes are built in the Scene Editor, my attempt was a universal app, yet decided to release for iPhone only it used to work properly, until ported the game over completely to SpriteKit

GameViewController:

 if let scene = WelcomeScene (fileNamed:"WelcomeScene") {

    let skView = self.view as! SKView
    skView.showsFPS = Constant.DEV.DEBUG
    skView.showsNodeCount = Constant.DEV.DEBUG
    skView.ignoresSiblingOrder = true
    scene.scaleMode = .AspectFit
    skView.presentScene(scene)



    }


   }


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

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

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return [UIInterfaceOrientationMask.LandscapeRight ,UIInterfaceOrientationMask.LandscapeLeft]

}

}

GlobalSceneDataSwift:

 if let scene = sceneToLoad {
    scene.size = size
    scene.scaleMode = scaleMode
    let transition = SKTransition.fadeWithDuration(3)
    self.view?.presentScene(scene, transition: transition)

      }
  }
}

Before I moved to SpriteKit everything was embedded into the GameViewController, I used it as regular ViewController, and embedded subviews, to facilitate the GameScene, worked great until about turn four, when cpu dropped to zero and memory spiked. So I went with SpriteKit. All other scenes look fine for iPhone. Except the GameScene. It pulls in the wrong assets and the scene looks like the picture.

Old code from GameScene with UIKit and SpriteKit Mix in case that helps:

    let deviceIdiom = UIScreen.mainScreen().traitCollection.userInterfaceIdiom

    switch (deviceIdiom) {

    case .Pad:

        let active = SKSpriteNode(imageNamed: self.name!)
        active.name = self.name
        active.size = CGSizeMake(100, 100)
        active.position = CGPoint(x: Int( active.frame.width + 0), y: Int(active.frame.height + 10))
        addChild(active)

    case .Phone: break

    case .TV:
        let active = SKSpriteNode(imageNamed: self.name!)
        active.name = self.name
        active.size = CGSizeMake(100, 100)
        active.position = CGPoint(x: Int( active.frame.width + 12), y: Int(active.frame.height + 12))
        addChild(active)

    default: break

    }

    let w12 = Int(self.size.width / 12)
    let w6 = Int(self.size.width / 6)
    let w5 = Int(self.size.width / 5)
    let h3 = Int(self.size.height / 3)

    for i in 0 ..< 5 { createSlotAt(CGPoint(x: w12 + (i * w5), y: h3 + 120 )) }
    for i in 0 ..< 4 { createSlotAt(CGPoint(x: w6  + (i * w5), y: h3 + 60)) }
    for i in 0 ..< 5 { createSlotAt(CGPoint(x: w12 + (i * w5), y: h3 + 10 )) }
    for i in 0 ..< 4 { createSlotAt(CGPoint(x: w6  + (i * w5), y: h3 - 50)) }

    RunAfterDelay(1) { [unowned self] in
        self.createEnemy()
    }
}

Im sticking with SpriteKit, solo because honestly its been a lot more stable, with transitioning scenes especially ones with a lot moving parts. Scene Size 1920 * 1080 back ground images match that setup, I chose that size in case I decide to port to Apple TV later. Thanks Again for everyone who takes the time to answer questions on here. Pic included

Legacy UPDATE Checked Assets and noticed the BackGround Size was off, being this part of the game was created two months ago I forgot that I manually adjusted the picture in code**** Has not solved the problem completely yet, my images show, and the background does not look like a Picnic Blanket.

1

1 Answers

0
votes

When reviewing my code I noticed my lack of comments in the original project I created. I bring this up because if properly commented, I would noticed the changes to take into effect when port from UIKIT + SpriteKit mix to using strictly SpriteKit.

1st) As for mention I was thinking of doing a universal app, as specified in the old code for the GameViewController. The embedded views inside a view controller, the collection view, the SkContainer view, UIImage View, where all created using the constraints of the GameViewController.

2.) The game scene sks was at a aspect ratio for Apple TV, and the CGPoints where utilized make the assets fit that size. (smh)

3.) Each node had a different scale factor to accomplish rendering the right view, these images were populated from a Database Swift file, I posted in a earlier post, about SKEmitters,

4.) Porting to SpriteKit, you lose some of the cool UIButton functionality, yet transitioning scene through Segues. (CAUSES MEMORY SPIKES AND CPU DROPS) IF You do not know what you are doing.

   Node.xScale = 0.5
   Node.yScale = 0.5

was the code I needed to render the proper sizes, as well as adjusting my assets to conform to my dimensions. Sometimes it comes down to a small piece of code, out of 30 swift files there it was. If I had //commented their purpose I would of saved myself hours of "learning experience"

SpriteKit transformation using the scene editor, can be fun, and the code amount can be rather small or large depending on the game. Subclass your buttons, in a touches began method, if there is a lot of them, and use a global scene/data base/or a dict to store data, to avoid strong references.

Finally: Tutorials are awesome you get a bunch of code you make a project you get excited, take the time to go line by line to learn "Exactly" what the code is doing. Comment the discoveries. So if you ever have to refactor a project you are a enlighten coder, not reaching for straws in the dark.

(had a few redbulls) :)

Legacy