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 Oliver

Im really new using box2d and i know its a dumb question, but i really cant get my entitys to be circular! i know im missing only 1 line, but i cant get witch one.
mixing code i found on posts here and there i did the "player.js" init funcition look like this:

init: function( x, y, settings ) {
		this.parent( x, y, settings );
		//this.addAnim( 'idle', 1, [0] );
                var b2CircleShape = Box2D.Collision.Shapes.b2CircleShape;
                var blFixDef	= new Box2D.Dynamics.b2FixtureDef();
                blFixDef.shape	= new b2CircleShape();
                var hw = 5 * 0.5;	// "half width"
                var hh = 5 * 0.5;	// "half height"
                blFixDef.shape.SetRadius(hw);
                var newX = (this.pos.x + this.size.x) * Box2D.SCALE ;
                var newY = (this.pos.y + this.size.x) * Box2D.SCALE ;
                var bodyDef = new Box2D.Dynamics.b2BodyDef();
                bodyDef.position.Set(newX, newY);
                //ig.world.CreateBody(bodyDef).CreateFixture(blFixDef);
		//this.body.DestroyFixture(this.body);
                //ig.world.DestroyBody( this.body );
		//this.body.CreateFixture(blFixDef);
		console.log(this.body.GetFixtureList());
		//this.body.SetMassData(blFixDef);
                //this.body.shape = bodyDef;
	},

it obviously doesnt get blFixDef and bodyDef porperties because i am missing that line. Could someone share his awesomeness with me? Im getting really mad with this :(

1 decade ago by Joncom

Using this plugin takes some of the thinking out of Box2D.

By default, all entities are rectangles, like in Impact.

But if you want a circle, just extend the circle entity found in the entities folder.

If you want a pill shaped entity (which is commonly used for the player), extend the capsule entity.

If you want a more complex shape, just extend the polygon entity.

Edit: Also allows you to control your entities with .pos and .vel, etc.

1 decade ago by Oliver

Im using box2d-sugar and it works great! But now im having another problem, im trying to get the player to do something when it touches another entity using "this.touches()" but i cant get it to work well
Here is my player:

ig.module(
	'game.entities.player'
)
.requires(
	'plugins.joncom.box2d.entities.circle'
	//'impact.entity'
)
.defines(function(){
EntityPlayer = EntityCircle.extend({
	animSheet: new ig.AnimationSheet( 'media/player.png', 50, 50 ),	
        radius: 25,
	isFixedRotation: true,        
	name: "player",
	
	init: function( x, y, settings ) {
		this.parent( x, y, settings );
	},

	update: function() {
		if (this.touches(ig.game.getEntitiesByType(EntityLibro))) {
			console.log("im touching you");
		}
		this.parent();
	},
});
});

and here is the entity "libro"

ig.module(
	'game.entities.libro'
)
.requires(
	//'impact.entity',
        'plugins.joncom.box2d.entity'
)
.defines(function(){

EntityLibro = ig.Entity.extend({
	size: {x: 200, y:200},
	type: ig.Entity.TYPE.A,
	_wmBoxColor: 'rgba(255, 0, 0, 0.7)',
	_wmDrawBox: true,
	//animSheet: new ig.AnimationSheet( 'media/player.jpg', 50, 50 ),	
        isSensor: true,
	name: "libro",
	angulo: 0,

	init: function( x, y, settings ) {
		this.parent( x, y, settings );
		//ig.game.libro = this;
		this.angle = this.angulo;
	},

	update: function() {
            this.parent();
	},
});

});

The result of this is that if i use ig.game.getEntitiesByType(EntityLibro) the IF never acts, and if i use ig.game.getEntityByName('libro') it only acts when the player touches the last "libro" placed in the level in weltmeister. Could someone help me with this?

1 decade ago by Joncom

You're not looping correctly.

// This is an array.
var entities = ig.game.getEntitiesByType(EntityLibro);

// Check all entities.
for(var i=0; i<entities.length; i++) {
    if (this.touches(entities[i])) {
        console.log("im touching entity " + entities[i].id);
    }
}

1 decade ago by Oliver

i'm feeling really dumb right now, Thank you man.

1 decade ago by Joncom

No worries. And by the way, ig.game.getEntityByName(name) does not return an array. It will only ever return exactly one entity, or undefined. The idea behind it is you give entities unique names, then they are easy to grab with that function.
Page 1 of 1
« first « previous next › last »