How do I detect if a sprite is beside another sprite?

0 favourites
  • 5 posts
From the Asset Store
A set of 10 pixel art animated magic effects with icons. 2 Fire, 2 Earth, 2 Wind, 2 Water, Portal, Explosion.
  • I am trying to make a perimeter game for my math class.

    My idea is to create a sprite and use a repeat loop to spawn it across an image which is a grid.

    The sprite has two frames one white and one a different colour.

    When you click the sprite it changes to the colour frame.

    I can spawn the sprites but the problem comes when I try to count all the perimeter squares only.

    I just want know how not to count the square if it is surrounded by another square on all 4 sides.

    I just want to count the squares on the outside of the shape.

    Thank you for your help

  • waiit are you trying to box in an area.

    so you have 1 sprite, and it randomly generates an area around its self

    tile maps might be the way forwards

    check out flood filling examples.

    after flood filling, you could just +1 to a perimeter variable for each tile thats filled.

  • I am trying to make a game like this one

    primarygames.com/math/areabuilder

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • a ahhh

    ok.

    im going to level with you. i got walled in my dungeon keeper game, as i wanted to connect adjacent tiles as 1 room.

    however, i was doing this with multiple rooms and the blocks didnt automaticly move to position.

    so, again. tilemap.

    just have an invisible tilemap on screen. when you release the object, have it snap to position ( or as i did it, just have the shape move with the mouse, but snap to squares (ie, it can only ever cover tilemap squares, cant overlap)

    then on release. set the tiles that are covered by the object to become tile 1.

    you can do this by comparing the blocks position/tile width so 128,128 will become tile 4,4 (if the tile size is 32)

    then. you can use a for each tile condition, and +1 to a global variable for each tile set to 1

    this works perfectly for a 1 square block. if its a 3x bloclk, youll have to figure out the calculation to assign 3x tiles

    1 more thing to note. set the hit box of the tiles used in the tile map to be slightly smaller than the box, or they can count incorrectly sometimes.

    i hope this helps!

    if you need me to be specific on anything, let me know. but, i am working on a big project with some people atm.

  • Thanks so much.

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