Game Development Reference
In-Depth Information
break;
case Keyboard.LEFT:
m_keyLEFT = false;
break;
case Keyboard.RIGHT:
m_keyRIGHT = false;
break;
}
}
// The callback fired when timer fires, move the sprite
private function onTimer(e:TimerEvent):void {
if ( m_keyUP ) {
m_sprite.y -= SPEED;
// make sure it does not go negative
if ( m_sprite.y < 0 )
m_sprite.y = 0;
}
if ( m_keyDOWN ) {
m_sprite.y += SPEED;
// does not go out of stage
if ( m_sprite.y > HEIGHT )
m_sprite.y = HEIGHT;
}
if ( m_keyLEFT ) {
m_sprite.x -= SPEED;
// make sure it does not go negative
if ( m_sprite.x < 0 )
m_sprite.x = 0;
}
if ( m_keyRIGHT ) {
// does not go out of stage
m_sprite.x += SPEED;
if ( m_sprite.x > WIDTH )
m_sprite.x = WIDTH;
}
}
}
}
 
Search WWH ::




Custom Search