Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Zetaphor

Hello everyone, let me start by thanking Dom for this excellent engine. I was hesitant at first, but it has definitely been worth the investment of my $99.

I've been fortunate to find the answers to all of my questions thus far in either the documentation or by a previous question in the forums. Though with this particular problem, I can't seem to find an answer.

I'm attempting to detect which tile in my tileset the player is currently standing on. I will be using this to trigger reactions in the player entity, an example being walking on ice tiles will reduce the players friction.

Here is a snippet of the code I'm currently using to retrieve the tile

	handleMovementTrace: function( res ) {
		if( res.collision.y ) {
			console.log('tile: '+ig.game.backgroundMaps[0].getTile(res.pos.x, res.pos.y+2));
		}

The problem here is that no matter which tile I'm standing on, the value is always 1. I'm looking for a value that corresponds with the particular tile in my tileset.

I've looked at the getTile and setTile methods, but I can't seem to make enough sense of it to achieve my goal.

FYI: I'm using the provided Biolab player sprite and level tileset, I've simply changed the color of a couple of the second row tiles.

Any help would be greatly appreciated.

1 decade ago by dominic

So you want to get that tile number from your main background layer, right? Are you sure backgroundMaps[0] is your main layer?

The order inside the backgroundMaps array corresponds to the drawing order - 0 is the layer that is drawn first; i.e. the bottommost layer. The layer 1 is drawn afterwards to occlude parts of the previous layers, and so on.

1 decade ago by Zetaphor

Correct, I want to retrieve the tile from my main layer. And no I'm not sure that 0 is my main layer, would re-ordering them in weltmeister effect this?

Edits: I looked at my level.js and found that the main layer is 1, going to try messing with that and some suggestions from IRC.

- Turns out backgroundMaps[0] is undefined

1 decade ago by dominic

Yes. If you re-order layers in Weltmeister, you change their drawing order by changing the order in that array. Note though, that the entity and collision layers are excluded from this ordering. The backgroundMaps array only holds background maps and always starts at 0.

You could overwrite the Game's loadLevel() method if you want to identify the main layer by it's name, instead of by it's position in the backgroundMaps array.

1 decade ago by Zetaphor

Still not sure if I'm on the right path though, what should I be using to find the sprite index in the tileset for a given tile?

1 decade ago by Zetaphor

Ok, I've got it all figured out now. I was right in using getTile, the problem was in my offsetting of the coordinates for the tile. Thank you Dominic and tjbladez for all the help!

Figures it was something simple :-P

1 decade ago by tjbladez

Good luck and kick ass :)
Page 1 of 1
« first « previous next › last »