Procedural landscape - bitmapdata?

Hi - I want to procedurally draw landscape, and then be able to collision detect against it. I’ve been going through the docs and found bitmapdata from v2, but that’s not in Phaser 3. What would be the best and most canonical way of rendering a bitmaped landscape to the screen and collision detecting those parts of it which are not entirely transparent?

The closest alternative in Phaser 3 is a Canvas Texture. You can use the whole canvas API with it, including getImageData and putImageData to manipulate the canvas as a bitmap.

Thanks! How would collisions work with a Canvas Texture?

The texture you use (Canvas Texture or Bitmap Data) only concerns rendering. Collisions are an entirely separate matter and it depends entirely on what your terrain looks like and how the characters are going to collide with it. If you want to roll your own collision, you could just check a given pixel’s alpha value to see if it’s transparent because you have the bitmap data. If you want to use an existing physics engine, you’ll have to create e.g. polygon bodies for the landscape. I can’t tell you anything more specific without knowing what sort of end goal you want to achieve.

I’d like to create a destructible landscape. Remove a section of it, and now the physics mean that a sprite can move into that location. It sounds as though Phaser isn’t really set up to allow this.

That’s plausible, but the complexity could vary depending on how you do the collision, which physics engine you use, and how your movement works. Conventional physics engines use polygons, and would require generating shapes for the terrain, then altering them as it changes. It’s possible to build your own collision, too, but I can’t say for certain which option would be easier.