本文主要是介绍小游戏桌游制作,双缓存,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import java.awt.*;
import javax.swing.*;
public class BallGame extends JFrame{
Image ball=Toolkit.getDefaultToolkit().getImage(“images/ball.png”);
Image desk=Toolkit.getDefaultToolkit().getImage(“images/desk.jpg”);
double x=100;
double y=100;
boolean right=true;
private Image OffScreenImage=null;
public void paint(Graphics g){
if(OffScreenImage==null){
OffScreenImage=this.createImage(856,500);
}
Graphics goff=OffScreenImage.getGraphics();
goff.drawImage(desk,0,0,null);goff.drawImage(ball,(int)x,(int)y,null);if(right){x=x+10;}else{x=x-10;}if(x>856-40-30){right=false;}if(x<40){right=true;}g.drawImage(OffScreenImage,0,0, null);
}void launchFrame(){ setSize(856,500);setLocation(50,50);setVisible(true);while(true){repaint();try {Thread.sleep(40);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}public static void main(String[] args ){System.out.println("JOJO的桌游");BallGame game=new BallGame();game.launchFrame();}
}
这篇关于小游戏桌游制作,双缓存的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!