Jump to content
Search Community

Enclosed Stage: Mario Bros-style tweening (AS3)

protoemocional test
Moderator Tag

Recommended Posts

Dear TweenMax users,

 

 

I have another question: How can I disort the x,y space on the stage, in order for an object moving towards X:0 to being appearing from X:stage.Width?

 

In other words, anyone old enough here can remember those Atari/early Nintendo games, where the character upon approaching the right extreme of the screen would appear at the opposing side, the left side.

 

I have devised a system using 2 identical movieclips, 1 TweenMax constructor, 1 TweenMax.fromTo method, and 1 TimelineMax to coordinate the, using the stagger and align properties.

 

To anyone who iss a genius on this, is there any other method with which I'd be able to use less variables and objects (in other words, optimized)?

 

Or perhaps should I look at classes to modify the stage coordinates independently?

 

Thanks a lot!

Link to comment
Share on other sites

One idea off the top of my head is to use an onUpdate and the modulus operator like:

 

TweenLite.to(mario, 1, {x:"2000", onUpdate:wrapX, onUpdateParams:[mario]});
function wrapX(mc:DisplayObject):void {
   var totalWidth:Number = mc.stage.stageWidth + mc.width;
   mc.x = ((mc.x + mc.width) % totalWidth) - mc.width;
}

This assumes that the registration point of your "mario" clip is in the upper left corner, but if it's not you can adjust the code easily. And it would allow him to move completely off the stage before entering on the other side, but if you want him to be able to start entering the stage on the other side AS he is moving off (so half his body is on one side and half on the other), you'd need to do some fancy footwork with either creating a BitmapData dynamically or duplicating the clip and juggle the position of the two (a bit more complex, but certainly doable).

 

You could also create a getter/setter in a custom class which you'd tween and that setter would have special logic in it to make the adjustments when the property exceeds a certain amount (the width of the stage).

 

Hope that helps.

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.
×
×
  • Create New...