How can I make characters follow the mouse?

Hello, I am designing a new game. I wanted to add the feature to have the character be controlled mouse. I tried different ways, but none of them does not seem to work. How can I do for where the character following the mouse at a constant speed?

package

{

import flash.display.Stage;

import flash.events. *.

import flash.ui.Keyboard;

import flash.display.MovieClip;

SerializableAttribute public class extends MovieClip Hero

{

public var stageRef:Stage;

public var health: Number = 6;

public var speed: number = 2;

public var leftPressed:Boolean = false;

public var rightPressed:Boolean = false;

public var upPressed:Boolean = false;

public var downPressed:Boolean = false;

public void Hero()

{

stage.addEventListener (KeyboardEvent.KEY_DOWN, keyPressed);

stage.addEventListener (Event.ENTER_FRAME, loop, false, 0, true);

stage.addEventListener (KeyboardEvent.KEY_UP, keyReleased);

}

public void loop(e:Event):void

{

{if (leftPressed)}

x = speed;

} else {if (rightPressed)

Speed x +=;

}

{if (upPressed)}

y = speed;

} else {if (downPressed)

y += speed;

}

}

public void keyPressed(event:KeyboardEvent):void

{

Switch (Event.keycode)

{

case Keyboard.LEFT:

leftPressed = true;

break;

case Keyboard.RIGHT:

rightPressed = true;

break;

case Keyboard.UP:

upPressed = true;

break;

case Keyboard.DOWN:

downPressed = true;

break;

}

}

public void keyReleased(event:KeyboardEvent):void

{

if(Event.keycode == Keyboard.Left)

{

leftPressed = false;

}

If (event.keyCode is Keyboard.RIGHT)

{

rightPressed = false;

}

If (event.keyCode is Keyboard.UP)

{

upPressed = false;

}

If (event.keyCode is Keyboard.DOWN)

{

downPressed = false;

}

}

}

}

:

package

{

import flash.display.Stage;

import flash.events. *.

import flash.display.MovieClip;

SerializableAttribute public class extends MovieClip Hero

{

public var stageRef:Stage;

public var health: Number = 6;

public var speed: number = 2;

private var angle: Number;

public void Hero()

{

stage.addEventListener (Event.ENTER_FRAME, loop, false, 0, true);

}

public void loop(e:Event):void

{

angle = Math.atan2 (x-MouseX, MouseY-y);

x = speed * Math.cos (angle);

y = speed * Math.sin (angle);

If (Math.ABS (x-MouseX) + Math.ABS (y-MouseY)<>

x = mouseX;

y = mouseY;

}

}

}

}

Tags: Adobe Animate

Similar Questions

  • How can I make Pages capitalize the first word in a sentence?

    How can I make Pages capitalize the first word in a sentence? The I phone t - it, the iPad does, why not not iMac using Pages capitalize the first word on a new sentence?

    Pages of IOS and IOS itself remain different implementations of Pages v5.6.1 for Mac and OS X. In any version of Pages v5, if there was an option to preferences in Pages ' 09, there is no auto-capitalisation function.

    See my previous post is launching an OS X App Store free application, which can be applied to auto-capitalisation to your Pages v5 documents.

  • Why I can't update my credit card payment information? It shows the error in the server. How can I make contact with the staff of Adobe?

    Why I can't update my credit card payment information? It shows the error in the server. How can I make contact with the staff of Adobe?Screen Shot 2016-08-29 at 9.18.44 PM.png

    Hi Purple % 20Lambs,

    Please contact Adobe support:Contact customer service

    * Be sure to stay connected with your Adobe ID before accessing the link above *.

    In case you can't reach Adobe support, please see:

    Contact the technical support FAQ: Impossible to reach support via the link "contact us".

  • How can I swap buttons of the mouse on a--no Microsoft Mouse with Microsoft Mouse and keyboard Center? (I have a Microsoft keyboard).

    I did a new install of Windows 8 on my Dell desktop computer that has a keyboard, Microsoft Natural 4000 and Dell's USB mouse.  Windows 8 Microsoft keyboard recognized and automatically downloaded and installed Microsoft Mouse and keyboard Center version 2.0.162.0.  However, I'm a lefty mouser and installation of the MS mouse & keyboard Center back on my right handed mouse buttons.  (I went to control panel |) Mouse and swapped buttons immediately after installation.)  When I went into the control panel. Applet of the mouse and the keyboard and mouse Center had resumed the first tab of the control panel mouse properties, stating "click here to change the settings for the Microsoft mouse.  This is the tab where the "Swap mouse buttons" is usually.  When the mouse and keyboard Center is launched, it offers only options for the keyboard.  Do I have to abandon my Microsoft keyboard or purchase functions go a Microsoft mouse to get exchanged my mouse buttons?

    How to swap the mouse buttons on my non-Microsoft with Microsoft Mouse and keyboard Manager installed mouse?

    Thank you

    C.C.

    To get all the benefits of Mrs Maes & Bishop, you can buy a MS mouse is compatilble with the Manager, MS software is for devices of Ms and it is unlikely that MS will change their software to accommodate mice made by other sources.

    If you want to keep the Dell mouse, you will need to disable MS M & K Bishop.

  • How can I make sure that the playback window corresponds to the resolution of the original item?

    Installing just the Premiere Pro on my laptop, I found that reading the timeline main window does not play the video in its correct resolution. This isn't a problem if I want to drag and drop the video clip in the preview window, he plays the clip as it was recorded. How can it be fixed, please?

    Extra: The clip in the timeline playback window seems to zoom in. Even when I select 'Fit', the clip is still extended...

    Your sequence setting is probably not the images.

    What first do you use?

    To get correctly the settings follow these steps:

    The latest version tells you to drag a clip in the timeline to get the appropriate settings.

  • How can I make maximized window the default size

    I have a notebook file which amounts to about half the size of the full window, enlarged. I tried "stretching" to the maximum and then close the file. However, it does not. How can I do optimize by default when I open it?

    Hello

    You can try to manually stretch it corners to save size. The forum of Windows would be useful.

  • Drive on which Windows XP to reside is always labeled as a system drive. How can I make one of the other disks that has Vista or 7 that the new system?

    Change the system drive

    I'll try to explain my situation better than I can.

    My situation is that when I used to have XP installed, I had installed the only drive I had back then which is now the drive D, for a long time, so I have Windows Vista Home Premium 32-bit, Windows 7 Home Premium 32 bit installed on two different discs, Vista is installed on drive C and 7 is installed on drive E , but I don't have XP that I had managed to get rid of it.

    My problem is that the drive on which Windows XP to reside has always left this disc marked as system in the disk management window, and I was wondering how to do that one of the other readers who has Vista or 7 that the new system?

    I already managed to change the startup disk from drive where Vista is installed to, it's just that I need to change the disk that is marked as system to another drive, such as D drive begins to show signs that it comes at the end of his life and I would like to move the startup folder as well as the other files needed to start on the other.

    I assume that you installed Windows XP 1, then Vista, 7 (these 2 OS not in order)?

    And Vista and 7 was by all means upgrade installation?

    Since originally, that you have installed Windows XP on drive D, it should be marked as 'system' and retains so the tag 'system '.

    The volume of the 'system' should be identified as the first primary partition active. It may or may not have the files it contains.

    The fact that the system considers "system drive" does not mean that there are files that it contains.

    Now, you want to delete the existing volume and create a new volume. Needs to be done outside the facility.
    When you start the cd or DVD to start the installation list us readers, if you remove the volume the volume drive letter is already booked, so you get the next available drive letter, do not re-use the deleted volume drive letter.

    If he removed during installation and then recreated as a new volume (formatting does not remove the volume, you need to delete the volume and recreate it)

    -[Posted by Darrell Gorter [MSFT] in another forum.]

    Try to format the XP partition and change the drive letter.

  • How can I make sure that the automatic renewal is disabled?

    Hello

    As a student; I had the composition cloud creative for some time now, because I am not able to afford it for more than 12 months, I want to be totally assured that my subscription will not get auto-renouvelé when it ends.

    I read in the following guide: disable autorenewal subscription services Adobe PDF

    However, it does not seem to be an option to disable the automatic renewal to 'manage', plan system nor does it display whether I left active.

    I can't really go through another year of my creative cloud membership because I might not EMA (upkeep allowance) to allow it at this time there and can allow me to cancel my subscription. Is there a possible way to make sure my subscription will not get automatically renewed in the end date?

    Cancel see answer #1 in https://forums.adobe.com/thread/2023066 - includes a link to Chat from Monday to Friday

    or

    Chat support: Mon - Fri 05:00-19:00 (US Pacific Time)<=== note="" days="" and="">

    Don't forget to stay signed with your Adobe ID before accessing the link below

    Creative cloud support (all creative cloud customer service problems)

    http://helpx.Adobe.com/x-productkb/global/service-CCM.html

  • How can I make Firefox (9) the default browser for Android (2.3.4) on a Motorola Bionic (5.5.893.XT875)?

    Several suggestions online (for example, through the Manage Applications-All-Browser, or the settings of Firefox) have not worked. Browser 'faults clear"is grayed out, probably because there is no set of default values, and I've yet to find how to put everything. Firefox has no button 'Settings' and 'Website Options' or 'Préférences' means making FF by default. Whenever I click on a link, FF appears as an option, however, and it works fine.

    You need get the Actions dialogue box to appear and check the use as default action at the bottom of the list. One of the common ways for this to appear is to follow a link to a program of e-mail or a social network like Facebook or Twitter application.

  • I work from home, how can I make Bittorrent via the wireless when I connect the ethernet to work

    Hi people,

    I know that the network connection with the lowest metric is chosen for the Internet, but it's killing Bittorrent as soon as I plug the ethernet cable.
    When I need to force traffice via the wireless I can use ' route add Pei *.» *. *. * mask etc. etc."but this only works for single IPs, such as streaming radio stations etc.   What I really need, is a sort of local proxy that I can specify in uTorrent, then use that IP to route via the wireless.
    Someone at - it ideas of how I could do this?  I read about SSH/socks etc. but it is a little confusing.
    See you soon... Buzz

    Hi Buzzcut50,

    I suggest that you contact the support of torrent of bits for more information.

    http://www.BitTorrent.com/help

  • How can I make WAP54G meets the WRT610N

    I just bought the WAP54G access point to use with an existing WRT610N.  I run the installation for the WAP54G CD and I get an error that a G network cannot be located.

    Please let me know how I can proceed with the implementation.  are two opposites?  What other options do I have?

    Thank you.

    Do not run the CD... Open the configuration page for WAP54G using IP 192.168.1.245 and configure WAP in AP Mode.

  • How can I make sure that the version of the client to REmote destop protocol (RDP) 6.0 or later is installed on the surface rt?

    I am trying to access my computer remotely works and that is the message I get on the durface tablet. How to do this. I've been to the ons announcement page and am stil lnos further to the front.

    Thank you.

    Hello

    Welcome to the Microsoft community. According to the description you want to use the Remote Desktop feature in Windows RT.
     
    Unfortunately, it is not possible to connect Windows RT PC from another PC via Remote Desktop. Reference: RT Windows: FAQ
     

    You can visit these links and check if it helps:
     
     

    I hope this helps. Let us know if you need help with Windows related issues. We will be happy to help you.
  • How can I make Adobe XI the default program for PDF files in Windows version 1511 10?

    I have Adobe Acrobat X! Standard (11.0.13).  I have recently upgraded to Windows 10 version 1511.  After the upgrade, it turned my default pdf for Microsoft Edge program.  I would like to change the default value to Adobe Acrobat Standard XI.  I tried to open a PDF with Adobe and Adobe followed automatically make my default program Adobe.  However, when I selected OK, I received an error message Adobe claiming that couldn't make Adobe default program.  Any suggestions?

    Hi johnv1955,

    Right-click on the PDF file, select open with-> choose default program, select Acrobat XI & confirm the changes.

    Kind regards
    Nicos

  • How can I make reference to the parent, without using _parent or _root?

    I can't use the following in my ActionScript because of conflicts with the host application:

    _level0

    _root

    _parent references

    A pop-up window I have a button closure with an absolute reference:
    closeBtn.onRelease = function () {}
    unloadMovie ("_level0. Page_1.holderBox");
    }
    Is there another way to do this job without use _level0 or _parent?
    I read that it is possible to use a global variable on the main timeline and ref, but cannot get that to work.

    You may need to try several different approaches (it's what I would do), but you may be able to target just the owner directly using the variable global and not necessary to include the reference Page_1 with her...

    section 1:

    _Global.mcVar = null;

    later...

    _level0. Page_1.imgholder.image0_0.boxS.onRelease = function() {}

    createEmptyMovieClip ("holderBox", getNextHighestDepth ());

    holderBox.attachMovie ("boxSound", "boxSound_mc", 0);

    _Global.mcVar = holderBox;

    };

    If this does not work, try to move in after every time holderBox is added in Page_1 and include Page_1 in the assignment as I showed earlier.

  • My iPhone has an ID different apple that iPad and Mac. How can I make them all the same?

    My iPhone was originally created as a business with the company email phone. The company or e-mail no longer exist, but iPhone continually ask the password to this ID from apple.  I can't update the applications because the phone think again it must use the old ID apple however, I am able to buy apps.  I want all 3 of my devices to work with the same apple ID.

    Applications that request the password for the old ID when they try to put up-to-date are related to this Apple ID because they were purchased with this Apple ID. You will need to continue to provide the password for this Apple ID old update these applications, or you will need to remove these applications and redeem them or re - download if they were free under your current Apple ID

    See you soon,.

    GB

Maybe you are looking for

  • HP G71-340: forgotten power on password and Admin password

    I really need help it's been awhile that I used the password (I forgot) and I have a HP G71-340... I am unable to connect and now I'm at a screen that says SYSTEM DISABLE [57784727] I'm not sure do next and seen one reply where someone had the same p

  • iPhone 6 seconds used to sync with MacBook

    Just bought an iPhone 6s and everything Sync except itunes. I get the following message "" Sharon iPod touch"iPhone cannot be used because it requires a newer version of iTunes. Go to www.itunes.com to download the latest version of iTunes. "  My iTu

  • Throw a UI object on top of another user interface object

    Hello friends and family,. So, I'm looking to place a label field ontop of a bitmap image. No idea how to do this? I want to do bitmap image to be in the background and the label at the forefront (top). Thanks for the help.

  • Unable to access several Web sites using Windows 7 regardless of browsers

    In recent weeks, I am unable to access several Web sites i.e., microsoft, linkedin, msn, etc., using windows 7. This doesn't work for all browsers. I get the following message while trying to launch some Web sites. ============================== This

  • How to order the products differently, in several catalogs

    Can someone help with my problem of customers with products of orders differently when they are in several catalogs? For example, product1 is listed in the catalog and list B. They would like that produces 1 to appear 3rd in the list in the catalog a