How to check if mouse is on a shpae in Flash

I am building a simple flash game in AS3 and I was wondering if I could use code similar to "hitTestPoint()" except it applies to a shape and not a symbol?

The maze is simply a line shape, so if the ball moves off the shape then the game is terminated. Is this possible?

Thanks, Peter

Answers


Simple enough. Just test if the maze is found at the current location of the ball.

function test():Boolean {
    // First we get the absolute coordinates of the ball
    var loc:Point = ball.localToGlobal(new Point(0,0));
    // Next we collect all the DisplayObjects at that coordinate.
    var stack:Array = getObjectsUnderPoint(loc);
    var found:Boolean = false;

    // Now we cycle through the array looking for our maze
    for each (var item in stack) {
        if (item.name == "mazeShape") {
            found = true;
        }
    }

    return found;
}

If you're really interested in whether the mouse (and not the ball) is off the maze, just replace the first line with this:

var loc:Point = new Point(mouseX, mouseY);

Depending how your game looks, you could also use coordinates for this.

Just tell the game if Player > 100 Y it is off the game it's limits = Restart.

It might won't be the most solid solution but it is definetely a way to solve it as I don't believe there is a function for it, please do correct me if I am wrong.


The AS3 Collision Detection Kit will let you detect hits based on color if separating the maze into smaller symbols is not appropriate.


Need Your Help

Number From Database in Python

python database number-formatting

I am a newbie at Python, and wading through the various peculiarities of the language. One of the peculiarity I found is the output of the following code snippet:

How to grab mysql field dynamically via php

php mysql

In php I access results from a mysql query results set as such:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.