Sprite Kit physics variables comparing to Cocos2d+Box2d - ios

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.

Related

How to draw lines on the screen for an iOS game

I am working on a game where I need to draw a bunch of lines to create a wireframe sort of object, I can do this in sprite kit using nodes but adding a bunch of nodes to the screen will drop the frame rate down a lot. I don't know how to use OpenGL Es at all so that's not an option for me. Is there anything that would just allow me to draw lines on the screen in Sprite kit without adding nodes or is there another framework that will allow me to do that?
If you want a 3D wireframe then your choices are sprite kit (which is built on top of OpenGL), OpenGL, or Metal. Or I guess you could use somebody's 3rd party framework that is also built on top of OpenGL or Metal.
I tend to agree with nhgrif's comment that you're "I don't know xyz so I can't do that" is needlessly limiting. If you can't do anything that involves learning new APIs then you're never going to get very far as a developer.

Changing b2_velocity threshold in an existing Swift iOS app

I am working on an iOS game using Swift and SpriteKit. It involves collisions between two or more SKShapeNodes that have physics bodies that go along with them.
My problem is that when they collide, if they are going too slow, the collisions are treated as inelastic and rather than bouncing they "stick" to each other so to speak.
From numerous searches, I believe I've found the problem to be in the underlying physics engine which is Box2d. There is a defined constant 'b2_velocityThreshold' that is set to 1.0f and if a collision happens at speeds under that threshold, I run into the issue stated.
How do I go about changing that value to a number that would help maintain the elastic collisions? I'm not sure how to access the files and be able to update that value. Would I need to download the Box2d library and then connect that into my project somehow? Or would I need to restart and import that from the start? and build the project in C++ from the beginning because Box2d is written in C++?
In Sprite Kit you can't change any of the box2d parameters because there's no source code for Sprite Kit and the version of Box2d that Apple used to build Sprite Kit with. You will have to make the game work with whatever parameters are exposed by the Sprite Kit API.
One thing you can try: set friction of the two slow moving bodies to 0. This may preserve their energy (velocities) when colliding.

Physics engine or not for making a Pendulum in iOS?

I'm trying to replicate the pendulum effect as seen in the old game "Gold miner", if you ever played it before. Do I need to use a physics engine for that, or not? I heard that Box2D is preferred over Chipmunk when it comes to ropes, but do I really have to join two objects together with a rope to accomplish this pendulum effect? I'd love to do it without a physics engine, but if I have to use one I think I would pref chipmunk as it comes with Cocos2d v3. (In short, whats the best way of making a pendulum that swings forever and can be lowered and raised)
Im' a complete n00b when it comes to physics engines, never used one before, only made non-games apps before :/ Any help is very appreciated =)
You mean the grappling hook in that game? That's absolutely not physics, or at least can be done easily without a physics engine. At best you may want to use the physicss engine's raycast collision detection methods (if any).

Objects and Players falling through static ground

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.

iOS - Cocos2d, Box2d or Chipmunk

I have to develop an app which has on screen 10 balls. When user shake the phone a sound will play and the ball have to move around the screen colliding each others without go out of bounds. I think i have to use cocos2d, box2d or chipmunk, but i don't know how can i do a thing like that. If someone have a tutorial, or some code it will be very appreciated.
I found another method that could be useful, it's CGRectIntersectRect(obj1.frame, obj2.frame)
but i think it isn't the correct way for my problem, is it right?
Thanks
Box2d or Chipmunk are supposed to take care of the collisions, so you don't have to use functions like CGRectIntersectRect to handle these kinds of events.
Start with some cocos2d tutorials to see how to display sprites on the screen and after that see some tutorials for your physics system of choice.
Box2d and Chipmunk are physics engines that come WITH cocos2d, cocos2d is the graphics engine.
I suggest you go for Box2d as it not only provides collision detections (including with circle body shapes for your case) but also lets you handle all the physics etc. I've never used Chipmunk.
There is a short Objective-Chipmunk tutorial that does most of what you are looking for already:
http://chipmunk-physics.net/tutorials/SimpleObjectiveChipmunk/

Resources