//Worldの設定(再設定可) public final void setWorld(World world) { if(this.world==world)return; if(this.world!=null){ this.world.stop(); this.world.destroy(); } this.world=world; if(this.world!=null)this.world.init(); } //Worldの取得 public final World getWorld() { return world; } public final void start() { super.start(); world.start(); } public final void stop() { world.stop(); super.stop(); } public final void destroy() { setWorld(null); super.destroy(); }
/*-------------------------------------------------------------- * (2)ダブルバッファリング * 画面のちらつき防止の為に * 裏面に画像を完成してからいっきに表示面にコピーする技法を使う -----------------------------------------------------------------*/ private Image bufferImage=null;//裏画面 private Graphics bufferImageGraphics=null;//裏画面用の絵筆 public final void update(Graphics g) { //裏画面が無かったり、表画面と大きさが異なる場合は裏画面を作り直す int w=getWidth();//表画面の幅 int h=getHeight();//表画面の高さ if(bufferImage==null || w!=bufferImage.getWidth(this) || h!=bufferImage.getHeight(this)){ bufferImage=createImage(w,h); bufferImageGraphics=bufferImage.getGraphics(); }
//裏画面を背景色で塗りつぶす Color back=getBackground(); if(back!=null){ //背景色が指定されていれば bufferImageGraphics.setColor(getBackground());//絵筆の色を背景色にし bufferImageGraphics.fillRect(0,0,w,h);//塗りつぶす } bufferImageGraphics.setColor(getForeground());//絵筆の色を規定値に戻す