Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpriteKit and UIScrollView and HUD

I am trying to make small iOs game. The user will be presented with a scene that is larger that the screen size of the device. I believe the correct way to handle this is to create the scene and place it inside a scroll view, so the user can scroll to see the entire scene (maybe even scroll in and out to see more detail). However I have been unsuccessful at this.. this is the code:

- (void)viewWillLayoutSubviews
{
    // Configure the view.
    SKView * skView = (SKView *)self.view;
    if (!skView.scene) {
        skView.showsFPS = YES;
        skView.showsNodeCount = YES;

        // Create and configure the scene.
        // the size will eventually come from the levels file
        SKScene * scene = [[PSMainGameScene alloc] initWithSize:skView.bounds.size andLevel:0];
        scene.scaleMode = SKSceneScaleModeAspectFill;

        // TODO Add ambiental music

        // Present the scene.
        [skView presentScene:scene];
    }

}

This seems to add the scene and I am able to scroll but scene has no sprites, even thou the skview should draw them (in the corner, after scrolling I am able to see the frame rate 11fps(why is this so small), and 0 sprites)when added outside of a scrollview the sprites are visible).

I would also like to add a HUD : several buttons that will hover in the same place no matter where the user scrolls/zooms ... I have seen an example without the scroll view where thouchesDidMove was used to scroll the SKView , I don't think this is the way to go... Does anyone know the best way to get this done? Or why is my code not working? Thanks

like image 359
user1028028 Avatar asked Dec 28 '25 16:12

user1028028


2 Answers

I answered a similar question here: What is the right way to create scrollable table in SKSpriteKit?

To summarize - I suggest building upon ScrollKit. On top of that I recommend flipping the UIScrollView Y-coordinates to match SpriteKit's coordinate system, as well as using a custom SKNode (example of such a node here) that allows to set its contentOffset.

like image 167
Janis Kirsteins Avatar answered Dec 31 '25 05:12

Janis Kirsteins


Have a look at this project on GitHub. It shows an example of using a UIScrollView in a SpriteKit project.

https://github.com/bobmoff/ScrollKit

like image 23
ZeMoon Avatar answered Dec 31 '25 05:12

ZeMoon



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!