00:00
00:00
Newgrounds Background Image Theme

Boochingi just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Help with Tweens

359 Views | 2 Replies
New Topic Respond to this Topic

Help with Tweens 2014-09-06 02:48:35


Okay, so it's late and i'm struggling a little bit with this code bit i'm working on. I'm a novice programmer and all blah blah, i would really appreciate some guidance. I'm working on a chunk of code for a game and i'm trying to get the shop to drop down using the following code:

shopWindow.addEventListener(MouseEvent.CLICK, shopopen);
function shopopen(event:MouseEvent)
{
	var shopopentween:Tween = new Tween(shopWindow,"y",Strong.easeOut,-123,173,24);
}

And it opens perfectly!
however, i could not get it to close. I've tried using booleans to tell when its open or closed but that did not work. I attempted to remove the EventListener, and add a second one, but that didn't work either. How can i apply a tween to an object on click, then a different tween on the next click?

Response to Help with Tweens 2014-09-06 03:27:47


There's few ways of doing it based on your game's structure. The most direct way I can think of is this:

var shopIsOpen:Boolean = false;

shopWindow.addEventListener(MouseEvent.CLICK, shopopen);
function shopopen(event:MouseEvent):void
{
	shopIsOpen = !shopIsOpen;

	var shopopentween:Tween;

	if (shopIsOpen) shopopentween = new Tween(shopWindow,"y",Strong.easeOut,-123,173,24)
	else shopopentween = Tween(<closing tween>);
}

If ya have something to say, PM me. I have a lot of time to spare.

Also never PM egg82.

BBS Signature

Response to Help with Tweens 2014-09-06 10:25:57


At 9/6/14 03:27 AM, MintPaw wrote: There's few ways of doing it based on your game's structure. The most direct way I can think of is this:

var shopIsOpen:Boolean = false;

shopWindow.addEventListener(MouseEvent.CLICK, shopopen);
function shopopen(event:MouseEvent):void
{
shopIsOpen = !shopIsOpen;

var shopopentween:Tween;

if (shopIsOpen) shopopentween = new Tween(shopWindow,"y",Strong.easeOut,-123,173,24)
else shopopentween = Tween(<closing tween>);
}

This worked wonderfully, thank you very much!
I guess I should have known not to assign to values to one variable. But this makes perfect sense, thank you.