Im making a scene for my game. Right now i`m working on the view for IPhone 5-5c-5s the orientation is in landscape. But the view was not big enough for my scene, so i made the simulated size to freeform so i could choose the width for the scene. (Im using a normal Viewcontroller).
In the game you are supposed to move an image to another image without colliding with obstacles. The users playing the app are going to move an image from one side of the screen all the way over to the other side to the other image to win.
But when my image moves, the view doesnt follow with my image. How do you do that?
I would be so thankful for any answear! Thanks.
I am assuming you are using SpriteKit yeah? The UIView size is not related to the scene size. So changing those will not make your scene any different.
To do what you are describing, you need to read the Apple's Official Documentation on SpriteKit.
https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html
Scroll down to Example: Centering the Scene on a Node
Basically Apple tells you to add a dummy SKNode to put all your world sprites into the scene, and then add another SKNode as "camera" into the dummy node so you can move it around.
If you are targetting only iOS9 and above, you can use SKCameraNode and set:
SKCameraNode *cameraNode = [SKCameraNode new];
cameraNode.name = #"camNode";
self.camera = cameraNode;
Then you add your "character" (that is to be moved together with the camera) into the cameraNode. Then any movement, you need to move the cameraNode instead of the "character".
Related
I am building a simple Breakout game (game with a paddle, ball, and bricks and you have to break all the bricks) for Stanford's 193p course. Right now, I have a UIView (that serves as the paddle) added as a subview to an another UIView that serves as the game's view. I did not add any UIViews in storyboard except the game view - everything else is in code.
This paddle uiview is added to a dynamic animator.
It is added when the orientation of the iPhone is vertical.
But, when I rotate the phone, the Paddle UIView repositions to another location and cannot be seen.
What is the best way to and how do I translate this view so that it is in the exact same position in respect to where to was in the vertical orientation to the horizontal orientation?
I do not want it to be removed from the dynamic animator so I do not want to remove the paddle, then find the new location and then add it back.
I'm using spritekit to make an iOS game, and I came across a problem I've never had before. I want my game to be available on multiple devices, so I'm dynamically sizing everything based on the screen size, which I'm obtaining by using UIScreen.mainScreen().bounds.size, as was recommended online.
It's returning a screen size of 667x375. However, when I place an object at half the height and half the width, expecting to see it in the middle of the screen, it's instead displayed in the lower left corner.
Curious, I had it print touch locations from mouse clicks and discovered that the top right corner returns 1024x764 when clicked.
I've never had this problem before, and this is my 3rd XCode project. Can anyone help me?
UIScreen.mainScreen().bounds.size returns the size of your screen.
Sprite Kit uses a coordinate system different from a UIView. The bottom left corner of the scene is (0, 0). The values increase as you move up and to the right, so the top-right corner will give you the maximal value.
A scene's contents are scaled to fit the view based on the scaleMode property.
I suggest you re-read the Building Your Scene documentation.
I am making a game in swift. I was wondering how I could fix the problem where the view of my scene does not match of with the Scene's frame.
To be more specific, I want to be able to make an edge physics body around the screen so that nothing can escape the outside of the screen. In GameScene I put self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame).
But this has the weird effect of covering a larger area than what I view at one time. If someone could help with this, I would be very appreciative. Thanks!
If you're using scale mode .AspectFill, maybe one part of your scene is outside seeable area of view controller then SKPhysicsBody(edgeLoopFromRect: self.frame) did not work as you expected.
try self.view.frame instead of self.frame (and maybe you will have to multiply with 2 if your device comes with rentina display)
I found the answer. Since I was loading the GameScene from a file, the size was off a little bit. I changed the size of the scene in GameScene.sks and my program works beautifully!
I am building a spritekit game with 2 screens. Inside the 1st screen the player should pick one Hangar out of 6-7, by horizontal scrolling. When one picked a new SKScene will appear with the actual game play. For scrolling - One Hangar should be centered, while two others are partly shown from the sides.
Can it be done with UIScrollView, on top of SKScene? Or better use sprite nodes for it?
I am just not sure about the best way to handle user interface with sprite kit.
I would implement this by putting the hangars as children of a SKNode. Swiping would move this this SKNode move around with all it's children.
If you wanted the positioning you described; when the swiping has stopped I would use an SKAction to center a the hangar closest to the middle of the screen.
I would do it like this because I think you should only mix in UIKit when necessary because :
It is easier to port to OSX
You don't have to convert between different types of coordinate systems
I have a scene, containing layers which are large enough to be off-screen. When I do scene transition (eg. CCTransitionSlideInR) the off-screen part is visible during transition which of course looks ugly. What I want is to clip the scene to screen size. How can I do that?
You could perhaps use this:
https://github.com/njt1982/ClippingNode
The main page references original sources.