Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Griegs

I have a maze type of level and I need to spawn entities randomly on the map.

However, I don't want them spawned in a collision state with the collision layer/

Is there a way for me to pick a random X and Y position and to check to see whether that square, beginning at the random x and y combo, will cause a collision with the collision layer?

1 decade ago by StuartTresadern

Use getTile against your collision map http://impactjs.com/documentation/class-reference/map#gettile

1 decade ago by Griegs

@StuartTresadern, that's great but I'd then need to check every pixel within the 54x54 sprite which seems a little heavy handed

1 decade ago by alexandre

@Griegs

Unless I misunderstood your question, one relatively fast&simple way would be for you to:

- parse the collision map's data, building an array of free tile descriptor objects
- then shuffle that array
- then iterate over it, using each descriptor's col/row props to calculate x,y coords and spawn a new entity at those coords
Page 1 of 1
« first « previous next › last »