Iphone I use cocos2d and need rgba pixel value on sprite

I am programming a shooter game in cocos2d for iphone. I and I want to exclude the collision detection alpha of my sprite. How to read RGBA value for one pixel. Thanks for the help.

+3
source share
2 answers

First of all, think about whether you really will do it - it is much more expensive than other methods of collision detection (i.e., bounding box, collision with a circle), which may not be so accurate, but for most purposes, working well is enough.

If you really want to do this, you must create a mask for each of your sprites that you want to detect, a collision between them. 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 take a few steps:

  • Since exact pixel collisions will take a long time, first make a collision with the bounding box between the two sprites to see if you even need to check for collisions at the pixel level.

  • If you know that the sprites collided at the borders, calculate the collision rectangle. At this point, you can do an optimization that says they exceed X%, overlapping what they collided with. Especially if your alpha areas of the sprite are on the outer edges.

  • , - 1, - , , .

, , . ( Atari 2600 ), .

, , , , , .

!

+2

Cocos2d, iPhone -

0

Source: https://habr.com/ru/post/1727537/


All Articles