Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
0
Members

Collisions with Tile Maps?

A topic by Ivan Fonseca created Mar 25, 2016 Views: 1,812 Replies: 3
Viewing posts 1 to 4
(3 edits)

Is there a tutorial available on how to do collisions with tile maps? I've tried adding an arcade boy 2d to it, setting it to tile map and putting in the number of the layers I want to collide with, but it didn't work. I have a arcade body 2d on the player actor as well. Here's my code:

class PlayerBehavior extends Sup.Behavior {

// Speed to move

speed: number = 1;

update() {

// Collide

Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, Sup.getActor("Level").arcadeBody2D);

// Move up and down depending on key presses

if(Sup.Input.isKeyDown("W")) {

this.actor.arcadeBody2D.setVelocityY(1 * this.speed);

} else if(Sup.Input.isKeyDown("S")) {

this.actor.arcadeBody2D.setVelocityY(-1 * this.speed);

} else {

this.actor.arcadeBody2D.setVelocityY(0);

}

// Move left and right depending on key presses

if(Sup.Input.isKeyDown("A")) {

this.actor.arcadeBody2D.setVelocityX(-1 * this.speed);

} else if(Sup.Input.isKeyDown("D")) {

this.actor.arcadeBody2D.setVelocityX(1 * this.speed);

} else {

this.actor.arcadeBody2D.setVelocityX(0);

}

}

}

Sup.registerBehavior(PlayerBehavior);

(Sorry about the formatting)

Does anyone have any suggestions?

You could take a look at the Pac-man-like that Sparklin Labs made. I'm pretty sure it uses tile maps for collisions. You can download the project from GitHub, put it in the projects folder and restart Superpowers for it to appear in your launcher. They also have a few videos they made that goes through the entire process for making that game.

(+1)

There is a 2D collision tutorial on the Superpowers website. Here is the link:

http://docs.superpowers-html5.com/en/tutorials/col...

I recommend not to just copy and paste the whole thing into your game and to try and recreate it yourself, you will learn a lot more in the long run! :D

I'm gonna hijack this topic for my own TileMap collision related question:

Is there any way to change an aracadeBody 2D in the middle of the game?

I'm trying to build a wall breaker clone at the moment, and I used a Michael Seyne's Sokoban-like way for handling the bricks (they're in a specific layer of a TileMap), but I used an arcadeBody2D for handling collisions (which is quite easy to use in this scenario). But I didn't find any code to change the TileMapAsset of that arcadeBody2D so I can't change levels by changing the TileMap (I will have the new tilemap correctly rendered but the arcadeBody2D won't match).

The only way I could change the arcadeBody2D is by loading a new scene, which means building a scene by level, an that seems to be more and more impractical as the level number goes up.