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:
If anyone can tell me what I'm doing wrong or missing I would love you forever. Thanks for reading :).
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 :).