This site requires JavaScript, please enable it in your browser!
Greenfoot back
Minion1
Minion1 wrote ...

2013/1/6

Image comparison

Minion1 Minion1

2013/1/6

#
I'm probably WAY out of my league here.. but I need to ask. I am making a new scenario that uses a background picture created from tiles. I need to be clear here: the background picture was created from tiles, then saved as a PNG. It is NO LONGER constructed of tiles. What I want to know is, is there a way to tell the program to look at what is underneath my character to see what he is standing on? For instance, if he is standing on a mountain, do this, a lake, do this, etc. I realize that the safer method is to create the world out of the tiles themselves using the compiler, but I am curious to see if this is possible. Thanks.
Minion1 Minion1

2013/1/6

#
I left out a few details: The tiles I used to construct the map are 32x32 pixels, and the "cursor" I'm using as a character is also 32x32. I need to know if there is a way for the Greenfoot to look at the entire 32x32 tile image and compare it to one in memory so that it will return what kind of tile the cursor is sitting on. I'm trying to be as clear as possible, please let me know if it still doesn't make sense.
Minion1 Minion1

2013/1/6

#
I've been thinking about it all day and I think that what i need to do is pre-load the tiles themselves and using them teach the compiler to compare the tile to the space below the character. Has anyone done this before?
danpost danpost

2013/1/6

#
You could set up an array to map the world. It could be of 'int', 'String' or 'char' type (guess it could even be of 'Class' type -- not that I would recomend it). This map could be used not only to create the initial background, but also to determine what is where during game play. Another possibility is to use color detection to determine what is where. This would involve breaking the color up into its primary color components and checking the values for certain ranges to distinguish between the different types of terrain (brown=mountain, blue=water, tan=dirt, green=grass, white=ice, black=hole). As long as you can tell which is which among the ones that act differently (mountain, dirt and grass would all act similarly -- normal movement of actor without anything special), this method would work. There are other ways to 'cheat' the matter. Like making the top-left pixel of each image a different color to start with (if they were not already) and using them as the flag to indicate which is which (they all would be located at (32*x, 32*y) in a world of cellsize 32 and (32*(x/32), 32*(y/32)) in a world of cellsize 1).
You need to login to post a reply.