Specific collisions with the mouse

Hi all

I am currently building a hidden object game, but finds it difficult to get accurate results to where the mouse is clicking. I thought using hitTestPoint to check if the mouse coordinates have been actually collide with the pixels of the form would work, but it produces exactly the same results by simply searching for a MouseEvent.CLICK event. It seems to be returning true even if the pixels that is clicked on are (i.e. just background/no part transparent form). Is there a way to check if the pixels that is clicked on actually contain the image of the object?

Thanks in advance,

Dinkyfish

Edit: and Yes, I put the third function hitTestPoint property to 'true' whereas it should resemble the actual object shape rather than just the bounding box

If forms that you test collision with have their property cacheAsBitmap set to true, or if they have been imported (not created using Flash's vector drawing tools) transparent areas in the rectangular bounds of the object contains transparent pixels that are the same as the non-transparent pixels for hit-testing.

What you can do is intercept the CLICK event and check if it occurred on a transparent pixel before letting trigger your listener function. Here is an example:

My_Button.addEventListener (MouseEvent.CLICK, check_for_transparency, true, 100, true);

My_Button.addEventListener (MouseEvent.CLICK, button_click_handler, false, 0, true);

function check_for_transparency(my_event:MouseEvent):void

{
var button = my_event.target;

var my_pixel = button.bitmapData.getPixel32 (my_event.localX, my_event.localY);
var pixel_alpha:uint = (my_pixel > 24) & 0xFF;

If (pixel_alpha == 0)

{
my_event.stopImmediatePropagation ();
}

}

function button_click_handler(my_event:MouseEvent):void

{

do things

}

The check_for_transparency listener will get the first event because its setting useCapture is set to true and its priority is higher (100). If the pixel is transparent, it stops at the event to spread the second listener ever calendar. If it is not transparent, it goes on its merry way.

Note that this method requires that the target of the event is a Bitmap object. In addition, it checks for alpha == 0 but it could check against any level of transparency that you want.

If you want to use buttonMode (hand cursor) with your buttons, or some sort of reversal / events you would need a listener ENTER_FRAME constantly looking for transparency under the cursor.

On the other, simpler but less dynamic method is to create a mask for each of your buttons is the same shape as the non-transparent part of them. Depending on the amount of buttons that you have and how complex your forms are it could be a lot of work.

Tags: Adobe Animate

Similar Questions

  • What happened to the feature to get around on the artboard by pressing the space bar and dragging with the mouse?

    What happened to the feature to get around on the artboard by pressing the space bar and dragging with the mouse?

    cwalker,

    If it does not, it may be time for the list:

    Sometimes, (some) things may fail or stop working for no apparent reason. When (other) possible reasons/remedies do not work, it is perhaps a kind corruption (temporary or permanent), or even preference settings which disturbs, which can be cured with something on the following list put in place in order to provide a catch-all solution for otherwise intractable cases. It starts with a few easy suggestions and safe) 1 and 2) for cases less serious and goes two ways 3) and 4) to reset the default preferences (easily but irreversibly and more laboriously but more completely and also reversible), then follows a list 5) various other possibilities, and it ends with a complete reinstallation 6). If no other suggestion doesn't work, or if no other suggestion appears, you can start on the list and decide how to go or who can apply.

    The following is a general list of things, try when

    (A) the question is not in a specific file,

    (B) you have a printer installed, connected and turned on if it's a physical printer (you can use Adobe PDF/Acrobat Distiller as a printer by default without the need to have a printer on, of course you will need to specify when you really need print on paper), and

    (C) It is not caused by problems with opening a file from external media (see below).

    You tried/made some of them already; 1 and 2) are easier for temporary strangenesses and 3) and 4) specifically may be corrupted/inconvenient preferences); ((5) is a list in itself and 6) is the last resort.

    If possible / there is, you must record a current work first, of course.

    (1) close Illy and open again.

    (2) restart the computer (you can make up at least 5 times);

    (3) close Illy and press Ctrl + Alt + Shift / Cmd + Option + shift during startup (easy, but irreversible);

    4) move the folder (follow the link with this name) with closed Illy (more tedious but also more thorough and reversible), for CS3 - CC you can find the file here:

    https://helpx.Adobe.com/Illustrator/KB/preference-file-location-Illustrator.html

    5 look through and try the relevant among the other options (click on the link with that name, item 7) is a list of the usual suspects among other applications which can disturb and confuse Illy, point 15) applies to the maybe CS5, CS6 and CC);

    Even worse, you can:

    6 (A) uninstall (check the box to delete the preferences, if any), B) run the cleanup tool (if you have CS3/CS4/CS5/CS6/CC) and C) reinstall. It is important to use this step three way: otherwise, things may persist.

    http://www.Adobe.com/support/contact/cscleanertool.html

  • Can not enter master password from the keyboard, but can copy with the mouse.

    I use gentoo and installation using portage. Firefox-31, 7 is fine, but firefox-36, firefox firefox-37-38 are cannot enter Masterpassword key, now I use firefox - 38.0.5,.
    When you create the user on this web site, password is can not enter key, so I copy with the mouse.
    I check if a new version is announced for portage (gentoo), check, but once firefox-36 can not enter password to key, even they seem.

    Note that Firefox uses its own storage of password (logins.json and key3db) and not the keychain Linux (hippocampus) application.

  • I can't get the tabs to work, opening with the mouse, cannot be closed only in groups that market

    I was obliged to upgrade of hate, has lost most of my applications, cannot get tabs to work, cannot change the tabs with the mouse, cannot close the tabs,
    UNLESS I go to the tab and then group I have a button close the tab or change the tabs but that is a huge pain. Yes, I opened
    tabs mix more and ticked all the boxes, closed, reopened, restarted nothing works

    Well, don't ask me why, but I logged in today and everything works
    don't know why or how but tabs suddenly works, so if anyone has this problem I don't know how to tell you to fix said WVREDNECK

    I was obliged to upgrade of hate, has lost most of my applications, cannot get tabs to work, cannot change the tabs with the mouse, cannot close the tabs,
    UNLESS I go to the tab and then group I have a button close the tab or change the tabs but that is a huge pain. Yes, I opened
    tabs mix more and ticked all the boxes, closed, reopened, restarted nothing works

  • How to scroll through the tabs with the mouse wheel?

    I used to be able to scroll the selection of tabs when the tab bar is filled using my wheel mouse (like the arrows on each side navigation), but recently it changes the tab I look as if I physically clicked on this subject.

    I'd appreciate help on how to make it work as he did.

    That should still work if you hover over with the mouse, the tab bar.

    Make the scroll buttons on the tab bar work?

    You have maximized the window of Firefox?

    Start Firefox in Safe Mode to check if one of the extensions (Firefox/tools > Modules > Extensions) or if hardware acceleration is the cause of the problem (switch to the DEFAULT theme: Firefox/tools > Modules > appearance).

    • Do NOT click on the reset button on the startup window Mode without failure.
  • Scrolling with the mouse on the pages to create black and white, lines

    When scrolling with the mouse, periodically the entire screen turns into black and white lines. Page sometimes together, sometimes just from ads pictures/side. If you continue to scroll disappear but you need to scroll to where the lines have begun, it's hard to explain, I took 1 picture of the problem but will have more photos that I can, I love how Firefox works on my computer, it has always been the best browser for my needs. I recently bought a new desktop computer, but he did so also, so I deleted and tried to launch the Explorer and Google and I don't like, so I hope that we can settle this problem.

    I don't know if it solved the problem, but he didn't precisely these days. Thank you

  • When the page opens, the scroll bar appears only if I move to bottom of page with the mouse

    It started last week with Firefox 5 and continues with the upgrade to Firefox 6. Each new page that opens in Firefox does not display a scroll bar. By entering the lower right of the page with the mouse and move the mouse to the right, the scroll bar appears and is usable. This "correction" is required on each new page.

    This condition looks similar to the condition met when Firefox 5 was introduced. The fix was to open appearances in tools then choose the default setting. This patch doesn't work anymore.

    Troubleshooting extensions and themes

    Check and tell if its working.

  • Have no control with the mouse on my Satallite P300-123

    I have a problem with my mouse on the laptop. When I use the mouse, the mouse is every time left right up down.
    So I have no good control with the mouse.

    Can someone help me with this probem?

    (Sorry for my English)

    Hello

    Do you use the touch pad or external mouse?
    If you use an external mouse disable touchpad by using the FN + F9 key combination, especially when you use the keyboard.

  • Scrolling with the mouse 5.1 BootCamp

    Scrolling with the mouse stopped working all of a sudden on BootCamp 5.1.

    Do you have any active Windows automatic updates?

  • Drawing line with the mouse clicks on picture indicator

    Hello

    I need to import a JPG file in an image control, draw a line in 2 clicks, read bothe XY positions and perform some basic trigonometry. Any simple or striaghtforward way to draw the line with the mouse and read thos passay on the bitmap (positions relative pixel)?

    Thanks in advance,


  • Pavilion/product #: B3F79AV #ABA / pc starts fast scrolling/no control with the mouse

    my hp Pavilion began to have "spells where the page suddenly begins to scroll. I can't control it with the mouse. I have installed norton. It seems no matter what the content of the page is this scroll occurs. Scrolling is very rapid. Does anyone know what it is and how to fix it? Thank you.

    Glad to know that!

    If you need assistance with your Norton product, please let us know. We are happy to help you!

    Thank you!

    Vineeth

    Norton support

  • With the mouse to draw the edges of a XY Chart to calculate the perimeter and area of him

    I have signals from a stabilometer... I traced X in terms of y in a XY Chart and I want to know how I can draw with the mouse a circle linking most of the points that is the graph of X on Y and calculate the area of her more perimeter. I joined my program labview with two files X and Y

    LV 2009 Version attached.

  • Dragging points in the chart with the mouse

    Hello

    I would like to ask if any Graph control NOR for .net enables drag and shift the points on the graph with the mouse.

    Here's the simple example to describe what I'm thinking:

    If there is no such functionality, can be implemented and if it cannot, in such a way?

    a.h.

    Hello

    It seems that you may be heading in a different direction, but I thought I would offer my 2 cents.  One possibility would be to update the point in the data table based on the position of the mouse in the MouseMove callback and replot then data.  Although it may not fully satisfy all your needs, below is a simple example of how to proceed.  If all goes well, it may be of some use to you.

    partial class Form1: Form
    {
    xData private Double [] = {2, 4, 7, 8, 5, 4, 2};
    Private Double [] yData = {5, 8, 9, 6, 3, 2, 5};

    private int pointIndex;

    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Load (object sender, EventArgs e)
    {
    scatterGraph1.PlotXY (xData, yData);
    }

    Private Sub scatterGraph1_MouseDown (ByVal sender As Object, MouseEventArgs e)
    {
    xPoint double;
    Double yPoint;

    scatterPlot1.InverseMapDataPoint (scatterGraph1.Bounds, Object, out xPoint, out yPoint);
    This XYCursor is transparent in color and it is
    SnapMode has the NearestPoint value
    xyCursor1.MoveCursor (xPoint, yPoint);
    Cursor.Current = Cursors.Hand;
    }

    private void scatterGraph1_AfterMoveCursor (object sender, NationalInstruments.UI.AfterMoveXYCursorEventArgs e)
    {
    pointIndex = xyCursor1.GetCurrentIndex ();
    }

    Private Sub scatterGraph1_MouseMove (ByVal sender As Object, MouseEventArgs e)
    {
    xPoint double;
    Double yPoint;

    If (get_Cursor is Cursors.Hand)
    {
    scatterPlot1.InverseMapDataPoint (scatterGraph1.Bounds, Object, out xPoint, out yPoint);
    xData [pointIndex] = xPoint;
    yData [pointIndex] = yPoint;
    scatterGraph1.PlotXY (xData, yData);
    }
    }

    Private Sub scatterGraph1_MouseUp (ByVal sender As Object, MouseEventArgs e)
    {
    Cursor.Current = Cursors.Default;
    }
    }

    NickB

    National Instruments

  • Vertical scrolling with the mouse, Microsoft 6000

    Is that what someone has encountered a problem with the mouse to move the front/diagram of block vertically scrolling panel.  Scroll wheel on the mouse works fine for all other applications, but is very intermittent in LabVIEW 2009.  I'm on a windows 7 OS.

    I tried a series of 5000 ms and that works well.  Any ideas?

    Thank you

    Hi Marc, I reduced the problem by not including not not a software startup in msconfig setup.  Then I discovered the mouse to operate as usual, sort of method of disposal, I reduced to a pointer unwanted facility that I deselected and then ran as usual.  All is well now.

    Thank you

  • I have a Logitech M315 keyboard and bought a new mouse Logitech M325 compatible. I cannot now typing on the keyboard, but I can scroll with the mouse.

    I have a Logitech M315 keyboard and bought a new mouse Logitech M325 compatible. I cannot now typing on the keyboard, but I can scroll with the mouse.

    Hello

    The M325 Nano-receiver allows you to connect up to 6 devices however you
    need a Logitech utility (free download) to achieve this. Check with Logitech
    Their online documentation, support and drivers, utilities and ask in their forums.

    I don't know if that keyboard and mouse are compatible.

    Software Logitech Unifying M325
    http://support.Logitech.com/product/wireless-mouse-M325#download

    Logitech
    http://www.Logitech.com/en-us/home

    Logitech - Support
    http://www.Logitech.com/en-us/support

    Logitech - Forums
    http://forums.Logitech.com/

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle="" -="" mark="" twain="" said="" it="">

Maybe you are looking for

  • turns out iPad problem

    OK, so a few hours ago, I decided to change the system turns out to hunagrien. immenditly, I changed it to English. but here's where the problem comes in. the keyboard is still in Hungarian! What should I do? I have hard reset it several times but re

  • How to pass the numeric value in the format hexadecimal teststep parameter?

    Hello My teststep is a custom c# function that has a parameter of type Number (byte). How can I insert the data to hexadecimal? (Step parameters + tab Module) Can I change like field insert in labview in decimal, hexadecimal, binary? THX

  • EFax number

    Hello, how do I change my eFax number is a number of USA to a local number of UNITED Arab Emirates? When registering, I was assigned a US number.

  • BlackBerry Z10 getting the error "SIM card is not compatible.

    Hi, I use data perfectly on my z10, until yesterday, he stopped working and get the message 'SIM card is not compatible. Everything works perfectly, I can call, send text and even use wifi. Also, my phone is unlock. Any help would be appreciated.  

  • Taskbar mode subway

    I think Microsoft did an excellent job so far with windows 8.1 but I still want the ability to display the taskbar using the metro.  I like the way metro better even on my dell not touchscreen workstation.  I still want to see the taskbar as a visibl