mfcv Posted May 27, 2014 Share Posted May 27, 2014 I'm drawing circles at random places anywhere across the game with this code in the create() function:bmd = game.add.bitmapData(width, height);game.add.sprite(0, 0, bmd);And this code is run when it's time to draw the expanding circle (radius and alpha is increasing until a certain point): bmd.clear(); bmd.circle(star.x, star.y, radius, 'rgba(122, 45, 255,' + alpha + ')');I wanna check for collisions with other sprites, but only with the circle. Not with the bitmapData that is covering the whole screen for obvious reasons. How can I do that? Link to comment Share on other sites More sharing options...
lightcross Posted May 27, 2014 Share Posted May 27, 2014 I have the same issue by colliding BitmapData (Rectangles) and Sprites. @mfcv: Please write here, if you have a solution.Thanks Link to comment Share on other sites More sharing options...
lewster32 Posted May 27, 2014 Share Posted May 27, 2014 You will probably have to write a custom function which uses a Phaser.Circle object and the Phaser.Circle.intersectsRectangle method to check against the body (which has the same properties as a rectangle) of each sprite. Something like this (however for your code I'd suggest making the circle just once, and then adjusting its radius property every time you want to do a check):// create a circle (note the third parameter is diameter, not radius)var collisionCircle = new Phaser.Circle(star.x, star.y, radius * 2);bmd.clear();bmd.circle(star.x, star.y, radius, 'rgba(122, 45, 255,' + alpha + ')');spritesGroup.forEach(function(sprite) { if (Phaser.Circle.intersectsRectangle(collisionCircle, sprite.body)) { // this sprite is colliding with the circle }}); Link to comment Share on other sites More sharing options...
lightcross Posted May 28, 2014 Share Posted May 28, 2014 Hi folks,I wrote about my issue above. My sprite draws a trail with BitmapData (same as in the Ship trail example).I have other sprites, which i want to collide with that trail.Is there a possibility to check for collision? Thanks Link to comment Share on other sites More sharing options...
lewster32 Posted May 28, 2014 Share Posted May 28, 2014 I have a feeling collision detection with an unlimited length trail would get quite CPU intensive, as it's essentially per-pixel collision detection, or you'd have to create some kind of grid of colliders and optimise it with a QuadTree. If, instead of drawing the trail to a BitmapData object, you created a pool of small sprites behind the ship and you could then detect against those - but this obviously limits you if what you want is a permanent trail (sort of like Tron light cycles). lightcross 1 Link to comment Share on other sites More sharing options...
lightcross Posted May 28, 2014 Share Posted May 28, 2014 Thank you lewster32.I think I have to reorganize my ideas :-/I will give sprites a try ... Link to comment Share on other sites More sharing options...
Recommended Posts