I have created a Tiled map and i’ve a little problem.
The follow tiled have a property which (should) return value “oui”.
I have not succeded in writing a PYTHON code. Can you help me ?
For example, i want to print ‘HIT’ when the submarine picture ( that is load in the “While”) is in the red area.
Can you write me a function please ?
Thank you !
What do you mean by “return value”? Is this in Tiled, or in a game engine? If it’s an engine, please specify which one. If this is in Tiled, then unless I’ve misunderstood what you want, it sounds like you’re trying to make gameplay in Tiled, which is not possible.
In-engine, the geneeral procedure for things like this:
- Every time the submarine changes position, check the tile(s) it overlaps.
- Read their “murs” property*.
- If “oui”, print “HIT”.
- The way to do read the property depends on your engine and how it interprets the data from your Tiled file. If it leaves the tile IDs and the tile list intact in memory, then you could look up the tile ID and read its properties there. If not, then you will need to add code that runs whenever the map is read to keep the data you want to keep, perhaps in a separate “murs” boolean array (true/false). It’s also possible that they keep the custom properties in some other way, depending on the engine/importer. Either way, this is something you need to figure out in your engine/import plugin, not in Tiled.
Since it looks like this is meant to just be collision (going by the property name “murs”, walls)
If you’re using something like SuperTiled2Unity or another pre-built plugin for your engine of choice, then why not use their built-in support for Tiled’s collision features? If you add a whole-tile collision block to each tile that’s meant to be collision, then you don’t need custom properties, and most plugins will take care of the result using the engine’s native collision features.
To edit collision, open up your tileset (click the wrench icon underneath the tile palette) and click the icon right between the Terrain tool and the Wang Sets tool:
This will open up an editor that lets you draw polygons on the currently selected tile. So, pick a tile you want to be a wall, then click the “Draw Rectangle tool”:
And draw a rectangle spanning the entire tile. Repeat this for your other “wall” tiles.
I would like to print ‘HIT’ in the Python Console. So i need to have a function in my program to check the tile’s value ? ( “oui” or “non” )
Do you have an example of code ?
I’ve another question : Does collision property work with picture ?
Because, in my Python program, i load a submarine picture ( in the “while boucle” ) and i want it to stop when it’s on a wall.
Thank you !
Ps. I’m french
@Mine_Code Welcome to the Tiled forum!
Please note that you can upload your images here on the forum. Please do this, since it makes them easier for us to see them, plus we don’t have to watch the ads. I’ve now downloaded and uploaded the images you’ve posted earlier.
About your problem, I see that you are using Pygame. You may not easily find somebody here who has experience with Pygame, since there are a lot of game development frameworks out there that people are using with Tiled. You may want to try asking in the Pygame community (maybe on Reddit) or to try asking the author of the Tiled extension you’re using directly.
I’ve succeded in creating the player Sprite. I just don’t understand how to write a function which check if it collides with a wall…
I’ve search for 4 days on Google…