How do I select different instances?

0 favourites
  • 8 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • Hi All,

    I have been searching around on here for a while and can't seem to find the answer. It's probably really simple, but I am stumped.

    I have a grid of 9 squares that all use the same object. All I want is for when one of the instances is clicked with a mouse, the instance next to it changes its animation frame.

    Ive tried using all sorts of things, but can't seem to get it.

    I'd rather not use invisible Collison objects as I'm planning on extending this to different size grids in the future.

    Heres a rough pic of what I mean.

    Any help would be greatly appreciated.

    Tagged:

  • Here is where I am at with it so far:

    dropbox.com/scl/fi/rg34m9k3qej97ium6ce18/test.c3p

  • When an instance is clicked get its coordinates (the center of the sprite). To get the instance to the left (as an example) subtract the width of the sprite from the x coordinate and pick a new instance that contains (overlaps) this new coodinate. For the one above you will subtract from the y coord etc.

    The crucial thing is you only get a single instance overlapping the new x,y. If your sprites overlap this won't work.

    yours

    winkr7

  • Thank you so much. I appreciate the help.

    One more thing though - How do I get the position info when I click on that instance?

  • If your bunch of sprites are all called Foo then set up a mouse event click on object. the object you want is foo. Once inside the mouse event you will have a single foo, so foo.x,foo.y is the middle of that sprite that was clicked. So the coordinates foo.x-foo.width,foo.y will be in the middle of the object (also a foo object) to the left of the one that was clicked. Find the foo object that overlaps this new coordinate and that is the foo object to the left of the foo object that was clicked.

    yours

    winkr7

  • Thanks again winkr7, I really do appreciate it. I also want to rename everything Foo from now on!

    However, It's still not working for some reason...

    Here's my set up...

  • Because your tiles are all the same object you have to be careful about the pool you are picking from. Create variables x,y and set x to xpicked-width,ypicked. Then below that you start all over with the tile pool since right now you only have one tile in it (the one you clicked). So you now want to start all over with just a coordinate and you want to find the tile that overlaps that coordinate from all the possible tiles out there. Pick all foo will make sure you can pick any foo. So do that and then pick the one that overlaps your point of interest.

    yours

    winkr7

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you so much!!! I got it working!

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