Convert a maze png to actual playable maze in cocos2dx - c++

I am developing a game in cocos2dx, I have a sprite of a maze, in png format (with walls and other areas are transparent).
I was wondering if there is any way I can detect collisions with these walls in the sprite. The player will drag an object through touch and solve the maze.
Any ideas are welcome.

basically what you need is map object's coordinates to image coordinates and then read pixel data at this image
for example, you have you sprite 8x8 pixels, but draw 256x256 world, ie each pixel in sprite is 32x32 texture
you have ball coordinates in "word", lets say 100x100, so just divide them by 8 = 12x12 - check this pixel in sprite
also, check out this tutorial for ios, it can give you additional ideas

Related

c++ opengGL: Draw polygon + image processing interior pixels

I am using opengl and c++ doing image processing. The idea is simple, I will load an image, draw a polygon by clicking and then apply an effect (desaturation for instance) only to the pixels in the interior of the polygon shape just created.
Can anyone give me any direction on how to limit the effect to the pixels within the interior of the polygon? Loading the image and drawing the polygon is not a problem
Supposing the following situation :
The picture on which you want to apply the effect takes the whole screen
The picture is rendered using opengl , probably through a simple shader, with the picture passed as a texture
You can do the following approach :
consider the screen as being a big texture
you draw a polygon, which will be rendered on top of the rendered texture
inside the polygon's vertices insert the uv's coresponding to the 2D coordinates on the screen (so from screen space to uv space (0 , 1 ) )
draw the picture normaly
on top of the picture draw your polygon using the same picture as texture, but with a different shader
So instead of trying to desaturate a specific region from your picture, create a polygon on top of that region with the same picture, and desaturate that new polygon.
This would help you in avoiding the stencil buffer.
Another approach would be to create the polygon, but draw it only on the stencil buffer, before the picture is drawn.

Scale or resize a sprite with image

The idea is: I have a sprite with rectangle image
CCSprite *sprite = [CCSprite spriteWithFile:#"Rectangle.png"];
When I touch the sprite, 8 red points will appear
Holding a point and drag it to scale(resize) the image like this
Can anyone show me how to do or give me a sample code.
I am not sure about this but you can redraw a texture on that 8 points.
It seems similar to draw texture of soft body. I have implemented that for my game and in that i use 12 points and on that 12 point i tried to draw the texture.
So what you can do is you have to redraw the texture on that points when any of the point dragged. This is a tutorial for soft body,but You can refer this tutorial for reference.
http://www.uchidacoonga.com/2012/04/soft-body-physics-with-box2d-and-cocos2d-part-44/
It's not the same thing what you are looking for but yes using this you can implement.

Background image in OpenGL

I'm doing a 3D asteroids game in windows (using OpenGL and GLUT) where you move in space through a bunch of obstacles and survive. I'm looking for a way to set an image background against the boring bg color options. I'm new to OpenGL and all i can think of is to texture map a sphere and set it to a ridiculously large radius. What is the standard way of setting image bg in a 3d game?
The standard method is to draw two texture mapped triangles, whose coordinates are x,y = +-1, z=0, w=1 and where both camera and perspective matrices are set to identity matrix.
Of course in the context of a 'space' game, where one could want the background to rotate, the natural choice is to render a cube with cubemap (perhaps showing galaxies). As the depth buffering is turned off during the background rendering, the cube doesn't even have to be "infinitely" large. A unit cube will do, as there is no way to find out how close the camera is to the object.

Need help understanding Sprite & Texture

I recently started looking at cocos2d game development.
What's the difference between sprite and texture?
Maybe I could through in 'bitmap' in there. What is a bitmap?
They all seem to be the same thing as 2d image.
A texture is an in-memory image that the device can draw onto the screen.
A sprite actually draws the texture, or just a specific rectangle of the texture, on the screen. The sprite can be scaled, rotated, positioned, skewed, tinted (colorized) among other things.
Multiple sprites can share the same texture. The texture is only loaded to memory once regardless of how many sprites are using the same texture. Moreover with CCSpriteBatchNode you can "batch" the drawing of all sprites that are using the same texture to achieve better performance.
A bitmap is a general term for a computer image where each pixel is represented by one or more bits. There's also the image format BMP which is/was popular on Windows. Most people would just say "image" these days as there are other forms of "bitmaps" that are not images. For example in AI code you often have bitmaps (arrays of bits) that represent state information of the AI or pathfinding algorithms for all areas of the game world. Ie each area in the world could have a "blocking" bit, or a "resource" bit that helps the AI making decisions.
See also Wikipedia:
Texture Mapping
Bitmap
you can load texture into memory, for example your file with image is texture. sprite is object with set of parameters, several of them are pointer to the texture, size and texture coordinate.
you can load texture 2048x2048 into memory, then create sprite with part of this texture.

Video as voxels in OpenGL

Any good references on displaying sequence of images from a video as voxel data in OpenGL? I want to display all these images at once as a cuboid with 50% alpha and navigate using keyboard or mouse.
Check out this tutorial on setting up a 3D texture.
If you then render slices through the texture array with the appropriate UVW coordinates you will get what you are after.