Is it Possible To Check For Objects Position?

0 favourites
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi Everyone,

    I want to clarify the title,I want to know is it possible to check if Objects are right next to eachother without Arrays?

    In my case im looking to make my plain dirt tile turn into a grass covered dirt tile after a breif wait period,But only if it is already next to a grass covered dirt tile.

    Thats why i needed to know how to check if tiles are side by side.I also have plans to use this same style of events in different parts of this project.

    Thanks everyone i hope i was detailed enough.

  • For something like mapping in your case, you will want to use array.

    Sure, there are other ways, but if everything is in a grid, then you could check for adjacent tile right away.

    But if you prefer, one possibility is, you could adjust the collision mask of any frame of any sprite in the sprite editor. Perhaps, you could try expand the collision mask of your plain dirt tile a bit more, and then check whether it is overlapping other objects in question or not. But again, you will also want to check for performance in this. Having many of these at once might not be a good idea.

  • Overlap at offset would work in your case. It checks if objects overlap at defined offset.

  • the thing about arrays is that its just to complicated for me to grasp at this time.I have gotten no sleep because of arrays.I was hoping to find alternate ways of checking if a tile is next to another tile.I will try your way and i have heard of a different from a friend on the forums.Thanks you keroberos

    vee41 So would i just make my collison mask bigger? and if i did make it bigger it would make my solid collision with my player funky aswell wouldnt it?

  • You can go old-school and check the bounding-box values.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So would i just make my collison mask bigger? and if i did make it bigger it would make my solid collision with my player funky aswell wouldnt it?

    Yes, it will affect the player object as well.

    You could try another trick like this:

    On the start of layout, for all of your objects that are plain dirt tile, create an invisible object that has collision mask bigger than your tiles. Now, with this, you refer and check to this invisible object for overlapping and check whether those tiles that overlapped are plain dirt tile or not. If so, ...you know what to do. ;)

  • blackhornet i would love to know more about checking for the bounding box values.I never heard of doing such a thing.

    i like this idea of creating an invisible sprite,I could be more precise with where i want to check for the overlapping collision.But also it has a fall back,Wouldnt i really be generating twice as many sprites than really needed? If i cant find another route i will have to use the double sprite techniqe.Thanks for replying so fast.

  • You only create the invisible object on the tile that has respective frame that you want to check. You do this in one go. The number of objects won't be doubled, but yes, it will still increase.

    Actually, ...how many tiles objects do you have anyway? And which device are you actually trying to put this game on?

  • You only create the invisible object on the tile that has respective frame that you want to check. You do this in one go. The number of objects won't be doubled, but yes, it will still increase.

    Actually, ...how many tiles objects do you have anyway? And which device are you actually trying to put this game on?

    im generating one hundred tiles and im making this game for tablets and high end phones

    I plan on reusing the function for different layouts.I just need a for sure way to check if tiles are right next to each other which seems it is possible to do without arrays.

  • Here just a quicky showing the bounding box expressions.

    bbox-print.capx

    The Top and Bottom values are the same, and the Right value = Left value of the adjacent tile. (You may want a buffer of a pixel or two when calculating).

    The algorithm is simply, pick the tile to compare, and cycle through every other tile to see if it's Top and Right equal the Top and Left of the other tile. If so, they are adjacent (on the right). You can do the opposite to check the left-side.

  • blackhornet as easy as that looks im not understanding whats going on.

    I dont want to sound lame but i am unaware of the expression your using.

    this is what i found in the manual.

    Size & Position

    BBoxLeft

    BBoxRight

    BBoxTop

    BBoxBottom

    Return the layout co-ordinates of the object's axis-aligned bounding box. This is the smallest unrotated box that completely encloses the object, taking in to account any rotation or stretching.

    I understand that its calling for the bounding box,But how does this work?

    I dont understand whats going on in your capX

  • bbox-sample.capx

    This prints each tile's BBox coordinates. As you can see, adjacent tiles share the same value for the Right of the one tile, and the Left of the adjacent tile.

    By scanning all of the tiles, you can detect which share a 'wall', let's call it, and are therefore adjacent.

    If this is still too much, you may want to give arrays another try. <img src="smileys/smiley29.gif" border="0" align="middle"> There are several tutorials on arrays on the site.

  • blackhornet

    i think you are right about the BBox Example,It might be alittle out of my leauge for now.

    as for Arrays,Im trying to learn them but i fail when it comes to actually making the tile i want appear on the layout.

    I need to figure out the easiest way possible to lay blocks through arrays.I dont need random i just want a flatland.

    Once i learn how to make a flatland generate i could move to the more complicated random.

  • array-sample

    I know there's a lot here, but try to draw it out on some graph paper, if you have some. X along the top, Y down the side, and walk through the algorithm.

  • So from what i have learned so far there are only three ways to check if an object is beside another object.

    The three ways i have been told are not what im looking for,The closest is arrays but i dont really get them thats why i dont want to implement them in this game.

    I would love to know if there are more ways to check if an object is next to another object.

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