Pick sprites directly surrounding the selected sprite

0 favourites
  • 5 posts
From the Asset Store
A set of retro 16-Bit Neon UI elements to make your menus pop!
  • Hello,

    I would like to make a puzzle game. Therefore I've set up a grid of 81 sprite instances (aligned as 9x9 instances on the layout).

    All instances have the same starting animation frame.

    When I select one instance in the grid by clicking on it, let's say Sprite instance 10, which is the second sprite on the second row (because it's 0-based), it should 'trigger' all instances directly surrounding the selected instance. In this example, instances 1, 9, 11 and 19 (the ones above, on the left, on the right and below) should advance 1 animation frame. All other instances should remain intact.

    Preferrably I would like to use a simple function that performs this check for each instance in the grid, by 'picking' the instances that are positioned above, below, left and right of the selected instance.

    I'm wrecking my brains on this, but I can't figure out how to do this best, and how to implement the correct conditions and actions to archieve this behaviour.

    What are the conditions and actions to pick the surrounding instances, in order to change their animation frame?

    Thanks in advance!

  • I guess the simplest way would be using the is overlapping at offset condition..

  • dirkdrie

    overlapping at offset is a good way, although you would have to check above, below, left and right individually.

    You could do it all in one go with a larger invisible "detector" sprite, center it over the selected instance, and then pick all the instances that it overlaps - just make sure it is the right shape to select only the ones you want...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could also utilize the "pick by comparison" with the distance expression. So if the tiles are 32x32 pick the tiles that are less than 33 pixels away. 1 extra pixel to account for float.

    Global number iid=0

    On Sprite clicked

    set iid to Sprite.iid

    On Sprite clicked

    Pick all Sprite

    Pick Sprite by comparison: distance(Sprite.x,Sprite.y,sprite(iid).x,sprite(iid).y) <=33

    [Negate] pick Sprite by uid sprite(iid).uid

    Sprite: set animation frame to 2

  • Well I thought I would try and be clever and use just code but, of course, once R0J0 posts I always feel like I belong back in the corner with my "D" hat on. I would never have thought of such a smart but simple answer but once you see it it becomes so obvious. Anyway here is my attempt...

    https://goo.gl/pLgYAN (R215)

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