Pick sprites directly surrounding the selected sprite

Get help using Construct 2

Post » Fri Oct 23, 2015 8:59 pm

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!
B
3
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..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Oct 24, 2015 5:58 am

@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...
B
99
S
35
G
20
Posts: 438
Reputation: 17,910

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
B
94
S
33
G
118
Posts: 5,392
Reputation: 75,845

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/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 2 guests