[solved] Test sprite position from another instance ?

0 favourites
  • 6 posts
From the Asset Store
Soldier Test
$9.99 USD
A Construct version 2 & 3 "Stand-alone" RPG game with "In-Game Module" (IGM) integration.
  • Hi.

    I have a lot of blocks and their position follow a 32*32 grid.

    For each block I would like to know if there are other blocks around it : top, top right, right, bottom right, bottom, bottom left and so on.

    So I can modify the current block and set the right graphic on it.

    For example, if a block has no other block to its top, top right and right, it has a slope (it will be a sprite special frame, nothing more) from top left to bottom right.

    The same way, if it doesn't have any blocks to its right, bottom right and under it, it will has a slope frop top right to bottom left :

    [attachment=0:1t1wnbjq][/attachment:1t1wnbjq]

    I don't know how to test each block position regarding other ones. Any (efficient) idea ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I usually achieve this using functions.

    I guess your top, top-right etc., blocks can be picked by some index variable relative to the current block...Otherwise you need to have some index variable depending on the instance id or while creating the blocks in the grid set a index variable for each block following a matrix notation(row number/col number).

    Once a index variable is established for each block,

    Then in a for loop, you need to check "for each" block --> pass the index variable of that block as a function param and call a function.

    In the function (on the event side) pick the block for the top, top-right blocks depending on the passed index variable vs self-index variable --> (on the action side) do whatever you want with the picked blocks.

    Hope this helps!

  • I'm note 100% to understand all your explanations as I'm not fluent in english.

    I did this following your suggestion :

    [attachment=0:2mkhqyie][/attachment:2mkhqyie]

    It tests only if there are other squares on the left, top left and top position.

    And it takes way too much time : a few seconds for only 100 squares, and I have about 2000 squares in my layout.

    How to improve it ?

    Maybe could I put all my blocks in an array before instead of testing the actual squares ?

  • Do you want to loopindex the logic on number of blocks or number of squares?

    I also believe when you say 2000 squares you have them on a Tiledbackground...Otherwise performance will sure be impacted with or without the logic! Try to have as many less static objects as possible...

    You can do the above logic only if the number of blocks you have are limited in number ( say less than 60 to 70 or so)...

    Also you should call the function on a triggered event rather than every tick...otherwise performance will again take a hit.

  • Hi,

    Let me explain what I exactly want to achieve

    I have a map :

    [attachment=0:moiwyv22][/attachment:moiwyv22]

    Each square is a sprite. Well in the editor it's from a tilemap object because it's easier to draw large area with this.

    When the layout is created, all the tiles are replaced by a block sprite. But that doesn't matter for my issue I guess.

    So i have a level with a lot of squares and I would like to automatically have slopes on edges, like this :

    [attachment=1:moiwyv22][/attachment:moiwyv22]

    And the blocks need to be sprites because I need to do some actions on them (change opacity and stuff) for other events.

    I don't really care if it takes a few seconds to iterate over all my blocks to set up the slopes on edges because it will be done only once when the layout is created.

    However, it will be done in smaller areas some time when a game occurs, because the blocks are destructibles. New edges will be created by the players so I'll need to change some blocks to slopes, but this is another issue at this time.

    I'm currently trying using an array to do the work but I'm not done finishing yet so I don't know if it will be faster than the previous method.

    I don't know if I explain well my issue

    Edit : How dumb I am. I just have to do this while I'm on my big loop at the start of layout, I can check the tiles positions for each loop index.

  • Well it is done and it was incredibly easy. Why do I focus on complicated things… :l

    The events I used in my loop :

    [attachment=1:3cgw10rt][/attachment:3cgw10rt]

    And the before/after (click on the picture) :

    [attachment=0:3cgw10rt][/attachment:3cgw10rt]

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