8 years ago
by Donzo
Hello:
I want to make an enemy walk all the way around the platform.
Like this:
!ig.game.collisionMap.getTile
to detect when he's near an edge on the X axis.
How can I detect when he's near an edge on the Y axis?
8 years ago
by Donzo
NM. I figured out how to use it.
8 years ago
by Donzo
I will post my solution for posterity:
checkTiles: function(){
//Tile Margins
var tMX = 7;
var tMY = 7;
//Tile 1
if (!ig.game.collisionMap.getTile(this.pos.x - tMX, this.pos.y - tMY)){
this.cT1 = false;
}
else{
this.cT1 = true;
console.log("CT 1 is True");
}
//Tile 2
if (!ig.game.collisionMap.getTile(this.pos.x + this.size.x / 2, this.pos.y - tMY)){
this.cT2 = false;
}
else{
this.cT2 = true;
console.log("CT 2 is True");
}
//Tile 3
if (!ig.game.collisionMap.getTile(this.pos.x + this.size.x + tMX, this.pos.y - tMY)){
this.cT3 = false;
}
else{
this.cT3 = true;
console.log("CT 3 is True");
}
//Tile 4
if (!ig.game.collisionMap.getTile(this.pos.x - tMX, this.pos.y + this.size.y / 2)){
this.cT4 = false;
}
else{
this.cT4 = true;
console.log("CT 4 is True");
}
//Tile 5
if (!ig.game.collisionMap.getTile(this.pos.x + this.size.x + tMX, this.pos.y + this.size.y / 2)){
this.cT5 = false;
}
else{
this.cT5 = true;
console.log("CT 5 is True");
}
//Tile 6
if (!ig.game.collisionMap.getTile(this.pos.x - tMX, this.pos.y + this.size.y + tMY)){
this.cT6 = false;
}
else{
this.cT6 = true;
console.log("CT 6 is True");
}
//Tile 7
if (!ig.game.collisionMap.getTile(this.pos.x + this.size.x / 2, this.pos.y + this.size.y + tMY)){
this.cT7 = false;
}
else{
this.cT7 = true;
console.log("CT 7 is True");
}
//Tile 8
if (!ig.game.collisionMap.getTile(this.pos.x + this.size.x + tMX, this.pos.y + this.size.y + tMY)){
this.cT8 = false;
}
else{
this.cT8 = true;
console.log("CT 8 is True");
}
},
I am checking for collision tiles around the entity in 8 directions.
I am using this information to change the behavior of my entity.
8 years ago
by Joncom
Thanks for sharing your findings.
Page 1 of 1
« first
« previous
next ›
last »