Jump to content

Groups, gravity and triggers


Recommended Posts

Hi , guys! I had a problem recently with traps, and i got a pretty good answer:


but i'm kind of stupid and i cant imagine how one would add several triggers and several traps. I learned about invisible triggers, and thats nice. But making a refference to a trap makes me uber confused, even more since i use the this. writing style.


The thing is, i have

this.physics.arcade.gravity.y = 1800

global gravity, so if i enable physics on a sprite, it will fall down. The only way i can keep it still is if i make a group and use

this.trap1.body.moves = false;

. Using it without a group makes my game not work somehow. I tried lots of things described in here


but still doesnt work.


Following the examples above , and this one http://www.html5gamedevs.com/topic/6993-goomba-move/, this is what i made:

function create() {this.triggerGroup = this.add.group();	this.triggerGroup.enableBody = true;	this.triggerGroup.physicsBodyType = Phaser.Physics.ARCADE;	this.trigger1 = this.add.sprite(640, 172, null, 0, this.triggerGroup);	this.trigger1.body.setSize(32, 62, 0, 0);	this.trigger2 = this.add.sprite(610, 172, null, 0, this.triggerGroup);	this.trigger2.body.setSize(1, 1, 0 , 0);		this.trapGroup = this.add.group();	this.trapGroup.enableBody = true;	this.trapGroup.physicsBodyType = Phaser.Physics.ARCADE;	this.trap1 = this.add.sprite(640, 50, 'trap');	this.trap1.body.moves = false;		this.trap2 = this.add.sprite(610, 50, 'trap', 0, this.trapGroup);	this.trap2.body.moves = false;					// store a reference to the trap this trigger sets off				// (if i hadnt put it in a group -.-)		//trigger.trap = trap;	},function update() {	this.physics.arcade.overlap(this.player, this.triggerGroup, triggerFunction(), null, this);},triggerFunction : function (player, trigger) {	if (!this.trigger.triggered) {		this.trigger.triggered = true;		dropTrap(trigger.trap);	}},

, and ofc it doesnt work.


Please, i spent like 10 hours trying to figure this out. Could you please explain it to me like im retarded?  Just need an example of 2 triggers with 2 spikes, one overlap test which works for both, and then activates gravity for the spike, or rather deactivates immobility.



Link to comment
Share on other sites


  • Recently Browsing   0 members

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