Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKSpriteNode image not displaying

When the view is presented, I would like the image named "Player" (set) which is in my images.xcassets to show on the scene.

Currently the scene just loads up blue. Not sure why, as even when adding a color to change the image color did nothing.

import SpriteKit

class CharacterScene: SKScene {

    var Circle = SKSpriteNode(imageNamed: "Player")

    override func didMoveToView(view: SKView) {
        backgroundColor = SKColor.blackColor()
        Circle.size = CGSize(width: 40, height: 40)
        Circle.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
        Circle.color = SKColor.brownColor()
        self.addChild(Circle)

    }

}
like image 708
tda Avatar asked Nov 19 '25 09:11

tda


1 Answers

You need to initialize the size of CharacterScene before presenting it on the screen. Here you go:

self.scene!.view!.presentScene(CharacterScene(size: self.scene!.size), transition: SKTransition.pushWithDirection(SKTransitionDirection.Up, duration: 0.3))
like image 188
WangYudong Avatar answered Nov 22 '25 04:11

WangYudong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!