Fla5h

Moving group objects

Recommended Posts

ok so i have a quick question

 

i have a full game running but i cant figure out how to get my group of enemys to follow my player. I tried this for a single enemy and it works,  but it wont work for my enemys group 

(the group is called "enemys")
// this will cause the enemy to follow the player, this works game.physics.moveTowardsObject(enemy, player, 100);
// this will cause the group enemys to follow the player , doesn't work game.physics.moveTowardsObject(enemys, player, 100);

the same thing when i try to assign a particle effect to every member in a group, For when a collision occurs and they are destroyed.

Am i supposed to control groups another way?

Share this post


Link to post
Share on other sites

I moved your post to its own thread because it wasn't relevant to the thread you originally posted it on, and warrants a thread in its own right.

 

The answer is that moveTowardsObject expects a Sprite to be given to it, not a Group. However once we release Phaser 1.0.7 later this week you'll be able to do this:

(function () {	var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });	function preload() {		game.load.image('ball', 'assets/sprites/shinyball.png');	}	var balls;	function create() {		balls = game.add.group();		for (var i = 0; i < 50; i++)		{			balls.create(game.world.randomX, game.world.randomY, 'ball');		}	}	function update() {		if (game.input.mousePointer.isDown)		{			//	First is the callback			//	Second is the context in which the callback runs, in this case game.physics			//	Third is the parameter/s the callback expects			balls.forEach(game.physics.moveTowardsMouse, game.physics, false, 200);		}		else		{			balls.setAll('body.velocity.x', 0);			balls.setAll('body.velocity.y', 0);		}	}})();

Share this post


Link to post
Share on other sites

I am having a group collide with sprite, which, group need to set velocity and sprite is static(remain at the main position all the time). I have a few question:

1) collision cannot detect if simply using += y, need to be in velocity?

2) balls.setAll('body.velocity.x', 0);

this line will have this situation - when the group hit the sprite, the sprite will move together with the group. The sprite suppose to be static on the screen. Any solution for this?

 

 

**** I get the answers already. Thanks anyway.  ;)

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.