mardi 28 juin 2016

AS3 code, Wheel of Fortune spinning game

I'm working on wheel of fortune game. Currently the spinning time of the wheel depends from the time the button is pressed. Longer you hold, the harder you spin.

I need the wheel to spin for 4 to 5 seconds after the button is pressed, with ease in/out effect and to stop on a random sector each time. Here is the code:

import flash.display.*;
import flash.utils.getTimer;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;

var spinning:Boolean = false;
var spinTween:Tween;
var startTime:Number;
spin_bnt.addEventListener(MouseEvent.MOUSE_DOWN, setStartTime);
spin_bnt.addEventListener(MouseEvent.MOUSE_UP, spinWheel);
function setStartTime(e:MouseEvent) {
startTime = getTimer(); 
function spinWheel(e:MouseEvent) {
if (!spinning) {
    spinning = true;
    var spinTime = Math.min(12.2, Math.max(2.12, ((getTimer() - startTime) / 100)));
    var endRot = Math.round((spinTime * 360) + (Math.random() * 360));
    spinTween = new Tween(wheel_mc, "rotation", Regular.easeOut, wheel_mc.rotation, endRot, spinTime, true);
    spinTween.addEventListener(TweenEvent.MOTION_FINISH, spinTween_finished);
function spinTween_finished(e:TweenEvent):void
spinning = false;

Aucun commentaire:

Enregistrer un commentaire