Help me think through a logical way to implement the desired effect.

Goal: (I'm using Adobe Animate CC 2017 targeting AIR for Desktop)

  • Move a sprite using a controller (mouse on a PC for instance) with a 1:2 ratio.
  • Have an event trigger a function that causes this relationship to become a -1:2 ratio (and another one to switch it back to 1:2)

My First Thought Experiment (represented in pseudo code)

  • sprite.x = mouse.x * 2 - stageWidth / 2 - sprite.width / 2 (works fine, 1:2 ratio)
  • function reverseRatio():void{ sprite.x = stageWidth - (mouse.x * 2 - stageWidth / 2 - sprite.width / 2) - sprite.width (also works fine, but with a catch*)

    • The "catch" is that the sprite, when triggered to reverse ratios, jumps to the reverse side of the display window. What I'd like to accomplish is somehow have the motion of the sprite tied to the motion of the mouse, but what I have accomplished is the position of the sprite is dependent on the position of the mouse. And since when this event is triggered, the mouse does not move, the sprite suddenly does (which I'm guessing would get bad reviews during play testing, although the very saddistic gamer may actual enjoy trying to master this effect!)

So it seems I need to do just that, link the motion of the mouse and sprite, instead of the position. This also seems to have a "catch" though.

Here's another thought experiment using this motion dependency method.

  1. You move the controller toward the right of the display window with a motion dependency to the Sprite of 1:2 (mouse:sprite). *By motion I mean use the delta or change in x position by recording the position in one frame and using the difference in the next frame to determine how much the Sprite translates.*
  2. The Sprite goes to the far right of the window as well (actually getting there before the mouse does because of the imbalanced ratio).
  3. The event is triggered that negates the relationship to -1:2 (mouse:sprite).
  4. The sprite does not jump to the far left side of the window because its motion is dependent on the motion of the controller, which isn't being moved.
  5. Now the controller moves further to the right
  6. This should have the effect of moving the sprite to the left, which it does, but by the time the sprite moves back to the left half way across the screen, the controller has left the window and thus can no longer influence the sprite (my application pauses when the mouse leaves, because my target framework doesn't support mouse input from outside the display window).

So because these two methods have these "catches" I have to choose between the sprite jumping across the screen or only being able to move the sprite halfway back when this event is triggered. I think this means I need to really rethink my whole methodology. Any thoughts on a slick way to achieve this effect? It seems impossible to me without having my PC physically move the location of the mouse cursor (which, if I could do that, would totally work!).

Thoughts? Questions?

enter image description here

in the bottom picture, the event has been triggered, but the sprite can't respond to the movement of the cursor, becasue it is already to the far right. I could manually move the cursor to the far left, at which point things would work fine, but the goal is for this to be instantaneous reversal of the relationship.


If I were to port this to iOS, I think I could use the accelerometer to control the Sprite which effect could be instantaneously reversed without a cursor running out of real-estate. Right? What about using a finger drag to control the Sprite? Would I run into the same problems as the mouse on a desktop? Just musing here.


I have an idea (just to give you an idea of the kind of ideas i am open to for suggestions). My idea is give a visual cue as to where the Sprite would "jump" to when the correlation gets reversed. I am imagining a ghost image, or an outline, or a Sprite with raster lines through it to indicate that it is an inactive version. Then when the correlation switches, the feint one becomes solid and vice versa.


1 Answer 1


It might be easier to take a delta, so record the position of the mouse in the last frame/update, then multiply the distances (change between last position and current position) by the desired amount (2 and -2 if mouse is clicked in your case).

  • 1
    \$\begingroup\$ This is precisely what I refer to as the motion method. The Sprites motion is dependent on the cursor motion. Sorry if I didn't explain that well. But the catch with this method is that the mouse would end up off the window/out of the app before the Sprite reaches the edge of its limit. Even if Adobe air didn't have that limitation, the cursor would eventually possibly reach the limit of the PCs screen or OS likely at some moment when the Sprite was in the middle of the window, not its limit. \$\endgroup\$
    – Neal Davis
    Dec 9, 2016 at 15:49
  • \$\begingroup\$ I updated my second thought experiment to try to make this more clear. Thanks \$\endgroup\$
    – Neal Davis
    Dec 9, 2016 at 15:57
  • \$\begingroup\$ Ah i see, sorry for the mix up. I don't see any way to do this if adobe air doesn't have the ability to capture the mouse. Upon digging through the forums it seems that you may be able to accomplish this by having another program capture the mouse, and then feed data back to the air application as discussed here with keyboard events forums.adobe.com/thread/560515 \$\endgroup\$
    – benh
    Dec 9, 2016 at 16:01
  • \$\begingroup\$ Interesting idea I will take a look. I couldn't force my user to use the keyboard. Hey while I've got you here, I just had a thought. If my final target were, let's say, iOS with an accelerometer, this could be easily done right? Tilting to the right suddenly switches to the effect of a left tilt and vise versa? Or even a left swipe suddenly has the effect of a right swipe? \$\endgroup\$
    – Neal Davis
    Dec 9, 2016 at 16:04
  • 1
    \$\begingroup\$ You mean that the user tilts the phone and then maybe touches the screen to reverse the direction of the tilt? that should be pretty easy if you just change the orientation used for your calculations by 180. \$\endgroup\$
    – benh
    Dec 9, 2016 at 16:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .