I'm developing a running game for iOS devices and have run into a problem. I created a subclass for a game tile which is 4 screen lengths long. The game tile will have some nodes which are obstacles. I have a scene which creates the player, some background decorations, and particle systems. I need to add the obstacle nodes to the physics simulation in the scene so that I can detect when they contact. I'm not sure how to do that... Is there another solution that would be simpler? Thanks in advance for your help.
Related
I am currently making a game with sprite and the spritekit library, and I am trying to add power ups. I have tried to use physics bodies to detect when the player touches the power up, however that has not worked for me as the enemies are also able to interact with it. This is a problem, as I only want the player to be able to pick up the power up and have enemies walk straight over the power ups.(The game is top down) I was wondering how I could achieve this. Thank you.
There are a lot of different ways to achieve this.
You could add in some code to the power-up sprite that checks that the colliding sprite is the player.
You could also add in some code to the enemy sprite so that when it collides with the power-up sprite nothing is done.
I'd recommend looking up some tutorials on game development with Swift.
Good luck!
I've been working on a 'side scroller' sprite kit game (not really side scroller, you can move in any direction) and the apple docs/stackoverflow answers say to make a world node as the child of the scene, and move the world node instead of the character sprite.
does this suggestion change for a multiplayer game where there are multiple character sprites moving inside the same world node? Because in this case, one sprite moving changes the world for everybody.
The suggestion still applies in multiplayer. Normally you have only one local player, so the "camera" will still be following that particular player and none other.
In local multiplayer (2 players playing on same device) you would probably have the camera follow the mid point between the two players. But it's still the same principle.
I just started to learn how to use spritebuilder since basically everyone told me it saves a lot of time and easy to integrate things, but I am running to an issue where the objects and players that are suppose to sit on the ground fall through.
You need to use a single CCPhysicsNode that contains all the physics objects of your game.
Your setup effectively creates two separate physics worlds that won't interact with each other, therefore rock and guy will never be able to "make contact" with ground.
Interestingly you tagged this with sprite-kit so if you are using the (not officially released, no longer in development) SpriteBuilder version that supports Sprite Kit, know that CCPhysicsNode will not function at all. The SpriteBuilder Sprite Kit version does not support physics.
I'm currently facing a - I think - very common networking problem. But I can't find an answer with SpriteKit.
Let's take a simulation with a ball that bounce again wall. The objective is to synch the ball position on two devices via bluetooth or Wifi.
It uses SpriteKit physics to simulate ball movement and collisions
It uses MultipeerConnectivity for networking on bluetooth or Wifi.
The Device A - master - simulates everything and tells ball position and vector to Device B at synchronisation points. The Device B simulates the scene between synch points.
Currently, the ball in Device B is always ~50ms later than device A. To prevent this, someone told me about "interpolation" : Device B receive the DeviceA's ball position and knows the info is 50ms old. So Device B should be able to predict the "real" position 50ms after the received one.
But I did not find a way to do this with SpriteKit. I don't want to manually develop what's SpriteKit physics automatically made for me!
I'm just searching for a way to simulate a 50ms jump in the future!
Any idea?
You can experiment with speed property of your SKScene. It can set above 1.0.
I trying to rewrite simple game (developed by me with Cocos2d+Box2d sometime ago) using Sprite Kit framework. Everything looks much simpler in Sprite Kit, which is great, but I have a problem adjusting physics world parameters in the new project. I have noticed that sprites created using exactly same graphic images (all have basic rect-based bodies) have four times lower mass in Sprite Kit than it had in Cocos2d+Box2d. Setting bodies density to 4 solve the problem, unfortunately that's not the main issue. It looks like the same problem with 4-time multiplier works for all forces in the physics world. I have done some testing in Sprite Kit and create a body with mass four time higher than in Cocos2d+Box2d, I have also set the world gravity to be four time lower than in Cocos2d+Box2d. As a result physic in both projects (first using Cocos2d+Box2, second using Sprite Kit) behaves similarly. I can't find anything like PIXEL_TO_METER_RATIO (that was available in Box2) in Sprite Kit. Is there any option that allows to adjust the physics world in Sprite Kit to behave like in Cocos2d+Box2d without multiplying all forces, masses etc? Maybe there is some kind of configuration property that allows to adjust it. If I leave the same values for gravity, mass and forces in Sprite Kit that I was using in Cocos2d+Box2d everything in the game will be simulated too fast. My question is how to deal with problems like this when migrating from Cocos2d with Box2d to Sprite Kit framework?
The only solution is to re-tweak the forces and other settings until things feel right.
Internally Sprite Kit uses Box2D but we have no way of knowing if and how Apple may have modified it. What is known is that they use different default settings for the Box2D world which means physics values can not be ported as is and expect the same results.
I believe this was discussed in the developer forum (under Sprite Kit) where someone investigated the actual numbers for changed settings. Note that these are settings in Box2D's code most users won't even consider to modify, so we have to assume Apple had their reasons to change them in the first place.