» Edit Game Info

4 years ago by Attanar

I'm making a super Mario style game.

As far as I know, tiles can't trigger actions, so if I want to add breakable "blocks" to the game, these should be Entities, and not just tiles in the map.

Did that, but noticed that when my player is running over a platform made of blocks (entities) it is not getting it "standing" property set to true, and therefore not playing the "run" animation, but the "jumping" one.

So, what is the best way to detect if my player is standing on a Entity? Should I manually set "standing" to true on collision depending on where the collision took place? I guess there must be a simple solution to this.

Thanks in advacne for your help :)

4 years ago by drhayes

Don't abandon the tilemap yet! Check out Entity::handleMovementTrace. You can override that method in your Mario entity and take a special action if it collides with the collision map from a certain direction or with a certain speed.

Another thing to consider is to not play the jumping animation unless there's a change in y velocity. It works for me.

4 years ago by collinhover

The standing property is completely unstable in ImpactJS as far as I can tell. I agree with drhayes, as that is what I did, but you'll also need to override the collideWith function. Add a grounded property to your entities that is true when the collision map result has a collision on y and your velocity is positive, and also set it to true when the entity passed to collideWith has a collides property of ig.Entity.COLLIDES.FIXED (or possibly ACTIVE, depending on your game).

4 years ago by Joncom

Quote from collinhover
The standing property is completely unstable in ImpactJS as far as I can tell.
I wouldn't say it's unstable. It's just that it has never been intended to work for "standing on entities", only on collision tiles.

4 years ago by Attanar

Thank you guys.

I already considered using the handleMovementTrace method you suggest, but the problem I found was there is no way in Weltmeister to assign properties to tiles. Therefore I don't think it is possible to mark some tiles as "breakable", like Super Mario bricks.

4 years ago by Datamosh

You can use a tile to mark where is "breakable" and update BackgroundMap.

Read last question and the Dominic answer in this post:

4 years ago by Attanar

Thanks for your help Datamosh.

I understand I can manually modify the map, but the question is, how can I know that the tile being hit by the player is breakable?

As far as I see, I only recieve the x and y position of the tile. That doesn't mean anything to me.

The only way I can figure out is by fetching the tile map array, check [x,y] tile and see what number it has, but the point is I have no idea on what numbers weltmeister is giving to each tile, I would have to try debugging the compiled game. That doesn't look like a very good practice to me :S

4 years ago by Attanar

OK forget what I just said, now I get what you mean and how backgroundMap uses identifiers for each tile.

The only problem I'm finding is that when the player collides with the map, I check for:

res.tile.x and res.tile.y

And they are always 1,1 or 1,0.

How do you find the real x and y position of the tile colliding with?

Thanks :)

4 years ago by Attanar

Well, I've been trying for hours and this is what I found:

1 - res.pos is the same as player.pos. It is NOT the tile position.
2 - res.tile.x/y is 1 or 0 depending on where the collision took place on the x or y axis.

With only that information, I am completely unable to determine the exact position of the colliding tile.

The player could be colliding with 2 tiles at the same time in the X axis, and since it can collide at different heights, there is no way, with only this information, to detect the exact position of the colliding tile.

Note that the player is slightly bigger than the tiles, in case it was bigger it could be even colliding with 3 tiles at the same time.

4 years ago by drhayes

Completely unable to? Sounds like a job for... breaking it down! ( ;

This works for either velocity, but we'll focus on the y since that's where most of your Mario-style tile interaction is gonna focus.

If you have the player's x and y position then you can convert it to a tile position using the Map's tilesize property. That, of course, gives you the tile under the x,y of the upper-right of the player; not super useful, I agree.

However, you also have the y velocity of the player and the direction of the collision from the res.tile argument to handleMovementTrace.

If the player's y velocity is negative (moving up) and res.tile.y is 1, then you know the player bumped into the tile above them. That only gives you one tile, I agree. You have to manually iterate over the tiles yourself based on the size of the player entity. Since your player entity's size in the x is greater than your tile's width, a quick Math.round(player.size.x / map.tilesize.x) + 1 will tell you how many tiles you have to check. That +1 is there because you could be overlapping the border between two tiles.

Given the player's x and a call to map::gettile you can get the position of the left-most tile above the player's head. Use your player's y position -1 in the call to get the tile above. You can then iterate over the correct number of tiles and check that they are within your player's bounds in the x.

Technically, the player has collided with each of the those tiles. If you want to do Mario-style, figure out which tile has the majority of the player entity's size; that's the one the player hit. Whichever tile (or tiles, depending on how small they are) is completely within the player's x bounds is the one that should get checked for special behavior.

For tiles below the player, add the player entity's y size + 1 to get the tiles below; the horizontal calculations are the same.

Is that what you're looking for?
Page 1 of 1
« first « previous next › last »

Post Reply

Please login or register to reply.