Sprites swap position with only one click.

Get help using Construct 2

Post » Sat Feb 11, 2012 11:23 pm

This is a tricky thing I think, I already thought about possible solutions but they are not elegant and more than everything I would like the opinion of the community.

Think bejeweled http://www.popcap.com/games/bejeweled2/online you click on a gem, then on another adjacent one and they swap,there may be two adjacent ones, three, four or none.

(X gem , O empty)
X X O X
X O O O
O X X O

What I would like is for the user to able to click on only one "gem" and the system will need to select the nearest one on an horizontal line (not vertical) and swap these two on the x axis.

I thought about storing the x position of the object inside an instance variable, then trying to move it on the axis checking for collision, it those happens swap the x of the two objects.

How would you do this?

Thank you very much
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Sun Feb 12, 2012 4:02 am

One way I could imagine is to use an invisible sprite which is less than the height of the gem and extending to the desired length and then checking if it overlaps with the gem you want to find. Probably you should store the "UID" of the gem that meets the conditions and if a "UID" is retrieved you could swap it with the one clicked. If there is none in the immediate left or right you should extend the sprite further to reach for the next gems. Still checking to the right first or the left may be a choice to make.Danijerry2012-02-12 04:03:05
B
28
S
9
G
6
Posts: 30
Reputation: 6,609

Post » Sun Feb 12, 2012 1:19 pm

how do you choose on which side you swap?
And do you swap between two gems or between a gem and an empty spot ?
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346


Return to How do I....?

Who is online

Users browsing this forum: Zebbi and 25 guests