A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Scrolling system.

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    7

    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;}}

  2. #2
    Junior Member
    Join Date
    Mar 2006
    Location
    New York
    Posts
    10
    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);

  3. #3
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    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:

  4. #4
    Junior Member
    Join Date
    Mar 2006
    Location
    New York
    Posts
    10
    bluemagicia..you're right...should read code more carefully

  5. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    7
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center