Jump to content

Getting coordinates of graphic Bitmapdata image on destroyable map with physics


linkers
 Share

Recommended Posts

Good day,

I have been struggeling with this issue for a few days, I am also quite new to Phaser, so please forgive me if this is a newbie question.

I am currently working on a project regarding a destroyable map with p2 physics.

I have been using Physics editor to capture the maps size in a JSON file and all that seems to be working fine, also I am creating the map as BitmapData object which also is working fine. But once a part of the map is being destroyed, it needs to recalculate the physics properties which obviously doesn't happen. 

The solution for me - I am going to get the boundaries of the map (its a small scrollable map not more than 1.5k pixels in width) and triangulate the smaller objects which create the shape myself, which means that if a part of the map is destroyed it will recalculate the physics properties. 

The issue here is that I simply can't get the boundary pixel positions of a map this size for the triangulation library, my browser simply crashes, for smaller objects it actually works fine and everything is working smooth! Only if I put larger pictures in the example, it crashes...

I am using contour.js marching ants algorithm from D3 an example is demonstrated down below to get the contour.

http://stackoverflow.com/questions/28207232/draw-border-around-nontransparent-part-of-image-on-canvas

 

Maybe there is a better solution to detecting contour pixel positions of larger objects in Phaser?

Why is this example not working with larger png objects?

And yes.. I also need to detect the transparent area

Link to comment
Share on other sites

I actually managed to somewhat solve the problem by adding this library instead of D3 contour.

Yet still the whole process of analysing the bitmapdata and delaunay triangulating seems very long.

https://github.com/sakri/MarchingSquaresJS

To give somewhat example of from Ingame and Physics editor. The difference is insane. The image is taken from game tanks example 002.

 

Tveršana.PNG

Tveršana.PNG

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...