Jump to content

Add gravity to a sprites in group over time


Recommended Posts

Hey all, I'm building a little christmas game... I've attached a screenshot, got a set up of conveyer belts (sorta Donkey Kong-ish).  I've created a group of sprites (giftgroup) hiding behind the pipe in the top right corner. My goal is to add gravity to each sprite over time, maybe 1 every half second so that gifts keep pouring out of the pipe. Should I be trying to do this in the update: function() or is there a way to add the gravity when creating the group but somehow delay the creation of each sprite? I'm a phaser newbie still and novice javascripter so any help with this is appreciated!

	buildGifts: function(){					this.giftgroup = this.add.group();			this.giftgroup.enableBody = true;       		for(var i=0; i<this.totalGifts; i++){									var g = this.giftgroup.create(1000, 80, 'blueGift', 0000);								g.anchor.setTo(0.5,0.5);				g.body.moves = true;				g.animations.add('gifted', Phaser.Animation.generateFrameNames('gift', 0, 0, '', 4), 30, true);				this.game.physics.arcade.enable(g);				g.body.bounce.y = 0.2;			//	g.body.gravity.y = 1500;				g.body.velocity.x = 0;				g.inputEnabled = true;				g.events.onInputDown.add(this.destroyGift, this);						}


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.

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.


  • Recently Browsing   0 members

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