View Full Version : advanced movement
StealingVision
10-20-2008, 05:25 AM
When I do the whole..... if(event.keyCode == number)
{
circle_mc.y -= number;
}.....code, it makes the ball moves really jerky and you're not able to press two keys at once. I know there's a way to make the ball move more efficiently and smoother with acceleration effects if you really get into it but I can't figure it out. Does anyone using AS3 know the code to make this work or can someone direct me to a link? Thanks. :)
runtime
10-20-2008, 04:34 PM
this will only move your circle_mc once.
you want to put it on an onEnterFrame event.
generally around here, the more code you post...the more help you get.
StealingVision
10-20-2008, 07:09 PM
Well I assumed that people would automatically think of that but I guess I was wrong, my bad. Here's my full code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, move)
function move(event:KeyboardEvent):void
{
if(event.keyCode == 38)
{
//trace(circle_mc.y)
circle_mc.y -= 20;
}
if(event.keyCode == 40)
{
//trace(circle_mc.y)
circle_mc.y += 20;
}
if(event.keyCode == 39)
{
//trace(circle_mc.x)
circle_mc.x += 20;
}
if(event.keyCode == 37)
{
//trace(circle_mc.x)
circle_mc.x -= 20;
}
}
snickelfritz
10-20-2008, 08:09 PM
Here's the code using TweenLite for easing the movement.
You'll see that diagonal movement is possible by pressing down and left arrows together, for example.
import gs.TweenLite;
stage.addEventListener(KeyboardEvent.KEY_DOWN, move);
var valX:int = mc.x;
var valY:int = mc.y;
function move(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case 38 :
valY -= 20;
break;
case 40 :
valY += 20;
break;
case 39 :
valX += 20;
break;
case 37 :
valX -= 20;
break;
}
TweenLite.to(mc, .2, {x:valX, y:valY});// ".2" is the duration.
}
StealingVision
10-21-2008, 01:58 AM
Well, that's cool but where's TweenLite? Where do I download?
snickelfritz
10-21-2008, 07:22 AM
Sorry about that.
There's actually three tweening/sequencing classes included: TweenLite, TweenMax, and TweenGroup.
Just place the "gs" folder in the same directory as your FLA.
http://blog.greensock.com/tweenmaxas3/
runtime
10-28-2008, 04:41 PM
interesting. did that work?
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.