Block Pushing too slow (grid-based game)

0 favourites
  • 3 posts
From the Asset Store
Hand-animated Sprite Base for isometric game/animation development
  • Good afternoon,

    I designed a block pushing game but I can't figure out how to make the game work without lag.

    You are able to move up, down, left and right on the field using the arrow keys. When you push into a block, it moves it over by 16px. When you push a block into another one, they both move. This is done by finding the furthest empty space and leap-frogging the block to it.

    Unfortunately once you stack more than 5 together an evident slowdown occurs. The line of blocks will appear to get shorter before waiting at least a few ticks and then righting itself, but this isn't satisfactory.

    It seems like my method of evaluating each block looking for the next empty grid slot is too slow for a computer to handle in a single frame. I'm trying to find a faster way to do it, as this will definitely get in the way when moving enemies you must trap are dropped in. Also the blocks cannot tell fast enough when they are against a wall (even though the code works) and a large chain will plow through it with impunity.

    I've added a capx in case anyone wants to mess with it themselves.

    https://drive.google.com/open?id=1ZQFji-wKQ05A4L-0aluGT8IFli_lUwiW

  • You misunderstand the issue, the problem isn'T that it'S too resource intensive, it's that the condition can only be true once a frame, so only one block moves per frame, hence the perceived "lag"

    Change your code so that all the blocks that need to be moved are picked and moved at the same time instead of one per frame

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for your answer. The fact that it only checks each block per frame makes perfect sense which is why multiple blocks seem to lag behind a few frames.

    Right now I'm looking into how to pick multiple blocks along the axis (uninterrupted by an empty space) and move all of them at once.

    Once again I appreciate the point in the right direction.

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