Reputation: 251
I'm actually creating a puzzle game for iPad. I would like to create a moving slider containing all the jigsaw parts, independently from the other elements of the game.
I've succeded to create the puzzle on the screen, with the different jigsaw parts all around that user can move with finger. To create the moving slider, I think to use the instruction in my main .swift file.
addChild()
One to create the different elements of the game, standing on the screen and the other to create the moving slider. I've made that successfully, with the different jigsaw parts contained on the slider but I can't make it moved horizontally, even with a touchMoved function on the slider. I've created a 4096 pixels large slider, my scene size is fixed to 2048 x 1536 with a a scene.scalemode set to .AspectFill. I think the problem come from here (maybe).
If I create a much bigger scene (like 4096 x 1536) with the scene.scalemode set to .Fill, I get a deformed picture on the iPad. How to manage that ?
class GameViewController: UIViewController {
override func viewWillLayoutSubviews() {
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = true
let scene = GameScene(size: skView.frame.size)
scene.size.width = 4096
scene.size.height = 1536
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .Fill
skView.presentScene(scene)
}
Thanks by advance for your help,
Upvotes: 0
Views: 428
Reputation: 1995
Although the title and your actual question diverge somewhat, I assume your problem is how to create a SKScene that is larger than the UIView that presents it.
The size of the SKScene is the point resolution that the presenting view (typically an instance of SKView) renders it at. This is before the UIScreen scaling is taken into account, so a scene of 1024*768 in a fullscreen iPad view is rendered at 2048*1536. The SKScene's scaleMode property is only taken into account when the size of the scene and the containing SKView instance is different.
In my opinion, scenarios in which the scene's size differs from the SKView's size are scarce and exceptional. You could compare SKView and SKScene with UIImageView and UIImage, respectively. Only when the aspect ratio differs does the scaleMode impact the rendering/appearance of the UIImage inside the view.
So, how to create a scene bigger than the view? This is a trick question, because you don't need to.
Consider the size of SKScene to be the viewport of the scene. SKNodes inside the scene are not restricted to be positioned only inside the scene's viewport. With an SKScene of size 1024*768, it is perfectly legit to create an SKSpriteNode (say, of size 20*20) and position it at:
Upvotes: 1