hey all can u help me on how to constrict the movement of a movieclip to move around but not out side of the screen size given… as i it wont allow it to go off the screen…
cheers and thanx
hey all can u help me on how to constrict the movement of a movieclip to move around but not out side of the screen size given… as i it wont allow it to go off the screen…
cheers and thanx
Are you talking about a movie clip that you drag with a mouse, or one that movies via actionscript?
no no i’m like using keys to movie the object around the scene, and i like dont want it to be able to go outside ( out of side) off the screen… so yeah can u help me?? i’m currently use the 4 arrow keys so yeah =)
What is the code that you’re using to move the object?
i used the simple and basic code :
onclipEvent ( keydown) {
if (key.isdown ( key.left ) ) {
_x-=10
}
}
onclipEvent ( keydown) {
if (key.isdown ( key.right ) ) {
_x+=10
}
}
etc for the other keys…
can u help me?
ok… there are two ways… but I’ll explain the more simple of the two.
What I do in this case is, on loading the clip, I set some variables. You can chage them to encapsulate the size of your stage, or a little smaller if you don’t want it to go all the way to the edge.
onClipEvent(load){
topSide=0;
bottomSide=400;
rightSide=400;
leftSide=0;
}
now in the key press event, you add “&&” which means, if this is true, AND this is true. _x>leftSide, just says, if this location is less than 0 (which is what we set the left side equal to.
onclipEvent ( keydown) {
if (key.isdown ( key.left )&&_x>leftSide) {
_x-=10
}
}
onclipEvent ( keydown) {
if (key.isdown ( key.right )&&_x<rightSide) {
_x+=10
}
}
This way if the key is pressed, the first condition is true. If it’s current location is within the parameter we set, then the second condition is also true. As long as both are true, the keypress will work, as soon as either of the conditions is not true, the object will stop.
hey hey thanx for the help i mean THANKs hehe upuaut8 i’m pretty new to this but yeah… n e ways i’ll be back for more hehe
cheers and thanks again
i have restained it already but i have another clip as well which follows the clip 1 only in the _y axis … and when the movement stops cuz its reached the limit, the clip 2 still is moving up can u help me? here is the code i used for the clip2
onClipEvent (keyDown) {
if (key.isdown(key.down)) {
_y -= (_root.movie_clip1._y-_y)/130;
}
}
onClipEvent (keyDown) {
if (key.isdown(key.up)) {
_y += (_root.movie_clip1._y-_y)/130;
}
}
can u helpp me? or explain a method and let me try it out?
if the second movie clip is following the first (you seem to have a good little script here for that btw) shouldn’t limiting the first movie clips movement also limit the second?
If so… on the first clip I had kind of figured that you would add this
onclipEvent ( keydown) {
if (key.isdown ( key.up )&&_y>topSide) {
_y-=10
}
}
onclipEvent ( keydown) {
if (key.isdown ( key.down )&&_y<bottomSide) {
_y+=10
}
}
maybe I’m not understanding you quite correctly.
no it dont seem to work… i fink its becuz of the function “key.down” i fink its becuz the key is till down and the movieclip2 is stilll moving becuz of that i donno what to add to my code for clip2 to make it stop move when clip1 stops movin !! i fink that might help u think of a solution other tahn that i’m lsot hehe thanx again
here are my code for the whole thing
clip1
onClipEvent (load) {
topside = “0”;
bottomside = “400”;
rightside = “700”;
leftside = “0”;
}
onClipEvent (keyDown) {
if (key.isdown(key.left)&&_x>leftside) {
_x-=10;
}
}
onClipEvent (keyDown) {
if (key.isdown(key.right)&&_x<rightside) {
_x+=10;
}
}
onClipEvent (keyDown) {
if (key.isdown(key.down)&&_y<bottomside) {
_y+=10;
}
}
onClipEvent (keyDown) {
if (key.isdown(key.up)&&_y>topside) {
_y-=10;
}
}
Clip2
onClipEvent (keyDown) {
if (key.isdown(key.down)) {
_y -= (_root.movie_clip1._y-_y)/130;
}
}
onClipEvent (keyDown) {
if (key.isdown(key.up)) {
_y += (_root.movie_clip1._y-_y)/130;
}
}
so yeah hoep u can help
onClipEvent (keyDown) {
if (key.isdown(key.left)&&_x>leftside) {
_x-=10;
}
when this is false it doesnt move the object only but the key is still down, i’m good at problem solving but i’m new to flash so yeah need to learn it abit more hehe…
so yeah if key is down and both condition are true then it moves clip1 right? to wot ever the _x value is…
onClipEvent (keyDown) {
if (key.isdown(key.down)) {
_y -= (_root.movie_clip1._y-_y)/130;
}
}
this one is also activated when the key button is down… but yeah i donno wots wrong … i knoe wot u mean by wot u siad but i’m quite lost as well
well… if the second movie clip is just following the first, you don’t need the key down method. I missed that cause I was tired. The second movie clip can just have this.
onClipEvent (enterFrame) {
diff=_y-_root.movie_clip1._y;
_y+=diff;
}
you might need to reverse that if it doesn’t work to look like this…
onClipEvent (enterFrame) {
diff=_root.movie_clip1._y-_y;
_y+=diff;
}
I don’t remember which you subtract from which…
:: Copyright KIRUPA 2024 //--