PDA

View Full Version : Seamingly easy movement ?



johnnyFlash
July 15th, 2004, 07:16 PM
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



onClipEvent(enterFrame) {
speed = 3
dist = 8.5
_x -= speed;
if (_x = dist) {
_x += 3
}
}


But all this is doing is throwing the block at the 8.5 distance...

any help???????? Thanx in advance

mattiaswargren
July 15th, 2004, 08:03 PM
I once wrote a prototype 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

mattiaswargren
July 15th, 2004, 08:07 PM
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/

johnnyFlash
July 15th, 2004, 08:07 PM
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?

THANKS a lot :)

scotty
July 16th, 2004, 02:55 AM
onClipEvent (load) {
speed = 3;
dist = 8.5;
origX = _x;
}
onClipEvent (enterFrame) {
_x -= speed;
if (_x <= dist) {
_x = origX;
}
}
In your code

if (_x = dist) {
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)

scotty(-:

ulysnep
July 16th, 2004, 04:19 AM
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:

onClipEvent(enterFrame) {
speed = 1;
this._y += speed;
}

Thanks

Michael Chen
July 16th, 2004, 04:23 AM
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:

onClipEvent(enterFrame) {
speed = 1;
this._y += speed;
}

Thanks


onClipEvent(enterFrame) {
if(certainPoint > this._y) {
speed = 1;
this._y += speed;
}
}

Hope that helps :)

cooleyo
July 16th, 2004, 01:31 PM
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;
}

johnnyFlash
July 16th, 2004, 11:09 PM
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.


onClipEvent (load) {
speed = 3;
dist = 8.5;
}
onClipEvent (enterFrame) {
_x -= speed;
if (_x <= dist) {
_x += 3;
}
}


I hope i can get some help :thumb:

scotty
July 17th, 2004, 03:31 AM
Like this?

onClipEvent (load) {
speed = 3;
dist = 8.5;
xMax = 400;
}
onClipEvent (enterFrame) {
_x -= speed;
if (_x<=dist) {
speed = -speed;
} else if (_x>=xMax) {
speed = -speed;
}
}

change xMax to the value you want:)

scotty(-: