|
Answer» So Im trying to learn platform GAMING for fun, cs5 flash AS.3
Followed TUT. Was at it for hours, quit came back next day realized i had missed alot of the tut instructions, can't understand how I could miss it even after reviewing the video 4-6 times. ANYWAY its a simple tutorial but im a simpler man. The ball is supposed to fall on the floor but It doesn't. Its probably something awkwardly simply but I've just started. Also I think I've copied on everything, but I taught so yesterday too...
TUTORIAL LINK: Part1: http://www.youtube.com/watch?v=Z160NtbM6Zs Part2: http://www.youtube.com/watch?v=LVaEZMiiz7A
My fla. file: http://www.mediafire.com/?hm2q3k2gcdbsmm0 My Code:
Code: [Select]import flash.events.KeyboardEvent; import flash.events.Event;
var KeyThatIsPressed:uint; var rightKeyIsDown: Boolean= false; var leftKeyIsDown: Boolean= false; var upKeyIsDown: Boolean= false; var downKeyIsDown: Boolean= false;
var gravity: Number = 1; var yVelocity: Number = 0; var canJump: Boolean= false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, PressAKey); stage.addEventListener(KeyboardEvent.KEY_UP, ReleaseAKey);
function PressAKey(event:KeyboardEvent):void { if(event.keyCode == Keyboard.RIGHT) { rightKeyIsDown = true; } if(event.keyCode == Keyboard.LEFT) { leftKeyIsDown = true; } if(event.keyCode == Keyboard.UP) { upKeyIsDown = true; } if(event.keyCode == Keyboard.DOWN) { downKeyIsDown = true; } }
function ReleaseAKey(event:KeyboardEvent):void { if(event.keyCode == Keyboard.RIGHT) { rightKeyIsDown = false; } if(event.keyCode == Keyboard.LEFT) { leftKeyIsDown = false; } if(event.keyCode == Keyboard.UP) { upKeyIsDown = false; } if(event.keyCode == Keyboard.DOWN) { downKeyIsDown = false; } }
circle_mc.addEventListener(Event.ENTER_FRAME, moveTheCircle);
function moveTheCircle(event:Event):void { if(rightKeyIsDown) { circle_mc.x +=5; } if(leftKeyIsDown) { circle_mc.x -=5; } if(upKeyIsDown && canJump) { yVelocity = -15; canJump = false; } yVelocity+ gravity; if(! floor_mc.hitTestPoint(circle_mc.x, circle_mc.y, true)) { circle_mc.y + yVelocity; } if(yVelocity > 20) { yVelocity = 20; } for(var i:int = 0; i<10; i++) { if(floor_mc.hitTestPoint(circle_mc.x, circle_mc.y, true)) { circle_mc.y --; yVelocity = 0; canJump = true; } } } Sorry if wrong section
|