ActionScript 3.0 :: Flash HitTestObject: One "hit" Counting As Multiple?
May 15, 2011
I'm having a problem in my side-scrolling game where when each "prey" gets eaten by the character, they are counting multiple times, causing the "score +1" to happen too many times. It's almost like they are hitting the character a few times before being registered as "hit" and disappearing.
Code:
function preyHandler(event:Event)
{// handler for prey getting eaten
for (var i:int=0; i<allPrey.length; i++)[code].....
View 6 Replies
Similar Posts:
Aug 23, 2011
I have been making a game and have run into some problems I want to make a hitTestObject between multiple arrays, i have tried something like this:
for(var i:Number = 0; i < array1.length; i++)
{
array1[i].y -= 10; //Moves object up
for(var a:Number = 0; i < array2.length; a++)
[Code]....
When i run it, some object will detect the collision and will output "hit", but some will ignore that. I have also noticed that some object in the array1 stop running the move code (array1[i].y -= 10) after i have added another array.
View 4 Replies
Apr 11, 2012
I have a horizontally scrolling flying game involving a character and diferent types of food moving across the screen from right to left which the character has to collect ("hit"). I have the hitTestObject working for 2 different food movieclips with one item belonging to a healthyList, and the other to a junkList.
how to add more items (movieclips) to each of the lists, so that I have for example 6 items in the healthyList and 4 items in the junkList.
Below is the code in my Engine.as file. The red highlighted text is the code that creates the problem. I thought that I just needed to add this line in order to add another item to the "healthyList" of food types, but I obviously have it in the wrong place or have the wrong code completely.
package
{
import flash.display.MovieClip;
import flash.display.Stage;
[Code]......
View 7 Replies
Nov 16, 2011
simply set: I do have a dragable movieclip (mcMagniDisplay) which is generated on the fly while initializing all my variables ... and I do have 4 circles (mc_boxXHitCircle) which are already placed at the bottom in the stage in advance.All I need to do is check, wheter the mcMagniDisplay is hovering one of the circles or not.
********************** code snippet ***********************
var mcMagniDisplay:MovieClip = new MovieClip();
stage.addEventListener(Event.ENTER_FRAME, hitTest);
[code]......
View 5 Replies
Dec 23, 2011
i have 4 movieclips on my stage , there are mc_1, mc_2, mc_3 and mc_4 and i also have 1 dragable movieclip (named ball), and i want something traced if my ball touch another movieclip, below are my code
ActionScript Code:
ball.addEventListener(MouseEvent.MOUSE_DOWN, drag);
stage.addEventListener(MouseEvent.MOUSE_UP, drop);
function drag(e:MouseEvent):void
{
[Code]...
View 2 Replies
May 10, 2010
I have the following code to pick up collision detection between two objects:
[Code]...
View 2 Replies
Jun 3, 2009
I have a circle_mc on the stage. Then I create randomly placed 20 squares (square_mc) on the stage. I can move my circle on that stage, and all I want is to check hitTestObject(or any *yet unknow for me* method that gives a result) if circle touches any of squares. Then I need to remove that touched movieClip (square) from the stage. hitTestObject checks if 2 specific objects are touched. My question is how to know which square is which, and then if it touches with circle_mc to remove it from the stage.
Code:
Select allif (circle_mc.hitTestObject( ?whatHere? ) ) {
?whatHere?.removeChild( ?whatHere? );
}
View 2 Replies
Jan 15, 2009
I created a timer with found tutorials and the Flash help files and everything works fine. My timer counts up from 000.000,0 to 999.000,0. Now I would like to also be able to do the same, but counting down from 999.000,0 to 000.000,0
Easy enough I thought, but now . how to make some modifications in my code to count down.
My code for counting up is the follow:
Code: Select allvar hours:Number = 0;
var seconds:Number = 0;
var minutes:Number = 0;
var pauseTime:Number = 0;
[Code].....
View 2 Replies
Mar 23, 2006
how I can count the number of clicks that people have made on a link in a flash movie. Not just the number of clicks one person makes within the movie but the number of clicks everyone has made
View 2 Replies
Mar 18, 2012
I have an object that rotates based on the mouse positionand I'm trying to count the degrees as it rotates.for example if i rotate 200 degrees cww the degree measurement is 200if i will rotate another 350 degrees cww the degree measurement will be 550now if i rotate 150 cw the measurement will be 400 now.I have this code: (it counts radians, but it is the same idea)p1 = mouse position
PHP Code:
theX theY =
p1.y - 250;radian = -
[code].....
View 8 Replies
Jan 29, 2012
I have a little problem with counting all elements on stage. Flash, unfortunately is counting all objects on the stage without drawn objects (all shapes, including drawing objects, rectangles etc) all missed. Is there any way to count them?
View 2 Replies
Nov 24, 2005
I am creating a simple game where you must remember the name of a number of people. On the stage is a table with faces. Text appears, asking who, for example, "Mike" is. You then have to click the correct face. The questions appear randomly.I have come this far, but what I want to do is the following:
1) Restrict the number of random questions, presumably by adding a variable, with the value incrementing by each question, and tells the movie clip to go to the "game results" frame when reaching a certain number.
2) Keep track of the number of questions answered correctly/incorrectly. I suppose this is also done easily by adding a value for number of incorrect answers, which is increased for each incorrect answer, with the amount of correct answers being calculated like (total number of questions)-(incorrect answers).
3) Display the number of correct and incorrect questions on the "game results" frame. For example "You answered X number of questions correctly, and Z number of questions incorrectly".
I know that the pieces of code below should be used, but I don`t know how to put it all together, or where to put it. I suppose the main code should be in the first frame, and some should be in the buttons.
Code:
var questionsAsked:Number;
Code:
myValue++;
Code:
if (questionsAsked == 20){
gotoAndStop("results");
}
View 3 Replies
Jan 16, 2011
I have a MC called 'playerP" and inside of it with 7 different MC. I can't seems to hit test on the children MC, it always show [object position_2]
private function cMove(e:MouseEvent):void
{
trace(MovieClip(playerP.RR), playerP.PT)
[Code]....
View 1 Replies
May 31, 2011
I'm trying to make a simple demo that works.
Basically, I have 4 Mcs on the stage. The same Mc with 4 instance names. Each Mc is a hole, and on frame 2 a bee appears. The 2 states of the Mc are:
frame 1, label: 'start'.
frame 2, label: 'action'. (a bee appears).
Here's my code so far. It works without errors so far, but I hope the arrays are setup right. What I'd like to happen is:
1) When the user has clicked on 4 holes in any order, the 'welldone' box appears. code to insert: addChild(welldone);
2) Since the order is random, I have a dynamic text box at the bottom of the stage. I'd like the words: one, two, three, four.. appearing in the textfield in that order.
It could be very simple or quite complex
var welldone:MovieClip = new Welldone();
var clipArray:Array = [hex1, hex2, hex3, hex4];
for (var i:int = 0; i < clipArray.length; i++) {
[Code].....
View 14 Replies
Aug 25, 2011
I have an array example from a Flash Connection tutorial, and I'm wondering if there's an easy way to add a bit of code to count through the user's clicks.
What I'm trying to do is count the clicks, so that once someone has clicked on all 5 buttons, something happens.
Code:
var clipArray:Array = [home_mc, about_mc, products_mc, services_mc, contact_mc];
for (var i:int = 0; i < clipArray.length; i++) {
clipArray[i].buttonMode = true;
[Code]....
View 6 Replies
Aug 17, 2011
I'm new to ActionScript but I've been following Lynda tutorials and tried to tailor them to my game. I simply want to make my character at the top of the screen shoot at enemies below. The error I'm getting when I press the shoot button is "Parameter hitTestObject must be non-null." I've read some other forum posts on this error for ideas but still can't seem to make mine work.
{
import flash.display.MovieClip;
import flash.events.Event;
[code]......
View 3 Replies
Sep 11, 2010
Trying to do hitTestObject on instances that are dynamically placed on the stage. Receiving an error:
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
[code].....
View 1 Replies
Jul 4, 2011
I'm new to papervision 3d and I created two display objects in basic view.
Here's a part of the code :
...
_stick = new Cube(materials, 50, 5, 500);
_ball = new Sphere(new ColorMaterial(0xfc0000), 80);
In the onRenderTick method, I tried to check whether two objects are hitted
[Code]...
However, stick.hitTestObject always returns false even if the stick really hits the ball as I see in the flash.
View 1 Replies
Aug 7, 2011
I had a problem with my hitTestObject collision detection a couple of days ago which has since been fixed (How can I solve my hitTestObject Collision Null Object Ref Error) with the help of you folks. My problem now is as such: When my "enemy.hit" comes into contact with "player.hit" it registers as a hit - this is good. When my "building.collide" comes into contact with "player.hit" it registers as a hit - this is good.
However, when my "building.collide" comes into contact with my "enemy.hit" it does not register, but sometimes it does register even though the only enemy on-screen is many pixels away from it - as if either the building or enemy "hitBox" is somewhere other than directly on the graphic(MovieClip in this case).
[Code]....
View 3 Replies
Aug 27, 2011
I'm making a simple snake game in as3. the problem I'm having is that the stroke on elements slightly overlap thus when the snake passes by the apple in an adjacent square it triggers hit test object. If i reduce the size or stroke of either the snake or the apple then they dont properly line up to the grid. is there a way i can use hittestobject but reduce the area of the object that will trigger it. ie only trigger if it hits the center of the object?
//this will hit when snake is adjacent due to overlapping strokes
if(snake.hitTestPoint(apple.x,apple.y,true))
{[code]............
when I traced the values for the bottom code the values are what would be expected but some reason hitTestPoint wont trigger. strangely if I do + 1 it will still work but because the stroke is 2 i need at least +3. If i set apple.x+n as a variable and use the variable in hitTestPoint it wont trigger. also on all cases where it does not trigger i get no errors and all trace values are what you would suspect...
View 1 Replies
Jun 7, 2010
I am placing my code within frames and using the code below to hit test an object. After the animated object leaves the stage, the hit test starts getting errors because it is now looking for an object that isn't there. NULL
Code:
var o1:MovieClip;
o1.addEventListener(Event.ENTER_FRAME, o1hit);
function o1hit(Event) {
[Code]...
So the question is: How can I get the Hit Test to stop after a certain frame? Or does it have to do with the EventListener?
View 1 Replies
Sep 16, 2010
Is there any other function similar to 'hitTestObject'. Am having problem with this function, b'coz it checks the collision on a box around that object. I want to find the actual collision with the object.
View 2 Replies
Apr 28, 2011
I have a bullet object and a boulder object (both movieclips originating from JPEGs) in my AS3 game. The trouble I'm having is with hitTestObject for the collision detection, as it's taking in to account the transparent areas and basing the collision on the bounding boxes surrounding the movieclips. This is a problem because the collisions are not accurate and if the bullet (long and thing line shaped) is at an angle...the bounding box is quite large around it...and it's "colliding" with the boulder even though it's visibly many pixels away. Is there a way to detect MovieClip collisions that ignore transparent areas?
View 2 Replies
Jan 18, 2012
i have a flash file with a number of movieclips in the library - various bubbles that can be popped at a clilck. The fla has a document class - BubbleGame.as, and the various bubble mcies in the library are all exported for action script, (using their own names, but) with a mutual Base Class - BubbleBase.as, in order that all the various bubble movie clips have the same behavior: load in a random position, play out their own timelines, be popped when clicked, and if not popped - reload in another position.
This is all working very well, however, I want the movie clips removed if they hit an object on the stage. The object has an instance name of sym_mc, and I have tried various bits of code to cause the bubble to be removed when it hits that object, but i either get errors or nada.
I tried doing the hitTestObject code in both the document class and the base class. It seems more appropriate to have it in the base class - BubbleBase.as (below), because that tells the bubbles what to do.
[Code]...
View 12 Replies
Apr 11, 2010
I have an XMLList 'Keywords', which consists of about 30 elements. I want to count the number of unique keywords in the List, and how often they occur. Then display the top 3 most occuring keywords.
View 1 Replies
Aug 21, 2010
hy this very simple preloader is not counting? It sits still on 1%, thats it, then eventually the content of the next scene fills the screen.(I use to import a number of heavy images to Scene 2 to slow the loading process down.)
View 2 Replies
Sep 7, 2005
and had another query on it. The AS on the first frame so far is :
//start number
var nr = 0;
//end number
[code].....
View 1 Replies
Dec 22, 2005
I'm working on a demo (mx 04) and it has a little over 14,000 frames so far. The preloader was working before but now it isn't. Is there a limit or something to how flash works when there are so many frames used?
View 5 Replies
Jun 27, 2006
Let's say I have a XML file with three types of nodes; type1, type2 and type3.How do I count the number of nodes named type1?
View 1 Replies
Jan 25, 2009
What actionscript code will be able to determine these numerals for me and assign them to variables? I want 1 variable to tell me how many firstChild(s?) there are <inventors>
Another variable to tell me how many children each firstChild(?) has, <person>
And another variable to tell me how many children each <person> has (name & comment)
Code:
<?xml version="1.0"?>
<list>
<inventors>[code].....
View 1 Replies