Skip to main content
Participant
March 9, 2016
Answered

How to make something move in opposite direction the mouse is moving?

  • March 9, 2016
  • 1 reply
  • 1157 views

Hello dear community.

I've seen on Sarif Industries‌ some cool background animations. Especially the background animation where everyting moves in opposite direction the mouse is moving.

So I did want to try doing this kind of animation too. But I don't know how I can do this nor do I know how this kind of animation is called.

I can't code but I do understand programming languages.

*For everyone who doesn't want to go on the linked website*

As said everything is moving in opposite direction the mouse is moving but it seems like the objects only moves in a determinated area and the objects are moving slower as the mouse is moving.

Thank you in advance and have a nice day

This topic has been closed for replies.
Correct answer MickaelKicker

stage.addEventListener(onMouseMove, MouseEvent.MOUSE_MOVE);

private function onMouseMove($e:MouseEvent):void

{

     _myBG.x = -stage.mouseX;

     _myBG.y = -stage.mouseY;

}

You have everything you need in there.

Just tweak the operations to get the desired effect...

Add " * 0.5" to make it move more slowly for instance.

1 reply

MickaelKickerCorrect answer
Inspiring
March 9, 2016

stage.addEventListener(onMouseMove, MouseEvent.MOUSE_MOVE);

private function onMouseMove($e:MouseEvent):void

{

     _myBG.x = -stage.mouseX;

     _myBG.y = -stage.mouseY;

}

You have everything you need in there.

Just tweak the operations to get the desired effect...

Add " * 0.5" to make it move more slowly for instance.

BlublokAuthor
Participant
March 10, 2016

Thanks for your help

Inspiring
March 10, 2016

That's a really nice effect.

If you have time, could you please explain how you implement this.

In its simplest form how would I apply this to an object on my stage. I assume it is an action that is applied to a frame/s, but how do I do that.

Keen to learn.

Thanks

EDIT: I've just noticed this is in the Actionscript forum - is it possible to achieve this effect when using HTML5 Canvas?