Skip to main content
JonnyDL-HV74P1
Inspiring
January 15, 2010
Answered

To Tween or not to Tween

  • January 15, 2010
  • 1 reply
  • 793 views

I was looking for a little advice/direction(still on a novice level). I'm trying a project. Making Movieclips jump. up and down (jump up from outside the stage, onto the stage, and then back down outside the stage). Ideally id like to have multiple objects doing this action at once.

I was considering trying it with tweens and plugging in the clips from an array, but I'm not sure if the tween will work with array items fluidly (or how).

I'm also experimenting with enter frame (Seems to be a better choice) , but I'm having trouble having multiple clips movie continuosly/fluidly.

Tweens seem simpler to work with,but don't give you much control

Any suggestions would be appreciated

This topic has been closed for replies.
Correct answer kglad

not terribly,but its the code I got to work =] (bouncing/jumping), but if its my only option

I'll need to figure something out.

If you have a better way of doing the jump/bounce I would be glad to hear it

Ideally Id like one to three clips, jump onto and off the the stage at different intervals.

I cant seem to get the enterframe to control the clips fluidly. I had seem something similar done on lynda.com,

as a particle system (lesson), but I wasn't sure how or if I could adapt it.

Thanks for the help. I feel like I'm making progress (writing more and more in AS3), though I still have some missing pieces I need to pull it

all together, so I don't need as much as much assistance.


you'll probably get better results and find it easier to use the tween class.  just change the code between the dotted lines to start experimenting with it.  you should change mc1, mc2 and mc3 to match your objects that you want to "jump".

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;

var tw:Tween;

var endY1:uint = 50;
var endY2:uint = stage.stageHeight+50;

----------------------------------------------------

jumpF(mc1,endY1);
jumpF(mc2,endY2);
jumpF(mc3,endY2);

---------------------------------------------------

function jumpF(dobj:DisplayObject,endY:uint){
   tw = new Tween(dobj, "y", Elastic.easeOut, dobj.y, endY, 3, true);
   tw.addEventListener(TweenEvent.MOTION_FINISH,twFinishF);
}

function twFinishF(e:TweenEvent){
    if(e.currentTarget.obj.y==endY1){
        var endY:uint = endY2;
    } else {
        endY = endY1;
    }
    setTimeout(jumpF,Math.ceil(Math.random()*5000),e.currentTarget.obj,endY);
}

1 reply

kglad
Community Expert
Community Expert
January 15, 2010

you can use the flash tween class, another tweening class or your own code to animate displayobjects.  each of those options should have no trouble handling displayobjects listed in an array.

if you're having trouble with one of those approaches and want help with that approach, explain the problem and the code you're using.

JonnyDL-HV74P1
Inspiring
January 16, 2010

This is what I have tried with the ENTERFRAME.  It currently moves one clip up and down continously. I've tried to add from an array others but it the chops up the motion, Im hoping to add some other random motions to the clips (a little rotation, random height,scale), but first I got to figure out how to get all the moviclips fluidly.

//var jumpers:Array= new array();

var pickTimer:Timer= new Timer (500,1);

var howhigh:Number=50

var howlow:Number=stage.height+5

var jumpspeed:Number=5

var jumpdirection:Number=1

//jumpers = []

pickTimer.addEventListener(TimerEvent.TIMER, pickme)

pickTimer.start();

function pickme (e:TimerEvent)

{

//used this spot to load a movieclip randomly from an array

//possibly calculate other motions here

test_mc.addEventListener(Event.ENTER_FRAME, jump)

}

function jump (e:Event)

{

if (test_mc.y>=howlow)

{

jumpdirection *= -1;

}

if (test_mc.y<=howhigh)

{

jumpdirection *= -1

}

test_mc.y-=jumpspeed*jumpdirection

}

Hopefully I'm close I'm just missing something small

Thanks

kglad
Community Expert
Community Expert
January 16, 2010

are you happy with the motion of that one movieclip and just want to extend that code to apply to an array of movieclips?