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 vidja_games

I have been confused as to why some code I've been toying with is not working as expected. I have a bug class that spawns in a bug and moves it west. Before it moves, it does a collisionMap.trace to check to for a static collision. No matter what I seem to do, it refuses to detect a collision.

I spawn the bug with:
ig.game.spawnEntity( 'EntityBug', 64, 64, {});

The map is tilesize of 8 and has a collision layer around the perimeter of size 8.

the class is here:
ig.module(
	'game.jsentities.bug'
)
.requires(
	'impact.entity'
    ,'impact.timer'
)
.defines(function(){

EntityBug = ig.Entity.extend({
	
	size: { x: 16, y: 16 },
    
    tileSize: null,
    
	init: function( x, y, settings ) {
		this.parent( x, y, settings );
        
        this.tilesize = ig.game.collisionMap.tilesize;
        
        this.animSheet = new ig.AnimationSheet('media/arise.png',32,32);
        this.addAnim( 'idle', 0.2, [0] );
        this.currentAnim = this.anims['idle'];
        
        this.size.x = this.animSheet.width;
        this.size.y = this.animSheet.height;
	},
    
    moveWest: function( numTiles ){
        var collisionTrace = ig.game.collisionMap.trace(this.pos.x,
                                        this.pos.y, 
                                        this.tilesize * numTiles * -1, 
                                        0, 
                                        this.size.x, 
                                        this.size.y 
                                    )
        if(!(this.pos.x < -1)){
            ig.log(collisionTrace);
        }
        if(!collisionTrace.collision.x){
            this.pos.x = this.pos.x - ( numTiles * this.tilesize );
        }
    },
    
	draw: function()
	{
		this.parent();
	},
	
	update: function()
	{
		this.parent();
        this.moveWest(1);
	}
	
});

});

If anyone can tell me what I'm doing wrong or missing I would love you forever. Thanks for reading :).

1 decade ago by vidja_games

bump

1 decade ago by jswart

The first thing I would do is use a

console.log(ig.game.collisionMap.tilesize);

to see if that has a value.

My other thought is that:

  update: function()
    {
        this.parent(); // <-- this could be over writing your moveWest method
        this.moveWest(1);
    }

Those are my thoughts.

1 decade ago by vidja_games

it was
update: function()
    {
        this.parent(); // <-- this could be over writing your moveWest method
        this.moveWest(1);
    }

Thank you very much, 10 cookies for you.
Page 1 of 1
« first « previous next › last »