Jump to content

Circular Collision


ptotheaul
 Share

Recommended Posts

First of all I'm not sure this is the best way to group element for collision detection but I'm crating CHARACTER elements that contain various sprites that I want to act as one element.  I want the different circles(made up of a few sprites) to bounce off of each other.

In order to keep all the elements together and since I can't set 'body.setCircle' on a group I'm using the 'circle' sprite for physics and just updating the positions of the other elements to match the x/y of the 'circle' in the bubble.update = function(){}.  Is there a better way to do this?

My other question is, as I add more CHARACTER's I'd like to add the corresponding 'bubble' sprite to a:

game.physics.arcade.collide()

so that the 'bubble's bounce off each other.  ie

game.physics.arcade.collide(bubble1, bubble2, etc)

is there a way to do this?

 

CHARACTER _ctor: function() {
        var character_g = this.game.add.group();


        var s1 = imageLoader.sprite(0, 0, 'Idle.png');
        
        var s2 = imageLoader.sprite(0, 0, 'state1.png');
        s2.visible = false;
        
        var bubble= imageLoader.sprite(0, 0, circle.png');

        game.physics.arcade.enable([bubble]);
        
        bubble.body.setCircle(160);
        bubble.body.collideWorldBounds = true;
        bubble.body.bounce.set(1);
        bubble.body.gravity.y = 0;
        bubble.body.velocity.set(150);      

 

        character_g.add(s1);
        character_g.add(s2);
        character_g.add(over);

      

        bubble.update = function(){

            s1 .x = bubble.x;
            s1 .y = bubble.y;
            
            s2 .x = bubble.x;
            s2 .y = bubble.y;

        }
              

        s1.inputEnabled=true;
        s1.events.onInputDown.add(this.itemClick,this);

    }

Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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