Uncertain about CGRectSizes when pinning elements to ScrollingNode
I've been playing around with trying to pin the "Top" and "Bottom" labels to the JADMainScene Scrolling Node to make it adaptable for different device sizes and so far I can't quite figure out how SpriteKit is rendering the ScrollingNode in terms of its rect size.
Basically I want to understand the logic in positioning the labels this way:
topLabelNode.position = CGPointMake(50, 2000-50);
bottomLabelNode.position = CGPointMake(50, 50);
If I wanted not to use magic numbers, how would you suggest I go about it?
Hi Iris,
If I understand correctly, you should be able to get what you need by making the "Top" and "Bottom" labels children of the scene (or another non-scrolling SKNode) rather than children of the the scrolling node.
For an example, take a look at the JADMainScene::initWithSize: method. At the very end of that method is the code to add a button that remains fixed as everything else scrolls:
SKLabelNode* otherSceneNode = [SKLabelNode node];
otherSceneNode.text = @"Switch To Part Scrolling Scene";
otherSceneNode.name = @"OtherSceneNode";
otherSceneNode.position = (CGPoint){800,100};
[self addChild:otherSceneNode];
Hey Jen,
Not quite. I don't want "Top" or "Bottom" to be fixed on the screen. I still want them to appear at the top and bottom of the scrolling node as their names suggest, but to have this position be fixed relative to the scrolling node when I view it on various devices (such as iPad 2, iPad Air, etc.) Basically I'm trying to understand the logic behind how you came up with the numbers you used in sizing and positioning.
Hi Iris,
I'll admit, it's been a while since I looked at this code, and I didn't try it on any other devices except my iPad Air. So I don't completely understand what it means for the buttons to be not fixed on the screen but fixed relative to the scrolling node.
Basically the "magic numbers" (2000,50,etc) were just arbitrary numbers to make the content area big enough to require scrolling. On the "Full Scrolling Scene" the content area needed to be bigger than the entire screen in order to require scrolling, and on the "part scrolling scene" this viewable area needed to be bigger than the 300x300 window. The JADSKScrollingNode itself takes care of the work of calculating the full content area of all of its nodes (see JADSKScrollingNode::minYPosition) so that the scrolling stops at the correct place when the user scrolls to the top and bottom. Any node that is a child of JADSKScrollingNode will scroll with all the rest of the content of the scrolling node. If you don't want it to scroll, it can't be a child of that node.
Hope this helps!
Jen
On Wed, Jul 8, 2015 at 1:13 PM, Iris Zhang [email protected] wrote:
Hey Jen,
Not quite. I don't want "Top" or "Bottom" to be fixed on the screen. I still want them to appear at the top and bottom of the scrolling node as their names suggest, but to have this position be fixed relative to the scrolling node when I view it on various devices (such as iPad 2, iPad Air, etc.) Basically I'm trying to understand the logic behind how you came up with the numbers you used in sizing and positioning.
— Reply to this email directly or view it on GitHub https://github.com/JenDobson/SpriteKitScrollingNode/issues/1#issuecomment-119717876 .
Hi Jen,
Yep, that actually helps matters a lot. Would you mind if I worked on getting this code compatible for most devices? I usually test on the iPad 2 which is why I ran into issues with the positioning. I can probably do a pull request at some point.
Iris
Hi Iris,
Feel absolutely free to do anything you think it needs. Honestly I haven't been doing any iOS coding in a little while, so I'm not sure if I plan to touch it anytime soon.
Just so you're warned, if I remember correctly the example on github gets kind of clunky when you when you try to remove the scrolling node from the scenes. The gesture recognizers that allow you to scroll are attached to the view, so if you remove the scrolling node from the scene or remove the scene from the view, the gesture recognizers don't get cleared gracefully unless you tell the view to clear them.
Anyway, after making the github example I reworked it a bit to clean up that issue and also some other problems with touches being received outside of the viewable window. So if you're interested I think have a more robust and more featured version of the scroll node (ie horizontal scrolling, zooming and panning) that I can try to get into shape and share with you. It's part of an app that I never finished, so I'd need a few days to separate the scrolling functionality from the rest of the app. (I was kind of in the middle of things when I stopped.) If you want I can share the repository with you as is, and then if you think it would be useful let me know, and I can do a little clean up.
On Wed, Jul 8, 2015 at 2:11 PM, Iris Zhang [email protected] wrote:
Hi Jen,
Yep, that actually helps matters a lot. Would you mind if I worked on getting this code compatible for most devices? I usually test on the iPad 2 which is why I ran into issues with the positioning. I can probably do a pull request at some point.
Iris
— Reply to this email directly or view it on GitHub https://github.com/JenDobson/SpriteKitScrollingNode/issues/1#issuecomment-119732105 .
Hey Jen,
Thanks so much for explaining! Yup, all this sounds immensely helpful. Would you mind sharing that private repo?
I'm working on a game where I want to create a scrolling menu of "achievements" in an SKScene and I wanted to avoid messing with mixing UIScrollViews with SpriteKit, so your solution seemed like the most elegant. I wouldn't have a need so much for horizontal scrolling or zooming/panning, but those other fixes you mentioned would be useful.
I also noticed that you used "touchesBegan/Ended" from within the scene but assigned a UIPanGestureRecognizer to the actual scrollingNode. My entire game uses UIGestureRecognizers so do you think that would interfere with the way the scene receives touches? (I'm working on testing out each of these issues so it's totally okay if you don't have the time to answer.)
Thanks so much!
Hi Iris,
I just sent you an invitation to view the repository on bitbucket. Over the next few days I'll get it into shape so it's a little more readable. I'll try to separate the scrolling window functionality from the rest of the app.
As for whether the gesture recognizers will interfere with the rest of the app, with this implementation that I'm sending now, I don't think so. I'm pretty sure that the touchesBegan/Ended was able to filter out touches that were not over the scrolling window. I'll keep an eye out for this as I'm going over the code.
Best, Jen
On Thu, Jul 9, 2015 at 9:31 AM, Iris Zhang [email protected] wrote:
Hey Jen,
Thanks so much for explaining! Yup, all this sounds immensely helpful. Would you mind sharing that private repo?
I'm working on a game where I want to create a scrolling menu of "achievements" in an SKScene and I wanted to avoid messing with mixing UIScrollViews with SpriteKit, so your solution seemed like the most elegant. I wouldn't have a need so much for horizontal scrolling or zooming/panning, but those other fixes you mentioned would be useful.
I also noticed that you used "touchesBegan/Ended" from within the scene but assigned a UIPanGestureRecognizer to the actual scrollingNode. My entire game uses UIGestureRecognizers so do you think that would interfere with the way the scene receives touches? (I'm working on testing out each of these issues so it's totally okay if you don't have the time to answer.)
Thanks so much!
— Reply to this email directly or view it on GitHub https://github.com/JenDobson/SpriteKitScrollingNode/issues/1#issuecomment-120059828 .
Hey Jen,
I just saw the Bitbucket notifications. Thanks for being so responsive! I totally understand having a busy schedule.
What a coincidence--the game I'm working on is for kids as well, although a slightly older demographic. :)
Best, Iris