I am currently struggling with the following problem:
I am creating a Sprite Kit game in Objective-C, in which I have to use a parallax-animation in all 3 scenes. I use clouds with randomly generated X and Y positions. They appear in the greeting scene, in the game scene and in the highscore scene.
Problem: whenever I switch from one scene to another, I have to restart the parallax-animation, which leads to an messy interruption.
What might be the best strategy to keep the "cloud scene" running all the time in the background, no matter how many times you switch between the game scenes?
Thanks in advance.
For this purpose, consider using only one scene and for each game theme (i.e greeting, game, highscore) use an SKNode which will contain the required elements for its purpose (e.g. the greeting node will have its greeting elements).
This way you can easily keep a "constant" SKNode (i.e. add it once to the scene when the game is first loaded) which will contain your parallax clouds and add/remove required node for the greeting game and highscore when necessary
Related
Is there any way how to pause rendering in Sprite Kit runloop, but still simulate physics and run all actions?
I'm writing small simulator and I need to be able to check collisions and apply forces to objects so I think it would be great to use the new Sprite Kit physics. However I have to be able to turn off rendering and focus just on simulation, but I am not sure if this is possible with Sprite Kit.
So what do you think, is it possible or do I have to use some other physics engine (Box2D)?
The short answer is no. There is no way to just stop rendering in Sprite Kit. The SKView is responsible for rendering which takes place as the last segment of the scene processing. SKView does have a paused command which causes no actions to be executed but it also stops the physics simulation.
Source: SKView Class Reference
You should use the Box2D engine, as SpriteKit does the same.
The Wikipedia page for Box2D says:
The physics engine used in SpriteKit for iOS and OS X uses Box2D
internally.
I was wondering how in Games when the character goes forward the screen moves with them and the level continues on, past the extent of a storyboard (Like the background is longer then the storyboard. Does anyone know how? (Not using a game engine)
I was wondering how in Games when the character goes forward the screen moves with them and the level continues on, past the extent of a storyboard
The objects on the game board generally aren't laid out in a storyboard file. The view that is the game board could certainly be part of the storyboard, but the content that that view draws is typically generated by the game's code. For example, it's common to use a sprite framework like SpriteKit or Cocos2D to draw objects using sprites. The data that the game manages is the collection of objects that appear in the game, and a sprite might be used to represent each of those objects.
Consider a platform jumping game like Doodle Jump, where the player hops from one platform to the next. The platforms keep coming and coming and coming as long as the player doesn't fall. Those platforms aren't laid out visually in the storyboard editor. Instead, a list of platform positions is somehow generated -- they could be read from a file, or calculated using some function, or create by some algorithm. A sprite is created for each platform as needed to fill the screen, and probably destroyed after it scrolls off the screen.
I am working on a game where I need to create an enormous "world" over which a rocket ship flies. On this world, I have to programmatically generate various simple background elements. There needs to be a record of the path, so I can't use parallax effects to give the feeling of motion.
When I create the background elements using SKShapeNode and SKLabelNode objects, I get terrible performance, because I literally have to add thousands of these nodes.
Is there a way to draw text and lines directly onto a sprite object?
Is it possible to add two (ore more) SKPhysicsBodys to one SKNode? Something similar to this:
Example from PhysicsEditor
Because the head of the character should collide with a ball, the top should be round. Furthermore the ball mustn't go through the player. Do you have an idea how to accomplish this?
As the physicsBody property on SKNode suggests, there's a one-to-one relationship between nodes and physics bodies.
However, that doesn't mean you have to have one basic shape for every visible sprite. There are a few approaches you can take to accomplish what you're looking for:
Does the top really need to be rounded? You can cover most of the monkey art with a rectangle. (I presume you want a rounded top so collisions bounce in different directions, though.)
Create the "round-ended-rectangle" shape you're after using a polygon. You'll have to pick a number of sides for approximating the curve that fits your app: too many and it'll slow down the physics simulation, too few and it won't behave like a circle when other bodies bounce off.
Every body needs a node, but not every node needs a visible sprite. You can make your monkey out of two nodes: one that holds the art and has the square or round physics body attached, and another node that has the other physics body, attached through a fixed joint,
but with no art.
This is the top hit on Google for this question so i thought I'd update the answers. This is possible (Although may not have been in 2013), as per the answer from Mike S in this post.
You need to use
// Swift
SKPhysicsBody(bodies: <#[AnyObject]#>)
// Obj-c
[SKPhysicsBody bodyWithBodies:(NSArray *)bodies]
So you create a body with other bodies and add that one body to your SKnode.
No, every SKNode can only have one SKPhysicsBody since physicsBody is a single property of SKNode. Like rickster said, your first option is to make the monkey one silo-shaped physics body using the bodyWithEdgeLoopFromRect: class method of SKPhysicsBody.
Your other option is to create two separate SKNodes and attach them with an SKPhysicsJointFixed. rickster's answer is great, but I just wanted to give the class names in case you want to do a little Googling around.
I have a UIView that a user drags around via setting its center in the touchesMoved: method. When the user lets go, I want the UIView to fall off the screen according to how fast and what direction they were moving it in.
Do I need to somehow create a vector by comparing the UIView's last center point to it's new center point? And subtract a fixed amount to the vector's y value every so often with a NSTimer?
Yes, you will need to a decent amount of physics in calculating
Speed of swipe
Direction of swipe
You will need to use the touchesMoved method along with a timer to track the amount of time for the swipe and also the co-ordinates for the new location of the object. This should be fairly straight forward. Once you are done finding those you can simply add a UIAnimation for the object to move to its new place.
~ A suggestion:
I would suggest that you have a look at Cocos2D and integrate the library with you app. You will not need to implement touch delegate methods and compute things yourself ~ there are libraries for that :) It has a lot of libraries especially for moving objects (or sprites if you wish to call them that way) and you have animation method like easeInEaseOut, etc.. that can be impacted on the moving object. If you are developing a game of some sort, have a look at chipMunk engine in Cocos2D as well.