How do I create a 900 block grid?

0 favourites
  • 15 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Probably biting off more than I can chew for my second game, but there might be an easier way to do this than to create 900 sprites that are clickable and changeable.

    I have a 29x31 grid I want to be able to click each square and change it to a different object. It will be like a tower defense game.

    My fears:

    ... to do 900 sprite objects all by hand

    ... do it in an un-optimized manner where the game won't run properly

    ... run into a dead end and have to start from scratch.

    Any helpful suggestions, words of wisdom, or places to start would be greatly appreciated.

  • on START LAYOUT

    FOR 1 TO 900

    SYSTEM CREATE "!"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't use skype anymore, I use discord. Unfortunately, I can't send you a pm, I'm too new.

  • The for loop are amazing. Id would do something thing like during an onstart and duriing a loading screen and do if loopindex = 900 start the game so that it loads it all without player input screwing. Up

  • As you described, the solution is to use nested loops and loopindex - For "x" from 1 to 29, then For "y" from 1 to 31 as a sub event. Your action would be to create a tile object at x, y where x is loopindex("x")*gridwidth and y is loopindex("y")*gridheight. You can add a constant value to each of these to offset the start position.

    In terms of optimization though... I personally would not create a potentially unused object for all the empty spaces and only create them when needed, in the right place.

    General words of wisdom - Never fear running into a dead end. In the process of doing so, you will learn exactly why and how a dead end can occur, and how to work around it. Also, there is no such thing as starting from scratch, as long as you have the experience of going through whatever you did previously. A program that takes you a month to write the first time, even if you were to lose everything, you could probably recreate in just a few days the second time you do so.

  • OK, I did it, but I can't click one to change it.

    Is it not

    on touched (sprite) - system create object (a different sprite) at (first sprite.X, first sprite.Y)

    • first sprite - destroy

    ?

    I know it works, but it doesn't work with sprites created with the loop.

    my game file is here: www -dot- cazualnoob -dot- com/web-games/

  • You forgot to add on start of layout on you non-disabled grid generation event. Your grid is being created every tick, which immediately covers up your single "dirt" tile you place.

  • Well, that worked like a charm and I did it.

    I've been searching all day and trying to find a way to select or pick a specific sprite without interacting with it with a touch or anything. Like, I want to indirectly affect a tile. I want a character to chop down a tree that is close to him. Do I have to click on the tree and say cut down, then he'll walk over and cut it down, or can I just put him somewhere and say cut down the nearest trees in reach?

    Is the loop not an array or can I mark each sprite block with an instance variable id? Construct 2 is so different than what I'm used to - scripting.

    It's so frustrating when I can't figure out something that I think would be so easy.

    I uploaded the newest game file to my server.

  • You can mark each sprite block with an instance variable. When an object is created, it is "picked" automatically for the duration of that (sub)event. So if you create an object, and set an instance variable, it will only set it for the instance that was just created.

    You can use conditions such as Pick sprite by instance variable to pick "trees", then use pick nearest sprite to get the nearest tree.

  • I'm surprised and thankful you're still answering my silly questions. I'm slowly chipping away at this mountain and thank you for your patients.

    I've changed the creation of the sprite grid to include random(), but the 10 ways I tried don't seem to work even though it accepts it and it's completely logical. But that's not even my real problem.

    Don't bother looking at the gate commands, I haven't gotten around to that yet.

    I got the id's to work like a charm - I think...

    I had them kind of working better earlier, but they weren't getting there, so I tried a different approach. I think I'm closer, but I don't think my new way is going anywhere either.

    I can honestly say I have no idea what is happening with the random generator or the grid sprite swapping.

    my game file is here: www -dot- cazualnoob -dot- com/web-games/

  • First your random problem:

    Else is a little bit tricky. The event sheet is read and each event executed in order from top to bottom, as long as the conditions match. Else means only run this if the event previously did NOT run (unless you have a series of elses, but that works as an extended if-else chain). So the way it is now, lets say your random picked 3, which would be dirt. The dirt event runs. The grass event does not run. The tree event DOES run because the grass event didn't, so it immediately covers your dirt with a tree.

    To solve -

    Explicitly define 4<=rng10<=6 in event 7

    Or Add Else to event 6 as well, to make it a proper if-else chain.

    Your terrain manipulation problem is similar. When you touch grass, event 12 runs and creates a tree. Then event 13 runs because a tree is now there where you touched, and then turns the tree to dirt. This is another bit of learning curve for the event sheet system because Triggers (the green arrow) don't follow the normal flow of top to bottom, and will run whenever the trigger happens. Thus you can't use Else with a trigger.

    This is a little troubling because when you turn one object into another, triggers will run on the new object and I can't think of a solution off the top of my head. The solution would be to use another system/approach, which I hate to bring up because you would have to mostly start over, but here goes. This is how I would normally approach a project of this type. Instead of using a unique object per tile type...

    1. (Better) Put all your tiles into one object called "Tile", and control look and properties by animation frame and instance variables. For example On Clicked Tile, with subevents If animation frame=1, do something, else if animation frame=2, do something ect. On generation, usually you want to save the tile x/y position as instance variables, and any other properties/identification you like. The type of tile is determined by the animation frame number.

    2. (Best) Learn/use the tilemap object and build a tilemap system. They are made for tile based games. https://www.scirra.com/manual/172/tilemap

  • I thought of a way for you to continue with multiple objects - you'll use on touch start or on tap gesture as your trigger, so there is only one event that triggers on touch, like so -

  • Yea, I was thinking there would be a better technique than what I was doing.

    And that else, although makes sense when you put it that way, it's not how other languages I know use it.

    I'll chalk that one up to learning and watch tutorials on tile mapping. Although the game isn't fully formed in my head just yet, I think the direction I'm going will turn into something fruitful.

    I'm sure I'll ask for more assistance in the future. Thanks.

    P.S. the total number of sprites in the grid was 1952, not 900... kinda funny.

  • I thought of a way for you to continue with multiple objects - you'll use on touch start or on tap gesture as your trigger, so there is only one event that triggers on touch, like so -

    I'm going to assume the best way is to still do the tile mapping. I'd rather do it the best way possible than to work around with what I have.

  • Else in C2 is definitely one of the special cases and different than other programming. Not sure if you found this page - https://www.scirra.com/tutorials/292/gu ... t-features

    Additional tips and tricks - Looking in the debug to see if things are expected is always a good idea - in your case you're creating way more sprites than expected, probably because a lot of them were overlapping.

    A related trick is to set sprites to 50% opacity when working. I do this for almost all my projects, as it makes it very easy to spot mistakes as opposed to digging through the debug.

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