Hey Community,
are the collisions calculated by the collisiontiles-image or via code?
if (not) {
Is there a way to do this easily?
}
Greetings
DevPlanet
9 years ago
by Joncom
Collisions are calculated via code. Modifying the image for a collision tile will have no effect on the collision behaviour.
Is there a way to [calculate collisions from collision-tile-images] easily?
I don't know if I would say "easily", but it's definitely "doable".
You could make some layer that you fill with "collision image tiles". Then at runtime, you would loop through this layer (it&
039;s just a normal layer, not a collision layer), and read the pixel data from each tile, checking to see if the pixel is solid or transparent. You'd then make a new instance of #ig.CollisionMap
with a tilesize of 1. And for all the pixels that were solid, you make the collision-map solid. And for all the pixels that were transparent, do nothing.
Hmm ok, thanks for your detailed answer. :)
You can also override the collision tile code. In a recent game I made for Ludum Dare I force the player to fall through the collision tile #12 that normally allows moving upwards only (the pink block with the up arrow).
I added this in the entity I want to fall if he has the right items:
,
handleMovementTrace: function(res) {
this.parent(res);
var upwardPassageOnlyTile = 12; //12th tile on collision tiles (0 is air empty for air, so tiles start at 1)
var tileSize = 8;
var toe = this.pos.y + this.size.y+1;
// toe touching upwardPassageOnlyTile ?
if (ig.game.collisionMap.getTile(this.pos.x + (this.flip ? +6 : this.size.x - 6), toe) == upwardPassageOnlyTile) {
if ((this.hasItem.coin || this.hasItem.goose || this.hasItem.harp)){// toe is on upwardPassageOnly tile
this.pos.y +=10; // force down no matter what collision tile is there
}
}
if( res.collision.x ) { this.flip = !this.flip; } // collision with a wall? return!
}
Page 1 of 1
« first
« previous
next ›
last »