-
[RESOLVED] Needing help creating a simple door
I'm extremely new to actionscript and still trying to learn, currently using as2.0 because i'm more familiar with it. I want to create a door where when a character walks in front of it and when a key is pressed it goes to another frame. I've been trying to look up tutorials and haven't found any at all. Anyone have a script that might help?
-
if (char.hitTestObject(door))
{
if (event.keyCode == Keyboard.SPACE)
{
gotoAndStop(2);
}
}
Here's a script I've been trying to use. I'm not entirely sure if this is even correct.
-
Prid - Outing
Hi,
you're close to a solution with that code of yours. The only problem is that your code, if used by itself, will only check ONCE if char is touching/hitting the door, and that is when you first start your game. To continuously check for the character hitting the door, you can wrap your code in an enterFrame event, which basically runs repeatedly (code goes on a Frame):
PHP Code:
onEnterFrame = function(){
if(char.hitTest(door)){
if(Key.isDown(Key.SPACE)){
gotoAndStop(2);
}
}
}
The code is to be used on a Frame (you do this by selecting a frame and opening the actions panel), and it's assumed that you have the movieclips char and door on stage. If you want the door movieclip to go to Frame 2, then simply add this instead: door.gotoAndStop(2);
also you're code seems to be in AS3, but I've converted it to AS2 above Let me know if you need help with understanding the code or even a sample FLA for testing
Last edited by Nig 13; 06-04-2015 at 05:55 PM.
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
oh wow! thanks, that helps a lot. I kinda suspected the code was AS3, I'm such a terrible noob XD
-
Prid - Outing
Haha, no problem, glad I could be of help You're not a noob, anyone can make a mistake and we learn from our mistakes
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|