You'd be better off doing it in an onEnterFrame or a onMouseMove than
in a setInterval call -- code is only executed between frames anyway,
so your way just adds extra processing burden.

Since all these events are only working once per frame, just comparing
x's isn't likely to give you meaningful data -- if a player moves his
mouse rapidly left to right at a rate that's some factor of your
framerate, you could easily get the same (or similar) x value at every
read. Increasing the framerate could help this, but brings other

Consider placing a small, invisible movieclip on the path you intend
the user to move his mouse, and listen for onRollOver. You can use the
number of RollOver events per second to adjust speed. Just keep in
mind that you won't get any more events than your framerate.

Finally, instead of adjusting speed directly, adjust max speed and
provide a constant acceleration toward the current max speed. For
example, if the user starts out at a rate that correlates to 50 mph,
his current speed should slowly increase at a constant rate over many
seconds until it reaches 50. Similarly, once the user begins to slow
down, the speed should decrease linearly to the maximum speed allowed
by the mouse move rate. This provides a slow acceleration at the
beginning -- which is probably what you want if you're emulating the
old button mashers -- and provides smooth speed changes as the game
progresses, which is definitely good.

On 2/12/08, Paul Steven <[EMAIL PROTECTED]> wrote:
> I am trying to program a game where a character moves faster, the faster the
> player moved the mouse left and right. A bit like the old Dailey Decathlon
> Game where you had to hit 2 keys on the keyboard on after the other as fast
> as you can to control the speed of say a character running.
> I could do with some advice on how to achieve this.
> I have a frame rate of 31 FPS, with a movie width of 600 pixels.
> Currently I am calling a function every 10ms to calculate the speed
> objShowerGame.updateSpeedInterval = setInterval(updateSpeed, 10);
> I compare the previous mouse X position with the current one and use this
> difference as the speed.
> This isn't really working so I could do with some suggestions.
> Thanks
> Paul
> _______________________________________________
> Flashcoders mailing list

Cory Petosky : Lead Developer : PUNY
1618 Central Ave NE Suite 130
Minneapolis, MN 55413
Office: 612.216.3924
Mobile: 240.422.9652
Fax: 612.605.9216
Flashcoders mailing list

Reply via email to