A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: x,y change giant canvas coord

  1. #1
    is not a good designer. No-Tec's Avatar
    Join Date
    Aug 2002
    Posts
    1,349

    x,y change giant canvas coord

    I'm looking for a site. well, particularly an .fla to go over. of a site that is kind of a giant canvas. but you only see a portion of it at any given time. and depending on which edge of the site you move your mouse too [top, left, etc] it scrolls over to show you a different portion of the giant canvas, sort of in an accelerated manner.

    somewhat hard to explain but I think I got it.
    Ive written enough to go left or right. or up and down. but not diagonal or smoothly any other way. any help is muich appreciated.
    maybe.

  2. #2
    Sounds like you want to find the change in mouse position relative to center first.

    Example:

    Code:
    // If mouse is outside of imaginary 'zero speed' box in middle:
    // This assumes you have your canvas image centered at (0,0)
    if ( Math.abs(canvas._xmouse) > 10) {
     speedX = canvas._xmouse * 1.2; // This is where the acceleration is
    } else {
     speedX = 0;
    }
    if ( Math.abs(canvas._ymouse) > 10) {
     speedY = canvas._ymouse * 1.2; // This is where the acceleration is
    } else {
     speedY = 0;
    }
    
    canvas._x += speedX;
    canvas._y += speedY;
    A quick guess would say that this should be smooth.

    Hope this helps, Phil
    - Phil Harnish of Ampre Industries

  3. #3
    is not a good designer. No-Tec's Avatar
    Join Date
    Aug 2002
    Posts
    1,349
    oh sweet, thanks man, but how would I go about setting up a perameter square around that? So when the 0,0 of the canvas reaches the 0,0 of the stage, the scrolling stops?
    maybe.

  4. #4
    Oops, I made a mental note to put something in for that, lets see.
    Looking at it again, it looks like the scrolling would be hard to control at the edges so let me try again

    Code:
    // If mouse is outside of imaginary 'zero speed' box in middle:
    // This assumes you have your canvas image centered at (0,0) on stage
    deltaX = (Stage.width - _root._xmouse)/2;
    deltaY = (Stage.height - _root._ymouse)/2;
    // Ok, here we make sure we are neither inside the imaginary
    //  zero-speed box OR at the edge of the picture..
    // Edge Check: find distance to edge of canvas, subtract absolute
    //  mouse position (relative to canvas) to get the distance away
    //  from edge. Make sure it is not negitive (crossed over the edge)
    if ( Math.abs(deltaX) > 10 && ((canvas._width/2) - Math.abs(canvas._xmouse)) < 0 ) {
     speedX = deltaX * 1.2; // This is where the acceleration is
    } else {
     speedX = 0;
    }
    
    if ( Math.abs(deltaY) > 10 && ((canvas._height/2) - Math.abs(canvas._ymouse)) < 0 )) {
     speedY = deltaY * 1.2; // This is where the acceleration is
    } else {
     speedY = 0;
    }
    
    canvas._x += speedX;
    canvas._y += speedY;
    Hrm, Okay, that should work. I wish I could test it but I am at school.
    - Phil Harnish of Ampre Industries

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