-
Scrolling system.
Okay so I have this animation here. I have it so the _root will follow the player. There is no V-cam, and all the code is on the player movieclip. But what I need is for this to only happen when the player is in the middle of the stage, like in this game. Does anybody know how to do this?
Here is the code for my character mc.
Code:
onClipEvent (enterFrame) {
if (Key.isDown (Key.RIGHT)) {
_xscale = +100;
this._x += 5;
gotoAndStop (2);
} else {
if (Key.isDown (Key.LEFT)) {
_xscale = -100;
this._x -= 5;
gotoAndStop (2);
} else {
gotoAndStop (1);
}
}
_root._x = (this._x - Stage.width / 2) * -1;
_root._y = ((this._y - Stage.height /2) * -1+100);
if(_root.player.hitTest(_root.Lwall)){
this._x+=5;}}
-
well just add something like this._x > 100 as shown below...then you wlll only move right if you are at least 100 pixels from the side...same idea for going in the other directions
Actionscript Code:
if (Key.isDown (Key.RIGHT) && this._x > 100) { _xscale = +100; this._x += 5; gotoAndStop (2);
-
Senior Member
Yeh that's the idea, but I think he doesn't want to stop moving the character, rather stop the scrolling, when the character is too close to an edge.
@Moai: If that's the case, then you can simply use an if check....
Code:
var xpos = (this._x - Stage.width / 2) * -1;
if(xpos>=0)
{
_root._x=0;
}
else if(xpos<(Stage.width-_root.width))
{
_root._x = Stage.width - _root.width;
}
else
{
_root._x = xpos;
}
If you like me, add me to your friends list .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter:
-
bluemagicia..you're right...should read code more carefully
-
Sweet! Thanks guys, I'll try this code out here in a sec.
Edit: Thanks guys! It worked!
Edit 2: Okay, I thought it would have been easier to edit it for the other side of the map as well, but it isn't :O. If somebody could show me the code for the other one that would be great. I'm going to go mess around with it some more to see if I can get it myself
Last edited by Moai; 07-10-2010 at 11:40 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|