How to I change a variable of a sprite depending on which tile (of a tilemap) it is overlapping?

0 favourites
  • 8 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hia folks,

    I am trying to create a map sort of feature. Very succinctly, I am trying to get each "square" of the map have it's own "resource value" depending on the tile that it is overlapping. Basically, I want to show how many "bundles" there are to collect for villagers, when the mouse is over the trees in the map.

    I have a tile map underneath the grid. The grid is composed of rows and columns of a sprite called "mapSquare". The mapSquare instances and the tiles overlap precisely. The sprite has a variable called "mapSquare_Bundles". My aim is to change that variable depending on which tile is beneath each instance of said sprite.

    Any comments are more then welcome :)

  • Here you go: 1drv.ms/u/s!AkmrWgxeuxlKhIdYm8XDr_dp3KCtdA

    Is this the basics of what you are after?

  • You can get the tile ID of the tile at any position with the expression Tilemap.TileAt(PositionToTileX(x),PositionToTileY(y))

  • Hi guys, thanks for the suggestions and the example as well!

    When I try that in a new project it works the way it should, however, it's not working in my project and I don't know why.

    I don't know if it's worth mentioning, but there are 2 instances of the same tilemap on top of each other (one has the grass and the other has the objects like trees and river and bridge). I have tried referencing the instance of the tilemap by picking it via its own UID, but still no result.

    Any ideas why?

  • Are no mapsquares being set? Are the wrong ones being set? Are you checking in debug mode or just seeing if your text is showing?

    It's easier to diagnose a problem like this if you actually uploaded the project rather than just a screenshot of events. You also have hidden events. I don't know if the mouse over and for each conditions are causing problems displaying the text, normally you wouldn't need both together in a single event. Do you have multiple overlapping mapsquares?

  • Hi there, thanks for the reply!

    I've not uploaded the project previously as it's pretty big and has many other things in there. I've truncated a copy of it with just the things needed in regards to my issue, link below :)

    I have already checked in debug mode, the instances don't get the variable changed for some reason. I've also tried to force them to change on mouse over the mapSquares. The square maps are created at startup over the tilemap as you'll see. I've also removed the "for each" conditions from mouse over actions but still did not fix the issue.

    The layout has a 9-patch at the bottom (the "frame" of the map) and 2 instances of the same tilemap as stated previously. The UI General sheet is the one you want.

    Thanks very much in advance for any insights!

    https://we.tl/t-aynk06hls1

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Two things -

    You put TileToPositionX/Y, instead of PositionToTileX/Y.

    You will need to pick the correct tilemap out of the two. You can use UID or an instance variable.

  • Hi,

    Worked like a charm when I changed it to PositionToTileX/Y, thanks very much. Very silly me. I was already picking the correct instance of the tilemap, but I think I've just deleted it in the version I have uploaded.

    I think I know now what I was doing wrong. I was converting tile position TO mapsquare x/y when I needed to get tile position FROM mapsquare x/y.

    Please let me know if I'm right in my assumption.

    Thanks again very much!

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