Is it possible to divide up boundingBox? - iphone

In cocos2d, i've got two objects that I want to detect collision with.
Im using CGrectintersectsrect, which has been working fine thus far.
But I want to divide up the bounding box of one of my objects into 4 quarters, so that if my object collides in any one of these quarters, appropriate physics can then be applied.
At the moment, there is only 1 large boundingBox which is insufficient. Ideally I would want 4+...
Is this possible, and if so how could i achieve this?
If not, is there any other avenue that could work?
Thanks everyone, once again :)

The boundingbox method returns a CGRect. You have to divide your rect manualy, there is no pre-made method for that.
Otherwise if there is a lot of objects, the best way to detect the collisions is to use Box2d. You can follow this tuto to see
How To Use Box2D For Just Collision Detection with Cocos2D iPhone tutorial.

Related

Best way to implement a "floating bubble" object

As the title says, I'm trying to find a way to implement a kind of floating bubble (a SKSpriteNode object) inside my game.
I'm using SpriteKitbut I really don't know which is the best way to approach this problem. In particular:
Should I "play" with values inside Xcode Physic Body in order to find good stats which reflects the physic of a soap bubble?
Or I should change the gravity to 0.0 and handle the animations through code? If so, what if I need to implement other objects who need to be affected by the standard -9,8 gravity value?
If i understood what you are thinking....a good idea would be using a Particle Emitter, there you can use a texture and play with lots of options. There you can have lots of bubble, emit them.
If your idea is just animate one or two bubbles....then you may do this with spritekit code (gravity to 0.0), using SKAction to move the bubbles, fade in/out or just play with .alpha.
You can also use gravity to move it...but you will have less control about what bubble is doing...
If you need more help just comment this. Hope i helped you!

Create a space environment with no gravity, Box2d or not?

I want to create a cclayer with 4-5 flying objects, flying in random directions on screen. I also want those flying objects transparent to each other, which means they can fly through each other.
What I can think of Ways to do:
With Box2D
Create a box2d world with 0 gravity. and add Polygon static ground around the edges of the screen.
Give an initial force to each of the flying objects, let them flying around and reflect on the grounds.
Problems: Objects still rest down after sometime.. Don't know why. Objects collide with each other, don't know how to make them fly through each other.
Without Box2D
use CCMove for each objects, detect if they reach edge of the screen, calculate new path for their move..
Can someone point me a direction, which way is easier? Thanks a lot.
If you have to handle complex collisions - go with Box2d. If your collisions are simple - handle them yourself.

What is the best way to handle collision detection between bodies efficiently?

I am new to Cocos2d, Box2d and game development all together, but I have read a good bit of tutorials to at least have a good start on a game set up and working...
Im now at the point where I need to start adding more bodies to a layer and need to check and see if and when my main avatar will collide with any of them..
Common sense seems to tell me that the more bodies I add and the more cases I add checking to see if fixture1 is colliding with fixture2 for instance will bog down the processor at some point..
Are there any best practices and/or efficient algorithms to make these checks more efficient over time as the number of bodies grow?
Any links or direction would be appreciated! thank you!
You can use QuadTree to divide the scene and get a list of bodies that needs to be checked.
(There are a lot of articles shows how QuadTree works, just google it:D )
And if that's a little complex for you. Then you can try to divide your scene into many grid, and make a loop to put bodies in their grid based on their 2d position. Then just check bodies in each grid. It's a lot faster than normal loop.
http://i.stack.imgur.com/W5cBT.png
As of iOS 7 you can use Sprite Kit to handle collisions:
https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Physics/Physics.html#//apple_ref/doc/uid/TP40013043-CH6-SW14

Iphone game cocos2d and box2d

I have image named "platform.png" that represents one brick for platform of a IPhone game. I have a cartoon character that will jump on this platform.
A series of platform.png will form one complete platform. These series will be generated by swiping finger across Iphone screen. When character will jump on this platform it should go down like elastic and bounce back up. Can anyone tell me how to do this ?
Thanks in advance.
What yo want is Collision Detection. I don't think using Cocos2d will be a great idea to use in this case because you want to show elastic and bounce effects which should seem real. For this, what I suggest, is using Box2d which clearly help in showing the effects in a natural way. Here Collision Detection can be handled in a separate class known as ContactListener. You can study Box2d and ContactListener here. In ContactListener you can generate these effects and this class is very easy to handle. Two or three months back I used the same to create my game Pogo Jump and believe me I was very easy to work on Box2d.
Good luck..!!
heye ,
you have two options for this , either use box-2d/chipmunk or dont.
If you have prior experience with Physics then i would say box-2d/chipmunk would look more realistic.

How do I create a floor for a game?

I'm attempting to build a Lunar Lander style game on the iPhone. I've got Cocos2D and I'm going to use Box2D. I'm wondering what the best way is to build the floor for the game. I need to be able to create both the visual aspect of the floor and the data for the physics engine.
Oh, did I mention I'm terrible at graphics editing?
I haven't used Box2D before (but I have used other 2D physics engines), so I can give you a general answer but not a Box2D-specific answer. You can easily just use a single static (stationary) Box if you want a flat plane as the floor. If you want a more complicated lunar surface (lots of craters, the sea of tranquility, whatever), you can construct it by creating a variety of different physics objects - boxes will almost always do the trick. You just want to make sure that all your boxes are static. If you do that, they won't move at all (which you don't want, of course) and they can overlap without and problems (to simulate a single surface).
Making an image to match your collision data is also easy. Effectively what you need to do is just draw a single image that more or less matches where you placed boxes. Leave any spots that don't have boxes transparent in your image. Then draw it at the bottom of the screen. No problem.
The method I ended up going with (you can see from my other questions) is to dynamically create the floor at runtime and then draw it to the screen.