i am wondering how could I detect collision on the course given in the attached image for example:
In XNA that could be done easily but i dunno how to make it possible in OpenGLES for such scenario as simple collision with rectangles is not a big deal but for this case I need help.
Opengl doesn't support any native collision detection, its just a polygon rendering utility. If you wanted to preform collision detection on the given image, you could set up an edge finder, and then load the detected edges into your own custom collision detection algorithm - but that has nothing to do with opengl or opengles.
For collision detection a simple and very dirty solution is to map your player position to the bitmap's coordinate system and check the pixel color/value. Grey is on-course, white is off.
Collision response is a whole other question :)
Related
We are trying to achieve the following in an iphone game:
Using 2d png files, set-up a scene that seems 3d. As the user moves the device, the individual png files would warp/distort accordingly to give the effect of depth.
example of a scene: an empty room, 5 walls and a chair in the middle. = 6 png files layered.
We have successfully accomplished this using native functions like skew and scale. By applying transformations to the various walls and the chair, as the device is tilted moved, the walls would skew/scale/translate . However, the problem is since we are using 6 png files, the edges dont meet as we move the device. We need a new solution using a real engine.
Question:
we are thinking of instead of applying skew/scale transformations, that if given the freedom to move the vertices of the rectangular images, we could precisly distort images and keep all the edges 100% aligned.
What is the best framework to do this in the LEAST amount of time? Are we going about this the correct way?
You should be able to achieve this effect (at least in regards to the perspective being applied to the walls) using Core Animation layers and appropriate 3-D transforms.
A good example of constructing a scene like this can be found in the example John Blackburn provides here. He shows how to set up layers to represent the walls in a maze by applying the appropriate rotation and translation to them, then gives the scene perspective by using the trick of altering the m34 component of the CATransform3D for the scene.
I'm not sure how well your flat chair would look using something like this, but certainly you can get your walls to have a nice perspective to them. Using layers and Core Animation would let you pull off what you want using far less code than implementing this using OpenGL ES.
Altering the camera angle is as simple as rotating the scene in response to shifts in the orientation of the device.
If you're going to the effort of warping textures as they would be warped in a 3D scene, then why not let the graphics hardware do the hard work for you by mapping the textures to 3D polygons, then changing your projection or moving polygons around?
I doubt you could do it faster by restricting yourself to 2D transformations --- the hardware is geared up to do 3x3 (well, 4x4 homogenous) matrix multiplication.
i want to detect collision detection two times in same row.
for example:-(see the below image)
the ellipse and rectangle or detcted. after that my ellipse will travelling in the straight line path to down and detect the another rectangle.
first one is( travelled in trajectory path ) working fine. second one i want to pass in straight line to down for collision detection.
how to do this process.
Use the Box2D physics library for collision detection. It is by far the best option in your case and elegantly supported in Cocos2d.
See here: http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
As i know cocos2d have no collision detection of sprites because it's not a phys engine. If you want the collision be detected automatically use Box2D or chipmunk physics engine, supported by cocos2d.
If the number of object you want to check for collision is small you can just run over your object and check if some of them (or only one if it's enough for you) overlaps with the others.
Making more complex collision detection will bring you for writing a collision detection part of a physics engine. It's much simpler to use en existing one
I'd like to create a game that has levels such as this: http://img169.imageshack.us/img169/7294/picdq.png
The Player moves "flies" through the level and mustn't collide with the walls. How can I create such levels?
I found that piece of software: http://www.sapusmedia.com/levelsvg/
It's not that cheap, so I wonder whether there is another way to create such a level as shown in the picture above...?
You can do that pretty easy by reading the color value of pixels at specific places of the level. Take for instance that your level background is white and the walls are black. In order to perform collision detection, whether your character had hit the wall, you would do the following:
-take your character's position
-look at the color values of the pixels of your map that overlap with character's bounding box or sphere at that position
-if any of those contain black color you have yourself a collision :)
Now if your level is all colourful, you would want to build a black and white mask texture that would reflect the wall surfaces of your actual map. Then use the coloured map for drawing and the bw map for collision detection.
I'd spend a good solid couple weeks getting caught up on Objective-C, Xcode, Interface Builder, and Apple iOS documentation. There are many good tutorials out there and sample Xcode projects to download and run on the iPhone/iPad simulator.
If just starting out, some of those quick startup libraries can rob you of the intimate knowledge you'll need to create the intricacies and nuances you'll need when your application starts to reach outside the boundaries of the code sandbox. Not bad to use as learning tools or to speed up development time, but I'd advise against using them as a crutch until you strengthen your developer legs. Crawl. Walk. Run!
I am programing a shooter game in cocos2d for the iphone. I and I want to exclude collision detection an the alpha of my sprite.
How do I read the RGBA value of the single pixel.
Thanks for the help.
First off, think about if you really want to do this -- it's much more computationally expensive than other methods of collision detection (i.e, bounding box, circle collision) which may not be as accurate, but for most purposes work well enough.
If you really do want to do this, you should generate a mask for each of your sprites that you want to detect the collision between. This mask should ideally be a simple 1-bit representation of your sprite.
Next, for each sprite you want to check for a collision, you need to do a few steps:
Since the pixel accurate collision is going to take a long time, do a bounding box collision first between the two sprites to see if you even need to check for pixel level collision.
If you know the sprites have collided at the boundaries, calculate the rect of the collision. You may want to do an optimization at this stage that says if they are greater than X% overlapped that they have collided. Especially if your alpha areas of the sprite are along the outside edges.
Using the rect area of the collision, go through the masks of each of your sprite -- if both pixels are 1, you have a collision -- exit out of the loop and do what you need to mark them as collided.
As you can see, this is very CPU heavy compared to the other methods, which is why I recommended against it at the beginning. Unless a system has hardware support for pixel accurate collisions (the Atari 2600 actually had this), most games are not going to use pixel values for their collisions.
If you decide to go with a bounding box approach, you can do things like shrinking the bounding box used for collisions to prevent false positives for when two sprites touch each other at a corner.
Good Luck!
Not specific to Cocos2d, but should work on any iPhone project -- check out this question & answer
What would be the best way to go about adding collision to my application. Right now I have a lot of jagged walls and a couple of weird shapes that I wanna make collision for but am not sure which is the right path to get the job done. What would you guys do if you had a room full of walls with different shapes and sizes that needed collision implemented ?
I would read a set of articles on collision detection. Paul Nettle used to write about the topic (PDF) and has a nice library for free.
This document will describe a
collision technique that allows you to
move an ellipsoid (a sphere with three
different radii, one for each axis)
through a world that not only properly
detects collisions, but also reacts in
a way that gamers would expect from
the common first person shooter.
This technique also allows for sliding
along surfaces as well as easy
implementation of gravity, which
includes sliding downhill when
standing stationary. This technique
also allows automatic climbing of
stairs and sliding over bumps in walls
(like door frames) and any other
randomly oriented “stair-like
topography”.
You can use Chipmunk physics engine, which has a very good physics + collisions.
Or even Cocos2d-iphone library - 2d game engine with Chipmunk inside. Here are examples of games, created with it.