0

In GameViewController

 override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidLayoutSubviews() {

        if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
            // Configure the view.
            let skView = self.view as SKView

            var boo = Bool();
            boo = true;
            skView.showsFPS = boo;
            skView.showsNodeCount = boo;
            skView.showsPhysics = boo;

            skView.showsFPS = true
            skView.showsNodeCount = true


            /* Sprite Kit applies additional optimizations to improve rendering performance */
            skView.ignoresSiblingOrder = true

            /* Set the scale mode to scale to fit the window */
            scene.scaleMode = .AspectFill

            skView.presentScene(scene)
        }
    }

And in didMoveToView

var hero = SKSpriteNode(color: UIColor.redColor(), size: CGSize(width: 40, height: 40));
        let hero_body = SKPhysicsBody(rectangleOfSize: hero.size);
        hero.position = CGPoint(x:self.frame.size.width/2, y:50);

        self.addChild(hero)

I dont understand how the position work.. when the Y is 50, the rectangle is not showing. Before in xcode 5 with objective-c in order the node to be in bottom of the screen I would do

-self.frame.size.height/2 + hero.size.height/2

But in here this doesn't work

Ben
  • 1,906
  • 10
  • 31
  • 47
  • 1
    What's your problem , is it that the rectangle isn't showing or is it that the positioning if your hero is not correct? , if the latter one is your problem , make sure that you didn't mess with anchor points , or just write anchorPoint = CGPoint(x:0 , y:0) Which basically means that the origin is bottom righted . – Abdullah Ossama Omari Oct 17 '14 at 22:04

1 Answers1

0

The comment is right. -self.frame.size.height/2 + hero.size.height/2 worked when your anchor point was CGPointMake(0.5f,0.5f); It seems that in your case the anchor point was never changed from (0,0). To change it, use the self.anchorPoint = CGPointMake(0.5f, 0.5f); method in your scene.

Andriko13
  • 992
  • 1
  • 7
  • 34
  • No the problem I have were that the frame width and height were for portrait mode, but the app start in landspace mode – Ben Oct 18 '14 at 20:59