How do I Incrementally Move Tiles

0 favourites
  • 11 posts
From the Asset Store
This is a code so you can see the same skin on all screens (peers). Each peer gets a skin, in addition to 4 directions t
  • I would like a basic run down or opinion on what the best way would be to incrementally move tiles in a tile map.

    In short, I am creating an endless runner and want to have the tiles in my tilemap scrolling to the left of the screen and anything that goes off the left of the screen gets destroyed.

    In a separate event sheet I am creating and setting a tilemap object in my main layout (I am also creating a character but that isn't important right now). I want the individual tiles to scroll to the left of the screen and all tiles that go off the left of the screen get destroyed. I want to be able to generate these tiles and get them scrolling to give the illusion of an endless level, there will be variations in height for the platforms but that I will deal with later haha.

    I have been trying for a 2 days messing with some logic. I came across this tutorial https://www.youtube.com/watch?v=I05TDijQx-Q which does seem to help a little until he starts moving the platforms, then I can't seem to translate what he is doing in Fusion 2.5 to Construct 2.

    I have learnt about expressions now and I am getting fairly comfortable in Construct 2.

    I have made a global variable which the guy in the video also does and he performs some math on that variable which basically creates the platforms. I have jumped ahead making this variable because I can't make my tiles scroll using the same method he does in the video because he is using objects and not a tilemap. I can make the tilemap itself scroll but then that isn't what I want to do as the tiles that get created won't be seen due to the tilemap scrolling off the screen.

    The reason I want to use a tilemap is because I have heard they work great in regards to performance and there is variations in the floor such as gaps and height which have specific tiles associated to that. Once I figure out how to get the tiles to scroll and not the tilemap itself, then I can start adding in rules to adjust the height and gaps of my tiles and choose the appropriate tiles that make sense (if that makes any sense lol)

    It seems very easy when I write down my thoughts of this process on paper but then using the conditions Construct 2 has to offer I feel a little lost on how to make the process work.

    The final result I want is to have an almost procedural generator which will generate my tiles as they scroll off screen and have variations in the tile gaps for obstacles such as spike pits or holes to fall down. In my mind I am thinking that I can make the tiles off screen on the right and have them scroll on screen, then get destroyed off screen on the left and this is a constant generation with all the variations I mentioned above working with rules to place the tiles in positions that make sense.

    Any help is appreciated

    Feel free to add me on Steam or Skype if you want to talk if you have the time. I would greatly appreciate it, I am still learning and although this may seem a simple task, it feels incredibly difficult for me to work out.

  • Still no answer on this?

    I've been trying to do this for 3 days now and cannot figure it out. I don't think it is possible to move tiles in a tilemap. I may have to look in to other ways to achieve this.

    I guess I could bring in my tiles as separate sprites and store those sprites in an array.

    Any help at all on this would really be appreciated, I'm surprised I've not yet got an answer on this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Full disclosure, I haven't worked on one of these so I may not be the best of help (But I see that you're looking for some ideas so I'l throw a few out there).

    So my initial thinking is that it might be best to use tiled backgrounds and then use the system to generate tiles as needed (either randomly or on a timer).

    https://www.scirra.com/tutorials/4777/h ... und/page-3

    https://www.scirra.com/tutorials/1019/b ... te-runners

    As for the array-to-tilemap implementation, maybe this tut can get you moving on a possible solution there:

    https://www.scirra.com/tutorials/746/au ... ise-method

    Hopefully this was helpful!

  • This is the best I could come up with using my lunch time. It looked a bit jerky to me so I tried maybe using an ever expanding tilemap instead of shifting the tiles and the tilemap. Can't decide if it makes things better... see for yourself!

    https://dl.dropboxusercontent.com/u/700 ... lemap.capx

    You would of course have to replace the "generateRandomColumn" function by one that fetch meaningful data. <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink">

  • Great examples guys. Thank you so much!

    I am still going through the material you guys have posted, so far it isn't exactly what I am looking for although I have still learnt some good techniques!

    My issue is that I am using a tilemap and need to make the tiles scroll. There is no condition or option for a condition or action that will allow me to scroll tiles that are within a tilemap (set the tiles positions).

    I can set the maps position and do simple math such as, every tick move the tilemaps position -1. This gives a scrolling effect but it moves the tilemap and not the individual tiles. So if I wanted to generate more tiles on the right of the screen I can't because the tilemaps position is constantly -1 on the X axis every tick.

    All I need is to make my tiles scroll across the screen, I can't seem to do this with a tilemap so I am trying to figure out ways I can use the tilemap to store my tiles (kind of like an array) to spawn and move the tiles X positions every frame to give a scrolling effect.

    I was thinking of saving my tilemap as a .JSON file and then loading that .JSON file into an array and then looping through the array to place down my tiles in my layout and have those scrolling but then I don't think that would work. I need something where I can set its X position every frame -1 to give a simple scrolling effect, I could do this with sprites and import every tile in my tile set as a sprite and store that in an array but this is for a mobile game and I need to be careful with performance (I have a lot of tiles and that's not including my character or prop sprites).

    I'm not looking for a level builder just an idea on the logic of how to make tiles in a tilemap scroll, by either setting their X position every frame or some other method somebody else knows about.

    Thank you though for your replies I really appreciate the material you have sent over, some very interesting techniques

  • After doing some thinking I realized that I could be using a sprite rather than a tilemap and still keep the performance relatively well.

    I've used one sprite object and I have imported each of my tiles in as animation frames. This way I can now manage each frame of the animation as it's own tile (similar to a tilemap) and still have the ability to set it's X position to every frame of the game to give a scrolling effect.

    This should make the generation of tiles a lot easier as well because now I can use my animation frames to figure out what tile can go next to another without the use of an array.

    Hopefully it is possible to do instances of sprites at different animation frames so my method can work this way rather than having a sprite object for each tile (which isn't what I want).

    I will continue to work on this and if this method works I will post a video and possibly write some information on the process, maybe I can make a sample .CAPX file and share that to the community as a thank you for everyone's help

  • I have been messing around with my idea of using a sprite object and storing each tile in its own animation state within that sprite object. This works great for storing each tile in one object. I can now set the X position of the sprite object in my layout to -1 every tick to get that scrolling effect.

    I've even made a global variable which I then use some simple math on to generate tiles on right side off my layout off screen so I get endless tiles scrolling across the screen.

    My problem now is that the tiles that are going off on the left of the screen I need to destroy, because I am using one sprite object for my tiles whenever I destroy those tiles with a condition that compares two values e.g Tiles.X < LayoutWidth("TilesLayer") -1, all of my tiles then get destroyed because each generated tile is an instance of the sprite object.

    Is there another method to destroy an instance without affecting all instances?

    If this isn't possible I may need to start looking into other ways to achieve this. It's frustrating that something like this is taking me so long considering that this program is so easy to use

  • System's "Compare two values" doesn't do any picking, thus all sprites get selected and destroyed as soon as the first tile reach the border. You can either add a "for each sprite" above your condition or ditch "Compare two values" in favor of sprite's "Compare X".

  • OMG!

    Thank you so much Magistross.

    That's it!

    I now have a simple system of tiles being generated on the right off screen and when they reach the left off screen they are destroyed. What a relief. I've been working all week to get this result, I can't thank you enough!

    Now I can progress and figure out how to change each tiles animation on this sprite object, depending on its neighboring tile. Like a procedural system. First though I will set the maximum height my floor tiles can be.

    Thank you so much Magistross, thank you!

  • Here is my progress after learning about the For Each loop (big thanks to Magistross)

    https://www.dropbox.com/s/4cipvzeay0a8oef/2016-03-18_00-04-29.mp4?dl=0

    I am now going to be adding the various heights to the floor, once that has been done I will be working on a 'tile sorter' which will check neighboring tiles and generate the correct tiles next to each other.

    I'm feeling very pleased with the results so far though and feel like some solid progress has been made. I am wondering if I continue to use the For Each loop for my tile checks this would work on a 'per tile' basis?

  • I've run into a small problem. The modulo operator doesn't seem to be working for me. I am comparing two values but my first value is X % (128/Y) = 0, I am still getting back a remainder which is giving me a decimal number and not a whole number. My order of operations is done using () so the division is done first and then the modulo which should bring me back a whole number.

    I am trying to use this to subtract 1 from a global value which is my gap length between my tiles.

    Here is a shot of the event sheet: http://i.imgur.com/pOkAedJ.png

    Here is the value of gap length in the debugger, I am not getting any gaps within my tiles either (my mouse cursor is over the gap length value box): http://i.imgur.com/cickRyD.png

    Anyone see where the problem is?

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