PDA

View Full Version : hitTest and keyboard key question


David87
02-19-2008, 08:23 PM
Im creating a flash game which is a side scroller and has a submarine underwater which is controlled using the arrow keys underwater.
The aim of the game is for the submarine to pick up objects under the water by colliding with them (hitTest).


My question is i dont know what the code would be which would allow me to control the submarine so that when i hit one of the objects in the water with the submarine it would recognize it as a hitTest and the object would then be removed from the stage or movie


I know the basic hitTest code to create a object which is detected through collision, but i cant figure out how to implement this basic hitTest code for my submarine in my game so that it can be controlled with the keyboard keys and then recognises a hit detection when it moves over a object?

If someone could help me that wud be gr8

Thx





EDIT**


My current code i have is this


onEnterFrame = function():Void
{
if (Key.isDown(Key.RIGHT)) && (_root.submarine, hitTest(_root.creature))
{
_root.text = "Collision Detected";
}

}


where submarine is the main object which can be moved using the keyboard keys and creature is the object which i want the submarine to perform the hitTest on

David87
02-20-2008, 07:40 PM
no one knows how to solve this problem? hmm suprising it should be straightforward for anyone that knows anything about actionscript, but im new to it all

rrh
02-21-2008, 05:07 PM
I don't know why you are combining the two. Why do you think the two are intertwined?

onEnterFrame = function():Void
{
subSpeed=5;
if (Key.isDown(Key.RIGHT)) {
_root.submarine._x+=subSpeed;
}

if (_root.submarine, hitTest(_root.creature))
{
_root.text = "Collision Detected";
}

}