The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.36 / 5.00 33,851 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.09 / 5.00 12,195 ViewsHey everyone. I am having some trouble with moving the _root._x (or the screen) in my game.
I have a long mc of the whole level in the background, and obviusoly only a part of it is visible at any time.
What i need, is when the character you control gets near the edge of the screen (both left and right) the screen smoothly moves so the character is in the middle of the screen again. (i require the same thing for up/down, but i think i'd be able to do that myself once i get the idea for scrooling left/right)
So far i've been unable to acomplish that since i was using stuff like:
if (_root.hero._x > (_root._x+700)) { //700 is the with of the screen
_root._x += _root.faceless._x; // here i tried variuos stuff to add
}
The point being i am doing this by trial and error, and so far i dont get the result i need, the screen either moves in the wrong direction, doesn't move at all, or doesnt stop moving up to infinity ;P
So i would really appreciate if someone would help me achieve this screen scrooling i desribed, and for the record, i already checked AS:Main, but i wasnt able to find what i need, or i didn't look close enough.
I aprreciate both tips and code, and i never just copy/paste, so i'll be happy to see any help, and learn from it.
Thanks in advance :)
THE CAKE IS A LIE
ah sorry i left one error in the example code ;P
the instance name of mc i have is "faceless" but i wanted to change it to "hero" for clarity. So the code's problem isn't really the different names it's just a typo i left ;P
THE CAKE IS A LIE
The problem is that the player's position is relative to the anchor point of '_root', so moving it doesn't change the player's position. So you need to reposiotion it by the diffirence between the player coordinate and its contraint.
Also don't use '_root' for such scrolling. You end up having to move lots of stuff backwards.
is faceless (or hero, whatever) in the _root, or did you change the code a bit for clarity? If faceless is inside another movieclip, you have to use a .localToGlobal alteration to the x,y coordinates. Judging by the results you posted about what was happening, this would be my guess at the problem.
To convert the coordinates, just put this in your code (depending on the code's location, etc.):
point = new Object ();
point.x = hero._x;
point.y = hero._y;
this.localToGlobal (point);
_root._x += point.x;
_root._y += point.y;
*** Please note that "point" uses the .x and .y attributes, NOT ._x and ._y (I made this mistake when I first tried it).
There's also a .globalToLocal (Object) function for going in the other direction. I believe you need to specify a movieclip for the localToGlobal, and *usually* you use the parent clip (I believe). Thus, I'm not sure of the "this.localToGlobal (point);" part would work correctly. You'd might have to substitute "this" for the parent clip (which, if hero is inside another clip, would be where the problem lies).
If this isn't the situation or the problem, I'm sorry for wasting your time (or regurgitating information you already knew).
At 11/1/07 10:27 AM, GustTheASGuy wrote: Also don't use '_root' for such scrolling. You end up having to move lots of stuff backwards.
Agreed. You're best sticking everything you want to move in a big clip, lest you want to have to move all of your UI every time something moves.
At 11/1/07 10:36 AM, Agnate wrote: is faceless (or hero, whatever) in the _root, or did you change the code a bit for clarity? If faceless is inside another movieclip, you have to use a .localToGlobal alteration to the x,y coordinates. Judging by the results you posted about what was happening, this would be my guess at the problem.
If this isn't the situation or the problem, I'm sorry for wasting your time (or regurgitating information you already knew).
Well, the hero movieclip that the player controls is not inside another mc, it is in root. So i, however should be sorry here, for not providing a good enough description of the situation. ;)
But information you provided is new to me, as i was not aware that movieclips inside other movieclip could require the use of "localToGlobal" to properly interact with. I did not consider using object either, so maybe that will prove usefull in the future as well.
At 11/1/07 11:23 AM, Paranoia wrote:At 11/1/07 10:27 AM, GustTheASGuy wrote: Also don't use '_root' for such scrolling. You end up having to move lots of stuff backwards.Agreed. You're best sticking everything you want to move in a big clip, lest you want to have to move all of your UI every time something moves.
Yes, i was aware of the problem of moving UI backwards. So, if i try the Big Movieclip trick, are there any limitations that arise from that? Or do i just use "_root.BigMc.[something]" instead of "_root.[something]" when i want to interact with stuff inside it, and that's it? And i still can use variables and functions in the actions of the main frame, or am i better of with defining everything in the big mc?
THE CAKE IS A LIE