Drawing to a minimap + clearing offscreen objects

This forum is currently in read-only mode.
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • So making a tile based map editor seems to be a pretty great way to learn more about Construct. For the most part there are a lot of tutorials that do a great job of showing the ropes.

    I have one pressing current issue that I have no idea to solve, and one issue I know is going to come up which I want to know if I'm headed the right direction before I start working on it and how to get started.

    So I have a minimap. It shows my sprites position on the map just fine. I have it so you can click a different spot on the map and it will take you to that spot so you can work on a different part of the map. The part I have been working on now is having the different tiles being represented in the minimap. I expect this to cause some slowdown eventually considering I'm creating objects for each tile and at 256 * 256 of these objects if you filled the map this would be 60,000 objects on the screen at once. Even if I turned the minimap into a proper array I imagine this would still cause me problems. Is there any way to do this?

    Also I notice that it slows down after I have about 20 tiles on the minimap. I think this might be because my main layer scrolls, and the minimap is on a seperate non-scrolling layer but I'm not sure.

    The second issue I know I am going to face is that since the map can be set to any size, if I create something as big as 500 X 500 tiles wide (I'm using 32 x 32 size tiles) I will need to come up with a system to destroy offscreen objects. This is something I see referenced a lot when I search the forum, but I haven't found a definitive way to do it.

    My guess is that I use the same array that I use to populate the map with tiles, I give it a depth of 2, and I use the second layer to determine the location of my sprite and destroy anything that isn't within a certain amount of tiles around that point. Although I understand the concept of an array, I am unsure of EXACTLY how to do this. Is this the right way of doing this, and can anyone give me an idea of where to start or how to work with an array in this way?

    I think after I finish this map editor I would like to work on cleaning it up and properly commenting it so I can post it and it can help other people learn to do all of these things, as they seem pretty necessary if you want to make something on a larger scale.

  • Have you tried the minimap object? It has a draw terrain action that uses the image of an object to draw.

  • how do you get the sprites to represented on the minimap?

  • Using the minimap object I did it like this:

    PlayerSprite is visible > Minimap: Clear Terrain

                              Minimap: Set Terrain to PlayerSprite scale 2

    If you don't like the minimap object then try looking at this tutorial:

    http://69.24.73.172/scirra/forum/viewtopic.php?f=8&t=5867

    Basically use lerp to position a tiny version of your sprite over a canvas. I might use a mixture of the two techniques if I can even get the minimap object to work properly. For some reason it won't work with boxes, it keeps putting them in the map as white squares.

  • Well seems like I got the minimap to work decently. I just have to see if I can get it to function based on the contents of my array instead of objects on the screen. This way when I delete objects not on the screen it won't just clear the minimap.

    I worked out my own little "field of view" system and made another .cap just to play around with the contents of arrays and learn ways to manipulate them. Here's to hoping this all works!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So here is where I'm at with this.

    <img src="https://dl.dropbox.com/u/69407974/destroy%20object.jpg" border="0" />

    This just deleted everything, so I added in inverted "Object is on screen" conditions.

    Now it deletes all the squares I want it to. Yay!

    The trouble now is creating them again as I move. This is where I'm currently stuck.

  • I am currently at a point where I've figured out how to delete objects that aren't visible on the screen. The plan is that when you move around with WASD the screen will be repopulated with tiles based on what is stored in the array.

    I have 2 tiles. A default one (represented by '1' in the array) and a PAth tile (represented by '2' in the array.) I have them both set to change the corresponding value in the array when you place them.

    I'm working on setting the W key to repopulate the screen (ASD don't do this yet) but for some reason the Path tiles just disappear when you move down and and only default tiles are filled in when you go back up.

    here is the link to my .cap file. It's cleaned up and commented as well as I can manage, and there is a Read Me group with more information inside.

    dl.dropbox.com/u/69407974/Map%20Editor%202.cap

    Can anyone take a look?

  • Here's an observation: Every time you destroy a tile another one needs to be created at the other end of the screen. You could store the array positions of each tile in the created tile's private variables, that would help in changing the tile. You could then do a loop to check to see if the tiles around the border of the screen exist, if they don't then create the object.

    Here is a different approach that recycles the tiles by moving them to the other side of the screen as they move off screen. This is done by having different tiles represented by different animation frames of one sprite.

    http://dl.dropbox.com/u/5426011/examples14/tilesFromArray.cap

  • Did you just effortly recreate a better version of my project that has taken me like 2 weeks in an hour or what? <img src="smileys/smiley36.gif" border="0" align="middle" />

    Anyways the different animation frames thing is pretty great, I would have never thought of that.

    It's going to take me awhile to wrap my head around this, even getting to where I've got has had me racking my brain and writing out text files trying to conceptualize each event.

    Thank you!

  • So it took me a couple of hours, but I've learned some cool things now, and I've implemented the relevant code into my project. It works beautifully! I was even able to create a 1000 x 1000 map. Even though it flickers when I teleport my sprite to a new location, at least I know it is working.

    Not that I want them to even be that big (what would I do with it?)

    Anyways, now I'm on to the task of fixing the damn minimap.

    I've tried a few things here, and since I can't even think of a way to test this, I'm not sure what else to try.

    I had my minimap set to put a different tile into it based on any value in the array that was a 2. It worked great. I've checked that the squares i'm changing are indeed changed to 2's in the array, so I'm not sure why it doesn't put anything on the minimap.

    I also tried changing the event to a "For Each Object" setting my sprite as the object, and setting another condition that the animation frame is 2.

    What gives?

  • You could add "while" conditions to the top of each of the events that compare x and y, that would allow for motion beyond a screen at a time without flickering. I should also point out that the player should be moved in events above the scrolling events.

  • Works like a charm.

    I fixed my minimap issue more or less. I have one bug where it seems to be reacting weirdly but I'm sure I'll sor that out.

    I was treating "draw terrain ________" as if that were only an image I was picking to plot whatever the condition was for, instead of picking the actual object I wanted to plot.

    Now on to saving and loading! (and I can let this thread die finally)

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