Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Hover left and right

New Here ,
Apr 03, 2018 Apr 03, 2018

I want it so everytime I hover over a specific object I can move it just left or right. I have attached a photo of the scene. Basically, I want it so when you hover your mouse over the knife you can move it left or right (not up or down).

Snip20180403_3.png

TOPICS
ActionScript
202
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 03, 2018 Apr 03, 2018

If you move your mouse quickly, and get outside of the width of the knife, would it stop following the mouse?

You could make it just follow the mouse all the time, and not insist that the user has to initially point at the knife. You could have code like this ('knife' is the instance name you gave the knife movieclip in the Properties panel):

addEventListener(Event.ENTER_FRAME,moveknife);

function moveknife(e:MouseEvent){

knife.x = stage.mouseX;
}

If you want to make sure the mouse is within the knife, you could do this:

addEventListener(Event.ENTER_FRAME, moveknife);

function moveknife(e: Event) {

  if (knife.hitTestPoint(stage.mouseX, stage.mouseY, true)) {

      knife.x = stage.mouseX;

  }

}

You'll see though that it's easy to move away from the knife and lose control of it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2018 Apr 03, 2018
LATEST

The second one is perfect! Thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines