var keyLeft = false;
var keyRight = false;
var balikLeft = false;
var balikRight = false;
var rotationSpeed;
stage.addEventListener(KeyboardEvent.KEY_DOWN, tekanKey);
stir.addEventListener(Event.ENTER_FRAME, stirEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_UP, lepas);
function tekanKey(control)
{
if (control.keyCode == 37)
{
keyLeft = true;
rotationSpeed = 5;
}
else if (control.keyCode == 39)
{
keyRight = true;
rotationSpeed = 5;
}
}
function lepas(control)
{
if (control.keyCode == 37)
{
keyLeft = false;
balikLeft = true;
rotationSpeed = 1;
}
else if (control.keyCode == 39)
{
keyRight = false;
balikRight = true;
rotationSpeed = 1;
}
}
function stirEnterFrame(control)
{
var velocity = 0;
if (keyLeft&& control.currentTarget.rotation>-90 )
{
control.currentTarget.rotation -= rotationSpeed;
}
else if (keyRight && control.currentTarget.rotation<90)
{
// rotate the object
control.currentTarget.rotation += rotationSpeed;
}
else if (balikLeft)
{
if (stir.rotation < 0)
{
control.currentTarget.rotation += rotationSpeed;
}
else
{
balikLeft = false;
}
}
else if (balikRight)
{
if (stir.rotation > 0)
{
control.currentTarget.rotation -= rotationSpeed;
}
else
{
balikRight = false;
}
}
var putaran = control.currentTarget.rotation / 180 * Math.PI;
control.currentTarget.x += Math.cos(putaran) * velocity;
control.currentTarget.y += Math.sin(putaran) * velocity;
}
WHAT'S NEW?
Loading...
stir control with key as3
- Judul : stir control with key as3
- Penulis : PF studio
- Kategori : Archive Code Snippets
-
Rating : 100% based on 10 ratings. 5 user reviews.
Item Reviewed: stir control with key as3
9 out of 10 based on 10 ratings. 9 user reviews.
facebook
twitter
google+
fb share