I have a block that i’m trying to make move from right to left, and if the block gets to a certain point, it will move back to it’s original position.
So, i have this on my block (movieclip) rightnow
I once wrote a [color=Magenta]prototype [/color]that I use for moving stuff around. Maybe this is a little more than you need, but you can sort out the things you want to use. About your code above, I think you should define speed and dist ONCE, not on every frame. And, don’t forget the difference between = and ==. Ask me if you have any questions.
////////////////////////////////////////////////////////////////////////////////////////////////////
MovieClip.prototype.Animate = function(steps,newX,newY) {
this.onEnterFrame = function() {
difX = Math.round(newX-this._x);
difY = Math.round(newY-this._y);
if ( difX != 0 or difY != 0) {
this._x += difX/steps;
this._y += difY/steps;
} else {
delete this.onEnterFrame;
// This will happen when animation is complete
this.Animate(3,200,0);
}
}
}
my_mc.Animate(3,15,60); // steps,newX, newY
Hm, your way is a little complex for me…as i am just beginnning to work with AS…Does my way not work at all after a little tweaking? Or should i just tough it out and read through some tutorials regarding your method?
the value of dist is assigned to _x, not compared, use "=="instead:)
I’ve used “<=” cause _x probably never gets equal to “dist” (depends on your setup)
Hi, I’m trying to do something along the same lines as johnnyFlash… I have an image that I’m trying to get to scroll up until it gets to a certain point, then I want it to stop. How do I do this? I’m using:
Hi, I’m trying to do something along the same lines as johnnyFlash… I have an image that I’m trying to get to scroll up until it gets to a certain point, then I want it to stop. How do I do this? I’m using:
Actually that’s a scroll down, but whatever! Remember that the _y is “upside down” in flash, thus the higher you are, the less is _y. The more down you go, the greater is _y.
So, ulysnep, if you want your movieclip to scroll UP, you’re gonna have to use negative speed ( or this._y-= speed instead of += ) and you’ll also have to make sure that your if conditionnal is appropriate, something along the lines of:
if(this._y> stopPosition){
this._y-=speed;
//OR, if speed is a negative variable:
this._y+=speed;
}
Hi again, this is working fine and i understand it a lot better (especially i learned about the whole <= ) But, what i kind of wanted to do was send the block back to it’s original point by moving, not just jumping right over there. So i was thinking something like this may give you an idea of what i’m talking about.