How do I implement collectible coins in a platformer game going directly to the HUD? [SOLVED]

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
112 High-Quality Coins and Chest SFX specially crafted for video games
  • Hi guys!

    I'm developing a platform game where collectible coins automatically go to the HUD in the top left of the screen when the character collects them in the stages, as in the image below:

    Since I couldn't do it using the bullet and Line of Sight behavior (!!!), I resorted to Lerp and/or Position to do it successfully.

    However, since the game's coins and the HUD are on different layers, the last coins collected are always shifted several pixels forward when they are collected, causing a strange effect.

    I tried to solve it using Viewport expressions and creating two variables (TargetX and TargetY), but I was unsuccessful (see image below).

    Does anyone have any suggestions on how to solve this in C2?

    Thank you in advance!

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Supposing that you have an "HUD" layer with parallax 0% where you want to position your coins after you collect them; the problem is that in your code you keep your coin in the same layer and you treat the hud coordinates the same way as the world coordinates.

    What i mean is that you may have your coin at position x:2000, y:2000 in your game world. If you simply move it to x:50 y:50, you're still moving the coin in the game world.

    So, what you need to do is move the coin to the HUD layer and set its position to the position the coin would have if it was on that layer to begin with. Basically you need to translate the coin coordinates from the "Game" layer to the "HUD" layer.

    Here's a revised version of the code:

    Note that Construct has specific expressions to make the translation easier:

    CanvasToLayerX(layer, x, y)

    CanvasToLayerY(layer, x, y)

    LayerToCanvasX(layer, x, y)

    LayerToCanvasY(layer, x, y)

  • Supposing that you have an "HUD" layer with parallax 0% where you want to position your coins after you collect them; the problem is that in your code you keep your coin in the same layer and you treat the hud coordinates the same way as the world coordinates.

    What i mean is that you may have your coin at position x:2000, y:2000 in your game world. If you simply move it to x:50 y:50, you're still moving the coin in the game world.

    So, what you need to do is move the coin to the HUD layer and set its position to the position the coin would have if it was on that layer to begin with. Basically you need to translate the coin coordinates from the "Game" layer to the "HUD" layer.

    Here's a revised version of the code:

    Note that Construct has specific expressions to make the translation easier:

    CanvasToLayerX(layer, x, y)

    CanvasToLayerY(layer, x, y)

    LayerToCanvasX(layer, x, y)

    LayerToCanvasY(layer, x, y)

    Thanks a lot, dude! It worked very well! :D

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)