• Using an image as background

    To show an image we need a window, an image and a loop.
    The Window is necessary to show in every update by the user or by the programmer on the screen related to the images.
    The loop is the core of the game, all the iterations and updates of the screen are made during the loop.

    To show the updates that were made, we use the following method:

    public void display();

    ps.: The method void update() must be called at the end of a list of objects that should be drawn on the screen. This is necessary because the method will present on the screen all the updates that were made during the loop. As an example we have the position updates.

    Example:

    
    						package GameImage001;
    
    
    	
    					import JPlay.GameImage;
    
    						import JPlay.Window;
    
    
    	
    					/**
    	 
    					* @author Gefersom Cardoso Lima
    	 
    					* Federal Fluminense University - UFF - Brazil
    	 
    					* Computer Science
    	 
    					*/
    	
    	 
    
    					public class GameImage001
    	
    					{
    	
    						public static void main(String[] args)
    
    							{
    	
    							Window w = new Window(800,600);
    
    	
    
    							while(true)
    	
    							{
    
    										command1;
    	
    									command2;
    	
    									command3;
    	
    									command4;
    	
    										//This command must be run at last.
    
    										w.display();
    
    								}
    
    							}
    
    						}
    
    	
    				


    To create a background image we use the GameImage class.

    The constructor is the following one:

    public GameImage(String nameFile);

    To the example bellow, we use the image "fundo.png", which is located in the same folder of the project.

    ps.: The extension is needed.

    Java accept the following image extensions: png, jpeg and gif.


    To draw images on the screen we use the method:

    public void draw();

    This method is used by all the other objects that needs to draw something on the screen.


    Example: Shows an image as background.

    					package GameImage001;
    
    					import JPlay.GameImage;
    					import JPlay.Window;
    
    					/** 
    					* @author Gefersom Cardoso Lima 
    					* Federal Fluminense University - UFF - Brazil 
    					* Computer Science 
    					*/ 
    
    					public class GameImage001
    					{
    						//Shows a picture as background.
    						public static void main(String[] args)
    						{
    							Window w = new Window(800,600);
    							GameImage backGround = new GameImage("fundo.png");
    
    							while(true)
    							{
    									backGround.draw();
    
    									//This command must be run at last.
    									w.display();
    							}
    						}
    					}
    					
    				


    UFF - Universidade Federal Fluminense - Institudo de Computação - Ciência da Computação