Highlighted

Wheel Game - sound f/x using hitPoint working TOO well...

Community Beginner ,
Jan 20, 2019

Copy link to clipboard

Copied

Okay gang, I have what I think may be a pretty good "poser" for any gurus out there.  I have developed what I think is a pretty solid "Wheel of Fortune" style spinning wheel animation, which includes: spin up and slow down; a randomly generated number of spin loops; a counter to determine which Wheel Wedge is active and how much it's worth.  I'm pretty happy with it as it stands. I will tell you in advance I am no guru so I tend to do my ActionScripting in long-form.  I'm sure a couple of well written Arrays would solve a lot of my lengthy coding, but I am only a part-time user so I go with what I know and what I find and cobble it together until it works!

Screenshot 2019-01-20 22.29.34.png

Here's the problem - I have tried multiple ways to add the "beep" to the spinning wheel with no success.  I've been able to produce the sound, just not in a satisfactory way. From exporting it for ActionScript and calling it with code to putting it in a movie clip to using collision detection, nothing has produced the desired results.  I think the best solution is a hitPointTest but that's where the real issue is. I have tried both the Point and Object modes of collision detection, with the following results:  If I use the Wheel Wedges themselves (which are already used to track the on-stage data) the sound plays several times in rapid/by-frame succession as the wheel spins up and slows down, because the pointer is still in contact with the same wedge.  I have also tried using the pegs in between the wedges as the collision objects, but then the problem becomes the fact that as the wheel spins, the regularity of each peg hitting the exact x and y coordinates of the pointer are practically null.

What I think I need is a way to use the individual wedges as the triggers, but somehow telling the beep sound to play only once, even if it's still hitting the same wedge.  I only want the beep the first instance it makes contact, and then not again until it encounters the next wedge.  That way the audio will track with the spin up and slow down speeds. The other problem is that the beeps overlap when the wheel gets spinning but I think I can trim the audio to a single frame and that would eliminate the overlap.

Here's a link to the FLA code for anyone who wants it:
https://login.filesanywhere.com/fs/v.aspx?v=8c696889595f6d7d6b9b

Thanks in advance for taking the time to read this and for any help you can render.

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

Hi.

Instead of using an enterFrame event and hit test, what I like to suggest to you is a tween approach.

Your wheel is divided in equal 15 degrees segments - I hope this is the correct way of saying this in English -, so I think it's best to find the current wedge using the relation between the wheel rotation and this fixed angle amount.

Like this:

AS3 code:

import fl.transitions.Tween;

import fl.motion.easing.*;

import flash.events.MouseEvent;

import fl.transitions.TweenEvent;

var baseAngle:uint = 15;

var randomAngleRange:uint = 36;

var spinDuration:uint = 3;

var numSections:uint = mWheel.wedges.numChildren;

var tween:Tween;

function spinTheWheel(e:MouseEvent):void

{

    var random:uint = randomAngleRange + uint(Math.random() * randomAngleRange);

    tween = new Tween(mWheel, "rotation", Sine.easeInOut, mWheel.rotation, mWheel.rotation + random * baseAngle, spinDuration, true);

    tween.addEventListener(TweenEvent.MOTION_CHANGE, wheelSpinning);

    tween.addEventListener(TweenEvent.MOTION_FINISH, wheelFinish);

    e.currentTarget.visible = false;

}

function wheelSpinning(e:TweenEvent):void

{

    var currentRotation:int = baseAngle * int(rotationTo360(mWheel.rotation) / baseAngle);

    var index:uint = numSections - (uint(currentRotation / baseAngle) % numSections);

    if (index == numSections)

          index = 0;

    mWheel.wedges["mWedge" + (index + 1) % numSections].gotoAndStop(1);

    mWheel.wedges["mWedge" + index].gotoAndStop(2);

}

function wheelFinish(e:TweenEvent):void

{

     spin.visible = true;

}

function rotationTo360(rot:Number):Number

{

    return (rot + 360) % 360;

}

spin.addEventListener(MouseEvent.CLICK, spinTheWheel);

For the sound, all I had to do was to place it in the second frame of the wedge Movie Clip with Sync set to Event.

I think it's a simpler code and you have the advantage of choosing different easing types according to your needs and/or preferences.

FLA download:

Wheel of Fortune AS3 - Single Player_v2 - Test.zip - Google Drive

I hope this helps.

Regards,

JC

TOPICS
Discussions

Views

151

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Wheel Game - sound f/x using hitPoint working TOO well...

Community Beginner ,
Jan 20, 2019

Copy link to clipboard

Copied

Okay gang, I have what I think may be a pretty good "poser" for any gurus out there.  I have developed what I think is a pretty solid "Wheel of Fortune" style spinning wheel animation, which includes: spin up and slow down; a randomly generated number of spin loops; a counter to determine which Wheel Wedge is active and how much it's worth.  I'm pretty happy with it as it stands. I will tell you in advance I am no guru so I tend to do my ActionScripting in long-form.  I'm sure a couple of well written Arrays would solve a lot of my lengthy coding, but I am only a part-time user so I go with what I know and what I find and cobble it together until it works!

Screenshot 2019-01-20 22.29.34.png

Here's the problem - I have tried multiple ways to add the "beep" to the spinning wheel with no success.  I've been able to produce the sound, just not in a satisfactory way. From exporting it for ActionScript and calling it with code to putting it in a movie clip to using collision detection, nothing has produced the desired results.  I think the best solution is a hitPointTest but that's where the real issue is. I have tried both the Point and Object modes of collision detection, with the following results:  If I use the Wheel Wedges themselves (which are already used to track the on-stage data) the sound plays several times in rapid/by-frame succession as the wheel spins up and slows down, because the pointer is still in contact with the same wedge.  I have also tried using the pegs in between the wedges as the collision objects, but then the problem becomes the fact that as the wheel spins, the regularity of each peg hitting the exact x and y coordinates of the pointer are practically null.

What I think I need is a way to use the individual wedges as the triggers, but somehow telling the beep sound to play only once, even if it's still hitting the same wedge.  I only want the beep the first instance it makes contact, and then not again until it encounters the next wedge.  That way the audio will track with the spin up and slow down speeds. The other problem is that the beeps overlap when the wheel gets spinning but I think I can trim the audio to a single frame and that would eliminate the overlap.

Here's a link to the FLA code for anyone who wants it:
https://login.filesanywhere.com/fs/v.aspx?v=8c696889595f6d7d6b9b

Thanks in advance for taking the time to read this and for any help you can render.

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

Hi.

Instead of using an enterFrame event and hit test, what I like to suggest to you is a tween approach.

Your wheel is divided in equal 15 degrees segments - I hope this is the correct way of saying this in English -, so I think it's best to find the current wedge using the relation between the wheel rotation and this fixed angle amount.

Like this:

AS3 code:

import fl.transitions.Tween;

import fl.motion.easing.*;

import flash.events.MouseEvent;

import fl.transitions.TweenEvent;

var baseAngle:uint = 15;

var randomAngleRange:uint = 36;

var spinDuration:uint = 3;

var numSections:uint = mWheel.wedges.numChildren;

var tween:Tween;

function spinTheWheel(e:MouseEvent):void

{

    var random:uint = randomAngleRange + uint(Math.random() * randomAngleRange);

    tween = new Tween(mWheel, "rotation", Sine.easeInOut, mWheel.rotation, mWheel.rotation + random * baseAngle, spinDuration, true);

    tween.addEventListener(TweenEvent.MOTION_CHANGE, wheelSpinning);

    tween.addEventListener(TweenEvent.MOTION_FINISH, wheelFinish);

    e.currentTarget.visible = false;

}

function wheelSpinning(e:TweenEvent):void

{

    var currentRotation:int = baseAngle * int(rotationTo360(mWheel.rotation) / baseAngle);

    var index:uint = numSections - (uint(currentRotation / baseAngle) % numSections);

    if (index == numSections)

          index = 0;

    mWheel.wedges["mWedge" + (index + 1) % numSections].gotoAndStop(1);

    mWheel.wedges["mWedge" + index].gotoAndStop(2);

}

function wheelFinish(e:TweenEvent):void

{

     spin.visible = true;

}

function rotationTo360(rot:Number):Number

{

    return (rot + 360) % 360;

}

spin.addEventListener(MouseEvent.CLICK, spinTheWheel);

For the sound, all I had to do was to place it in the second frame of the wedge Movie Clip with Sync set to Event.

I think it's a simpler code and you have the advantage of choosing different easing types according to your needs and/or preferences.

FLA download:

Wheel of Fortune AS3 - Single Player_v2 - Test.zip - Google Drive

I hope this helps.

Regards,

JC

TOPICS
Discussions

Views

152

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 20, 2019 0
Adobe Community Professional ,
Jan 21, 2019

Copy link to clipboard

Copied

Hi.

Instead of using an enterFrame event and hit test, what I like to suggest to you is a tween approach.

Your wheel is divided in equal 15 degrees segments - I hope this is the correct way of saying this in English -, so I think it's best to find the current wedge using the relation between the wheel rotation and this fixed angle amount.

Like this:

AS3 code:

import fl.transitions.Tween;

import fl.motion.easing.*;

import flash.events.MouseEvent;

import fl.transitions.TweenEvent;

var baseAngle:uint = 15;

var randomAngleRange:uint = 36;

var spinDuration:uint = 3;

var numSections:uint = mWheel.wedges.numChildren;

var tween:Tween;

function spinTheWheel(e:MouseEvent):void

{

    var random:uint = randomAngleRange + uint(Math.random() * randomAngleRange);

    tween = new Tween(mWheel, "rotation", Sine.easeInOut, mWheel.rotation, mWheel.rotation + random * baseAngle, spinDuration, true);

    tween.addEventListener(TweenEvent.MOTION_CHANGE, wheelSpinning);

    tween.addEventListener(TweenEvent.MOTION_FINISH, wheelFinish);

    e.currentTarget.visible = false;

}

function wheelSpinning(e:TweenEvent):void

{

    var currentRotation:int = baseAngle * int(rotationTo360(mWheel.rotation) / baseAngle);

    var index:uint = numSections - (uint(currentRotation / baseAngle) % numSections);

    if (index == numSections)

          index = 0;

    mWheel.wedges["mWedge" + (index + 1) % numSections].gotoAndStop(1);

    mWheel.wedges["mWedge" + index].gotoAndStop(2);

}

function wheelFinish(e:TweenEvent):void

{

     spin.visible = true;

}

function rotationTo360(rot:Number):Number

{

    return (rot + 360) % 360;

}

spin.addEventListener(MouseEvent.CLICK, spinTheWheel);

For the sound, all I had to do was to place it in the second frame of the wedge Movie Clip with Sync set to Event.

I think it's a simpler code and you have the advantage of choosing different easing types according to your needs and/or preferences.

FLA download:

Wheel of Fortune AS3 - Single Player_v2 - Test.zip - Google Drive

I hope this helps.

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 21, 2019 0
Community Beginner ,
Jan 21, 2019

Copy link to clipboard

Copied

Thank you!!!  It works like a dream and I certainly appreciate the opportunity to dissect and understand the code you have provided. Always eager to learn!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 21, 2019 1
Adobe Community Professional ,
Jan 21, 2019

Copy link to clipboard

Copied

Excellent!

You're welcome!

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 21, 2019 0