Sprites swap position with only one click.

0 favourites
  • 3 posts
From the Asset Store
Full game Construct 2 capx code source to post on Google Play
  • 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 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • how do you choose on which side you swap?

    And do you swap between two gems or between a gem and an empty spot ?

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