Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by MobileMark

In my game I'm trying to have the main character walk through a trigger and change the gravity level. I have the trigger set but I can't seem to get the right syntax for reaching back into the main.js and changing the variables. Does anyone know the right syntax?

1 decade ago by MikeL

To change gravity generally (without Box2D), you should be able to use:

ig.game.gravity = someGravity; //whatever the gravity setting should be

You can generally use ig.game.someVariable to access 'global' game variables from your game.main module, even new ones that you create yourself.

However, to do it specifically for Box2D then you have to follow Dominic's advice below.

1 decade ago by dominic

If you use the Box2D plugin, the ig.game.gravity variable is only handed over to Box2D once when creating the world. If you want to change the gravity afterwards, you'll have to set it for the world again:

var gravity = new b2.Vec2( 0, someGravity * b2.SCALE );
ig.world.SetGravity( gravity );

See: http://www.box2dflash.org/docs/2.0.2/reference/Box2D/Dynamics/b2World.html#SetGravity%28%29

1 decade ago by MobileMark

Thanks dom

1 decade ago by Montana

""Quote from MikeL
To change gravity generally (without Box2D), you should be able to use:

ig.game.gravity = someGravity; //whatever the gravity setting should be

You can generally use ig.game.someVariable to access 'global' game variables from your game.main module, even new ones that you create yourself.



Please excuse my ignorance, but how do you set that variable in the editor (welmeister) or in the code? Cant seem to work it out :-(

1 decade ago by Montana

Ok I got the gravity to change, but i thought it would revert when the collision was no longer true .. so i'll post it as is and update when i work it out :-)

ig.module(
	'game.entities.wind'
)
.requires(
	'impact.entity'
)
.defines(function(){

EntityWind = ig.Entity.extend({
	_wmScalable: true,
	_wmDrawBox: true,
	_wmBoxColor: 'rgba(255, 170, 66, 0.7)',
	
	checkAgainst:ig.Entity.TYPE.A,
	update: function(){},
	
	check: function(other){
	ig.game.gravity = -120;
	}
})
});

1 decade ago by Montana

embarrisingly , i did this:

ig.module(
	'game.entities.norm'
)
.requires(
	'impact.entity'
)
.defines(function(){

EntityNorm = ig.Entity.extend({
	_wmScalable: true,
	_wmDrawBox: true,
	_wmBoxColor: 'rgba(55, 22, 60, 0.7)',
	
	checkAgainst:ig.Entity.TYPE.A,
	update: function(){},
	
	check: function(other){
	ig.game.gravity = 300;
	}
})
});

and then drew boxes around the wind area to change gravity back .. if soem kind soul wants to take pity on me i'd greatly appreciate it!

I guess im looking for a "while colliding" option?

1 decade ago by zedd45

have you tried the Entity's "collideWith" method:
http://impactjs.com/documentation/class-reference/entity#collidewith

?

1 decade ago by jerev

I truely hope he figured it out by himself after 2 years ;)
Page 1 of 1
« first « previous next › last »