rolandino Posted July 2, 2014 Share Posted July 2, 2014 Hi,Wonder if I could ask a question ....I wish to generate a set of sprites at random positions on and off screen. I have this working, the creation is not a problem. However what I would like to do is to ensure that on initialisation the sprites don't overlap with each other. And to do this efficiently. Once the game starts, handling collision etc is not the issue here, it's just ensuring that on initialisation there is no overlap.I'm using Arcade Physics, so could use the http://docs.phaser.io/Phaser.Physics.Arcade.html#collide functionality, but can only see repetitive use of this being inefficient. Any thoughts or suggestions anyone?Many thanks,R Link to comment Share on other sites More sharing options...
lewster32 Posted July 2, 2014 Share Posted July 2, 2014 Although it doesn't mention it explicitly, this example has a routine for ensuring all objects have a unique position based on a grid; this could probably be adapted pretty easily to your situation: http://examples.phaser.io/_site/view_full.html?d=groups&f=depth+sort.js&t=depth%20sort I think if you didn't want to use a grid, you'd probably have to run some iterative separation routine using overlap rather than collide (which won't work until the sprites are given a velocity and have stopped intersecting in the first place) to 'nudge' the sprites away from one another by a certain amount, and keep going until there are no more overlaps. I think in this case it would seem inefficient but it'd probably be pretty quick nonetheless if you use Arcade's own intersects/separation stuff. Link to comment Share on other sites More sharing options...
rolandino Posted July 6, 2014 Author Share Posted July 6, 2014 Many thanks (again). The grid approach worked fine, many thanks.R lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts