Prevent diagonal swiping

vikingviking Member, PRO Posts: 322

Hello Forums!

I have 25 actors in a scene and I can tap on one actor to make it disappear or swipe up to five actors and release touch to remove them and it is working fine. However, I want to prevent the player from doing diagonal swipes. I have attached an image that shows better what I am looking for. Anyone have an idea of the best way to do this?!

Best Answers

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2016

    If you're using a grid set up, have each grid square actor "pass" its location (e.g. self.row and self.column set manually according to its position) to game attributes or table cells when touch is inside and then when touch is released, check to see if the pattern follows the restrictions you want.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • vikingviking Member, PRO Posts: 322

    Thanks for the suggestion Tatiang :) But I am not sure how I can use this approach to measure a diagonal swipe attempt. How would you differentiate an illegal swipe from a legal one?

  • ArmellineArmelline Member, PRO Posts: 5,368
    edited January 2016
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2016

    @viking said:
    Thanks for the suggestion Tatiang :) But I am not sure how I can use this approach to measure a diagonal swipe attempt. How would you differentiate an illegal swipe from a legal one?

    Not to be difficult but how would you differentiate? In other words, if you had to describe a legal swipe from an illegal one, how would you explain that to someone (regardless of how you might code it)? That one image is probably not all-inclusive of your needs for setting this all up.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • vikingviking Member, PRO Posts: 322

    No problem @Tatiang. I know you are trying to help and I appreciate it very much. Let me try to explain: An illegal swipe is at a diagonal angle while a legal swipe is a straight swipe or a series of 90 degree turns. I actually have no idea how I would measure the difference between a diagonal swipe and one that is straight or straight angles.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2016

    If it were me, I would keep track of each actor that the "touch" is inside and check for grid square values that are diagonal from each other. I can make you a demo later but I'm on my phone at the moment.

    Here's how it might work. Assume each grid square is assigned a location value (I'll use a 3x3 grid to simplify things):

    123
    456
    789

    If the initial touch is in square 4 and the next "touch is inside" is in square 5, then I would calculate the difference as 5 - 4 = 1. Moves of difference 1 are fine. But if the next "touch is inside" is in square 9, then the difference is 9 - 5 = 4. Moves of difference 4 are not allowed.

    If we look at all other possible moves, we see that the difference could be 1, 2, 3, or 4. 1 is fine, 2 is not, 3 is fine, and 4 is not.

    I have no idea if the same strategy will work for a larger grid! This is just off the top of my head...

    Edit: I just checked a 5x5 grid and there are still only 4 possible values so it looks like it could work.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Member, PRO Posts: 5,368
    edited January 2016

    Try this. Not sure how well it'll adapt to your game without seeing your game, though.

    Edit: You'd also need to add a max distance between swipex/y and current x/y. Will do so when I have a moment.

  • ArmellineArmelline Member, PRO Posts: 5,368

    Here you go. This one is much more robust.

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2016

    @viking said:
    No problem @Tatiang. I know you are trying to help and I appreciate it very much. Let me try to explain: An illegal swipe is at a diagonal angle while a legal swipe is a straight swipe or a series of 90 degree turns. I actually have no idea how I would measure the difference between a diagonal swipe and one that is straight or straight angles.

    Depending on how you are measuring the swipe you would simply record the angle between the start and the end of the swipe measurement, if it is within the range you define as 'legal' then [do something] otherwise it's illegal.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    That's probably simpler, @Socks.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • vikingviking Member, PRO Posts: 322

    Wow! Thanks guys. You are amazing! @Armeline's solution is super-robust and very elegant. I just threw in a bunch more actors making it a 5x5 grid and it still works perfectly. It could be that limiting the swipe based on angle could be simpler, but it is also potentially more prone to mistakes. For example, if you swipe at the bottom of one actor towards the top of a diagonal actor you would have a very slight angle that still results in a diagonal swipe. Thanks again fellas! This Forum is GS's number one asset.

  • ArmellineArmelline Member, PRO Posts: 5,368

    @RThurman said:
    Glad you got an answer that is working for you.

    Here is one other idea that might come in handy as well. Its based upon the fact that diagonal actors are slightly farther away from a selected actor. Adjacent actors will be slightly closer to a selected actor.

    This was essentially the method I used, but you went and made it 5x simpler!

  • vikingviking Member, PRO Posts: 322

    Thanks @RThurman Simplicity is the ultimate form of sophistication :)

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @Armelline said:
    This was essentially the method I used, but you went and made it 5x simpler!

    I think it might seem simpler at first because I assumed square actors. The more out-of-square the actors are, the more checks you will probably need to make, until it starts to resemble your solution.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @viking said:
    Thanks @RThurman Simplicity is the ultimate form of sophistication :)

    If square actors (and a perfectly square grid) are assumed, then its probably a simple solution.

    One thing to simplify it more might be to use 'proportional spacing' so to speak. I think it used the comparison 'self.width + 7' or something like that. Its probably more robust if you just use a proportion like this:

    If (magnitude(xxxxx,yyyyy)) < (self.width*1.3)

  • vikingviking Member, PRO Posts: 322

    This little feature turned into a lot of fun in my game so I have decided to keep it :) However, I am a bit stuck because I can't figure out how to retract the steps to cancel the swipe. I am pretty sure players will be super-annoyed if they can't cancel a swipe during gameplay. Anyone have an idea on how to do this?

    To add some detail in terms of what I am trying to do:

    Step 1: Select actor 1 and then swipe to the right across the next two adjecent actors to select actors 1, 2 and 3. (This is already working).

    Step 2: Without releasing the mouse button, swipe backwards from right to left across actor 3, actor 2 and back to the original actor 1. This should then change the color back to the original color for all three actors.

    Step 3: If I have multiple actors selected like in step 1 and then release the mouse button I will change an attribute called SwipeActive to true. If I retract the swipe back to the original actor, then release the mouse button, the SwipeActive attribute should be changed to false.

    Hope that is clear...

    Any ideas are more than welcome :)

Sign In or Register to comment.