Jump to content

Group creation with rotation


Jirka1111
 Share

Recommended Posts

Hello,


I am pretty desperate (yeah, again).


 


Can you please look at this code and tell me, what I am doing wrong with function addGroupOfBunnies?


 


I just want to generate bunch of sprites with body and then make a collision between player and each sprite from group. 


 


https://mega.co.nz/#!yVRzBAJI!WbRqInoZBF4zbeYoJbrz10fVZlh9NXW-tjtzo5OPo5Q


Link to comment
Share on other sites

this.groupOfBunnies = this.add.group();

        this.groupOfBunnies.enableBody = true;

        this.groupOfBunnies.physicsBodyType = Phaser.Physics.ARCADE;

addGroupOfBunnies: function(){

        for(var i = 1; i < 10; i++){

            this.pos = this.bunniesPos();

            this.bunny = this.groupOfBunnies.create(this.game.world.centerX, this.game.world.centerY, "player");

            this.bunny.name = 'bunny' + i;

            this.bunny.rotation = this.pos + Math.PI / 2;

            this.bunny.x = this.game.world.centerX + Math.cos( this.pos ) * ( this.radius + this.bunny.height / 2 );

            this.bunny.y = this.game.world.centerY + Math.sin( this.pos ) * ( this.radius + this.bunny.height / 2 );

            

            

            

        }

    },

    

    bunniesPos: function(){

        return this.game.rnd.pick([/*0, 0.314, 0.628, */0.942, 1.256, 1.57, 1.884, 2.198, 2.512, 2.826, 3.14, 3.454, 3.768, 4.082, 4.396, 4.71, 5.024, 5.338, 5.652, 5.966/*, 6.28*/]);

    },

Link to comment
Share on other sites

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...