jdkdoen05 wrote...
Can we make a limit for the world? The school pc are trash and the performence isnt very well!import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * CLASS:OpenScrollWorld * * @author (your name) * @version (a version number or a date) */ public class OpenScrollWorld extends Levels { public static final int WIDE=1000; public static final int HIGH=866; Scroller scroller; Actor scrollActor; HealthBar healthbar = new HealthBar(); Health_Text health_text = new Health_Text(); static GreenfootSound music = new GreenfootSound("GameMusic.wav"); /** * Constructor for objects of class ActorScrollWorld. * */ public OpenScrollWorld() { GreenfootImage image=new GreenfootImage("Clowd.png"); scroller=new Scroller(this,image); scroller.scroll(0,0); prepare(); } public void act() { if(scrollActor!=null) { scroll(); } else { keyScroll(); } music.play(); } private void keyScroll() { int dsx=0,dsy=0; if(Greenfoot.isKeyDown("right")) { dsx++; } if(Greenfoot.isKeyDown("left")) { dsx--; } if(Greenfoot.isKeyDown("down")) { dsy++; } if(Greenfoot.isKeyDown("up")) { dsy--; } int rate=15; scroller.scroll(dsx*rate,dsy*rate); } private void scroll() { int loX=200; int hiX=WIDE-200; int loY=200; int hiY=HIGH-200; int dsx=0; int 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; } int rate=15; int signX=(int)Math.signum(dsx),signY=(int)Math.signum(dsy); dsx=signX*Math.min(Math.abs(dsx),rate); dsy=signY*Math.min(Math.abs(dsy),rate); scroller.scroll(dsx,dsy); } }
int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); scroller=new Scroller(this,image,imageWidth,imageHeight);
scroller=new Scroller(this,image,2000,600);