TommyBs
TommyBs

Reputation: 9648

SKSpriteNode with a size relative to the screen

I'm trying to create a 'modal' SKSpriteNode that fills most of the screen minus a border on each side. I have a subclass of SKSpriteNode as I need to pass some other info to it for display purposes, so I have a custom init method.

After I initialise my Modal I'm then setting the size as below:

    let modal = Modal(items: [Item])
    let newSize = CGSize(width: (frame.width) - 40, height: (frame.height) - 40)

    modal.size = newSize
    modal.zPosition = 999
    addChild(modal)

The trouble is there is no border at the top or bottom on my Modal, it fills the entire screen vertically. My custom 'init' method of modal calls the super.init passing in a size of 50,50 so even that should be a lot smaller then the screen if that's what it was using but it's not. My game is in landscape mode and I tried switching the width and height above but that fills the entire screen (so there's no border on the left and right either). I know I've not set the position in the above code, but even then I would expect to see a 'border' somewhere evening if it isn't uniform.

This is all done in my main scene file, so frame here relates to the frame of the main game scene.

Any ideas?

Upvotes: 0

Views: 440

Answers (1)

TommyBs
TommyBs

Reputation: 9648

So for anyone else has a similar issue the problem was that my scene was loaded from an SKS file.

The SKS file in question had it's size set to freeform. Changing this to a specific device e.g iPhone 6 and making sure the orientation was set to landscape has fixed the issues with sizing

Upvotes: 0

Related Questions