2

I'm getting the feeling this won't be possible, but worth asking anyway I guess.

I have a background sprite and a foreground sprite, both are the same size as the window/view.

As the player sprite moves across the screen I want to delete the pixels it touches to reveal the background sprite.

This is not just for display purposes, I want the gaps the player has drawn or "dug" out of the foreground layer to allow enemies to travel through, or objects to fall into. So hit detection will be needed with the foreground layer.

This is quite complex and maybe Cocos2D-JS is not the best platform to use, if not possible could you recommend another which would be easier to achieve this effect with?

Varrick
  • 627
  • 1
  • 6
  • 11

1 Answers1

1

I believe it's possible, but I'm not capable of giving you a proper answer.

All I can say is that you'll most likely have two choices:

a. Make a physics polygonal shape and deform it, then use it as a "filter" to display your terrain image (here's a proof of concept example in another language using box2d).

b. Directly manipulate pixels and use a mask for collision detection (here's pixel-perfect collision detection in cocos2d-js, sadly I've got no info in modifying pixels).

Sebastián Vansteenkiste
  • 2,234
  • 1
  • 19
  • 29