Thanks for the reply Wolfy.
I do have pretty much the same setup as you describe.
I have quite a lot of different classes but im pasting my keyboard
object class below:
public class KeyboardObject extends MovieClip
{
private var stageRef;
public var keyIsDown:Boolean = false;
public var keyDownArray:Array;
public function KeyboardObject(_stageRef)
{
this.stageRef = _stageRef;
}
public function init()
{
initKeyDownArray();
this.stageRef.addEventListener(KeyboardEvent.KEY_DOWN,
keyDownListener);
this.stageRef.addEventListener(KeyboardEvent.KEY_UP,
keyUpListener);
}
private function initKeyDownArray()
{
this.keyDownArray = new Array();
}
private function keyDownListener(e:KeyboardEvent)
{
this.keyDownArray[e.keyCode] = true;
if(e.keyCode==Keyboard.LEFT)
{
this.keyDownArray[Keyboard.RIGHT] = false;
}
else if(e.keyCode==Keyboard.RIGHT)
{
this.keyDownArray[Keyboard.LEFT] = false;
}
else if(e.keyCode==Keyboard.UP)
{
this.keyDownArray[Keyboard.DOWN] = false;
}
else if(e.keyCode==Keyboard.DOWN)
{
this.keyDownArray[Keyboard.UP] = false;
}
}
private function keyUpListener(e:KeyboardEvent)
{
this.keyDownArray[e.keyCode] = false;
}
}
In my main class I initialise my keyboard object like so:
var obj:KeyboardObject = new KeyboardObject(this.stage);
Then in every frame of a frame event listener I say:
if(this.obj.keyDownArray[Keyboard.LEFT])
{
//some code
}
I have tested my KeyboardObject object by putting trace's in the
keyUpListener event and I see that the trace sometimes gets called 1-2
seconds after I have let go off the keyboard. This only seems to
happen in areas where the poly count is higher.
I dont know what else to do.
On Nov 29, 2:55 pm, Little Gray Wolfy <[email protected]>
wrote:
> In my code I am setting true/false values on key down/release and then
> updating movement on frame event, so depending on frames/sec updates
> come fast or not so fast. With even 30fps, I am not getting any delay.
> You might want to copy-paste your code, so folks can see it and advise
> you better.
> Also try to do
> yourMainContainer.stage.focus = yourMainContainer
> In my case I am extending UIConponent in Flex and using
> this.stage.focus = this; which removed some of the keyboard/mouse
> delay issues.
>
> Cheers.
> ~Wulf
>
>
>
> On Mon, Nov 29, 2010 at 7:18 AM, jonny <[email protected]> wrote:
> > Hi,
>
> > I am creating a driving game in away3d where you control the car with
> > the keyboard.
>
> > The problem is that the KeyboardEvent.KEY_UP event is being triggered
> > too late at certain points where the poly count is higher (the poly
> > count is about 600 at these points which I dont think is massively too
> > high right?)
>
> > For example, when you press the "Right" key on the keyboard, the car
> > goes right but when you let go of the key, sometimes the key_up event
> > triggers a few seconds later which means that the car continues to
> > veer right for a few seconds which is highly undesirable.
>
> > I tried to use the Senocular Key Object instead but the same problem
> > happens because that is also based on the KeyboardEvent.KEY_UP event.
>
> > Anyone have any ideas what I can do?
>
> > Many thanks- Hide quoted text -
>
> - Show quoted text -