Making a swiping menu that wraps in X direction

inmonjonesinmonjones Member Posts: 9
edited March 2012 in Working with GS (Mac)
Hi all! I am fairly new to Gamesalad, but I have been lurking here for awhile and have checked out many of the templates and video tutorials. Great stuff.

This is one that has been tough for me to tackle. Unlike the wonderful demo that TSB has done for the Cover Flow, I am not moving the camera over stationary actors. I want the menu to wrap so it is endless and loops back around. So I am moving the actors instead. Ideally I want the actors to follow the mouse position while touch is pressed, then move in the direction of the swipe once touch is released, then glide to a stop.

I am only doing this in the X direction. No Y movement.

I have tried a few ways:

Method #1: When touch is pressed, constrain the actors x position to the mouse position + an offset calculated when touch is pressed (initial touch location - self.position).

The problem with this approach is that the offset doesn't get recalculated correctly when the actors wrap (maybe I am just not doing it right). Wrapped actors end up jumping all over trying to maintain their offsets. This happens if I use Scene wrap or if I set up my own rules to make the actors jump from one side to the other.

Method #2: Constrain a "Dragger" actor's linear velocity x to the mouse position x. This involves letting the Dragger chase the mouse with a nice equation like velocity = 20*(mouse.pos.x - self.pos.x). Then constrain the menu actors' velocityx to the Dragger velocity.

This works OK with a few actors, but once you have 10 or more, they begin to drift due to lag and lose their happy spacing with relation to their neighbors. It gets worse the more you swipe or the faster you swipe. I tried getting creative with using collisions and other tricks to get the actors to maintain their spacing, but none gave a good result.

Method #3: I record the positions and game time of when the swipe touch and release happen. Then I set game.velocity = (release x - touch x)/(release time - touch time). Distance over time = velocity. The menus actors have their individual velocities constrained to game.velocity.

This last method works best so far with a lot of actors, and actually was accomplished with a lot fewer attributes and rules. Probably it works better because I am not constantly calculating a new velocity. Rather, it is calculated only once at the time of swipe release, and so there is no lag. All the actors get their velocity setting and behave well. But I have not found a way to get the menu actors to follow the mouse position when touch is pressed; just to move them once the swipe is registered.


Has anyone else come up with a wrapping swipe menu that works well? If so I'd be interested in any tips. This seems like something that should be easy to do, yet it eludes me so far...


Comments

  • inmonjonesinmonjones Member Posts: 9
    Of course right after posting, I seem to have a workable solution, although it is so similar to other tries that I hesitate to call it solved. I used a combination of methods 2 and 3 above. Method 2 when I have touch pressed inside the swipe area; method 3 when i leave the swipe area or touch is released.

    If anyone is interested in looking at the setup, please post. I would still be interested in having someone more experienced look it over and tell me if it can be improved.
Sign In or Register to comment.