Pick sprites directly surrounding the selected sprite

Get help using Construct 2

Post » Fri Oct 23, 2015 8:59 pm


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!
Posts: 4
Reputation: 183

Post » Fri Oct 23, 2015 9:03 pm

I guess the simplest way would be using the is overlapping at offset condition..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
Posts: 6,160
Reputation: 19,775

Post » Sat Oct 24, 2015 5:58 am


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...
Posts: 438
Reputation: 17,790

Post » Sat Oct 24, 2015 7:28 am

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
Posts: 5,294
Reputation: 70,999

Post » Sat Oct 24, 2015 7:59 am

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)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
Posts: 1,194
Reputation: 30,882

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, ratboy3, yolkgames and 33 guests