Skip to main content

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

Having issues detecting which tile a player is on

A topic by fufroom created Dec 08, 2016 Views: 423 Replies: 2
Viewing posts 1 to 3
(1 edit)

I am trying to detect what tile my player is on, I have an actor called "bg" that has a tileMapRenderer it points to a tileMap with one layer "0 - Layer" here is the code I am trying and the error I am getting:

 if (Sup.Input.isKeyDown("T")){ 
        var tileMap = Sup.getActor("bg").tileMapRenderer.getTileMap();
        Sup.log( tileMap.getTileAt(0, this.actor.getX(), this.actor.getY()) );
      }

error: "Uncaught TypeError: Cannot read property '0' of undefined"

 if (Sup.Input.isKeyDown("T")){ 
        var tileMap = Sup.getActor("bg").tileMapRenderer.getTileMap();
        Sup.log( tileMap.getTileAt(1, this.actor.getX(), this.actor.getY()) );
      }

error: "runtime.js:336 Uncaught TypeError: Cannot read property 'data' of undefined"
I checked the data coming back from this.actor.getX() / this.actor.getY() and they are both always a float.

I am stumped, thanks for any help!

(+1)

Sorry for a late response, but your problem is related with passing floats to the function. You should use:

Math.floor(axis_position);

In order to make them integers. Also you need to consider the tile position for example if you're doing a sidescroller then tiles will be actor_position - 1 on Y axis (Since the player will be walking over the tile) if you are doing a top down view then you shouldn't have that problem.

Thanks so much, I didn't realize It was asking for tile column and row number!