Jump to content
GreenSock

Jbassking

Shell game shuffle

Recommended Posts

I'm working on creating a simple shell game but it's turning out to not be so simple. I want to shuffle the 3 shells swapping position with 2 at a time.

 

For the first couple of shuffles it's fine but after that they seem to get confused and it looks like more than 2 are being shuffled at once.

 

 

function initShuffle(event:MouseEvent):void{

running = 0;

shuffle(Globals.ShuffleCount);

}

 

function shuffle(times:int):void{

Globals.IsShuffling = true;

 

this.times = times;

 

var s1:int = Globals.getRandomShellIndex(-1, Globals.Shells.length);

var s2:int = Globals.getRandomShellIndex(s1, Globals.Shells.length);

 

shellTmp1 = Globals.Shells[s1];

shellTmp2 = Globals.Shells[s2];

shellTmp2.parent.setChildIndex(shellTmp2, shellTmp2.parent.numChildren - 1);

var x1 = shellTmp1.x;

var x2 = shellTmp2.x;

finishX1 = x2;

finishX2 = x1;

ss2(shellTmp1, finishX1, true);

ss2(shellTmp2, finishX2, false);

}

 

function ss2(shellObj:MovieClip, finishX:Number, use1:Boolean){

TweenLite.to(shellObj, Globals.speed, {x: finishX, onComplete:tweenComplete} );

}

 

function tweenComplete():void{

if (--this.times > 0){

shuffle(this.times);

}

Globals.IsShuffling = false;

}

 

Ideally I would love it if I could get the Z to change as it moves on the X and than go back to it's original Z before it reaches the final X position. This would make it look like the shell in front is closer and the shell moving the opposite way is further.

 

Thanks for any help,

Joe

Link to comment
Share on other sites

I like what you are trying to do. neat idea. the only thing that might be an issue is that you call

 

ss2() for each shell that is being shuffled.

 

 

ss2(shellTmp1, finishX1, true);
ss2(shellTmp2, finishX2, false);

 

each time ss2() is called a tween is created that is using an onComplete callback which calls tweenComplete();

 

I believe tweenComplete() is being called twice every time the 2 shells are moved.

 

slow down your global speed to like 4 seconds and add a trace in tweenComplete to see how often it is firing

 

 

function tweenComplete():void{

trace("!!!! TWEEN COMPLETE !!!!");

if (--this.times > 0){
shuffle(this.times); 
}
Globals.IsShuffling = false;
}

 

what is the third boolean param in ss2 supposed to do? it doesn't look like it is being used.

It would probably make sense to use that param to decide whether or not the onComplete should fire. I'd guess that might be what you had intended at some point.

Link to comment
Share on other sites

Thanks for your response.

 

I added the trace as you suggested and the tweenComplete is only getting called once per call. So if times = 1 then it's called 2 - once for each shell.

 

The third param I since removed

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×