0

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.

Wajahat
  • 1,593
  • 3
  • 20
  • 47

1 Answers1

0

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

Iłya Bursov
  • 23,342
  • 4
  • 33
  • 57
  • The world and image are the same size, I want to know how to detect collision. I do not want to use box2d that will make things complex. If I update the position of object by using the touchLocation in CCTouchesMoved, then how do I check if it is a legal move or not ... – Wajahat Oct 18 '13 at 20:45
  • @Wajahat I suppose it is described in question, just check pixels, if sizes are the same - you do not need to divide – Iłya Bursov Oct 18 '13 at 20:48