zier(.22,1,.36,1) .35s backwards}@media(prefers-reduced-motion:reduce){::view-transition-group(*),::view-transition-new(*),::view-transition-old(*){animation:none!important}}body,html{background:transparent;border:0;margin:0;outline:0;padding:0;vertical-align:baseline}body{--scrollbar-width:0px;font-family:Arial,Helvetica,sans-serif;font-size:10px}body,html{height:100%}body{overflow-x:auto;overflow-y:scroll}body:not(.responsive) #site-root{min-width:var(--site-width);width:100%}body:not([data-js-loaded]) [data-hide-prejs]{visibility:hidden}wix-interact-element{display:contents}#SITE_CONTAINER{position:relative}:root{--one-unit:1vw;--section-max-width:9999px;--spx-stopper-max:9999px;--spx-stopper-min:0px}@supports(-webkit-appearance:none) and (stroke-color:transparent){:root{--safari-sticky-fix:opacity}}@supports(container-type:inline-size){:root{--one-unit:1cqw}}[id^=oldHoverBox-]{mix-blend-mode:plus-lighter;transition:opacity .5s ease,visibility .5s ease}[data-mesh-id$=inlineContent-gridContainer]:has(>[id^=oldHoverBox-]){isolation:isolate}
top of page

/**
 * CLASS: ImageScrollWorld
 *
 * DESCRIPTION: creates a limited center screen actor scrolling world
 */


import greenfoot.*;

 

public class ImageScrollWorld extends World
{
    public static final int WIDE = 800;
// world width (viewport)
    public static final int HIGH = 600; // world height (viewport)
   
    Scroller scroller;
// the object that performs the scrolling
   
Actor scrollActor; // an actor to stay in view
   
    public ImageScrollWorld()
    {
        super(WIDE, HIGH, 1, false);
// creates an unbounded world
        GreenfootImage bg = new GreenfootImage("bg.png"); // the limiting image
        int bgWide = bg.getWidth(); // scrolling image width
        int bgHigh = bg.getHeight(); // scrolling image height
        scroller = new Scroller(this, bg, bgWide, bgHigh); // the Scroller object
        scrollActor = new Player(); // creates the actor to maintain view on
        addObject(scrollActor, bgWide/2, bgHigh/2); // add actor to world (wherever)
        scroll(); // sets initial background image and scrolls if needed
    }
   
    public void act()
    {
        if (scrollActor != null) scroll();
    }
   
   
// attempts scrolling when actor is not in center of visible world
    private void scroll()
    {
       
// determine scrolling offsets and scroll
        int dsx = scrollActor.getX()-WIDE/2; // horizontal offset from center screen
        int dsy = scrollActor.getY()-HIGH/2; // vertical offset from center screen
        scroller.scroll(dsx, dsy);
    }
}

The following can be used to allow some actor movement before scrolling begins:

 

// attempts scrolling when actor is outside roaming limits
private void scroll()
{
   
// roaming limits of actor
    int loX = 100;
    int hiX = WIDE-100;
    int loY = 50;
    int hiY = HIGH-50;
   
// determine offsets and scroll
    int dsx = 0, dsy = 0;
    if (scrollActor.getX() < loX) dsx = scrollActor.getX()-loX;
    if (scrollActor.getX() > hiX) dsx = scrollActor.getX()-hiX;
    if (scrollActor.getY() < loY) dsy = scrollActor.getY()-loY;
    if (scrollActor.getY() > hiY) dsy = scrollActor.getY()-hiY;
    scroller.scroll(dsx, dsy);
}

ACTOR FOLLOW SCROLLING

bottom of page