Skip to content
Snippets Groups Projects
Commit ae503abb authored by Villard PierreFrederic's avatar Villard PierreFrederic
Browse files

Add background scrolling

parent ebb4f677
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,9 @@ public class Afficheur extends JPanel { ...@@ -29,7 +29,9 @@ public class Afficheur extends JPanel {
Monde m; Monde m;
//l'afficheur de Decor //l'afficheur de Decor
public DecorFixe decor=new DecorFixe(); //public DecorFixe decor=new DecorFixe();
public DecorVariable decor=new DecorVariable();
//double buffering //double buffering
BufferStrategy bs; BufferStrategy bs;
...@@ -75,7 +77,8 @@ public class Afficheur extends JPanel { ...@@ -75,7 +77,8 @@ public class Afficheur extends JPanel {
g.setColor(Color.black); g.setColor(Color.black);
//affiche le décor //affiche le décor
decor.affiche( g); //decor.affiche( g);
decor.affiche((int)m.balle.px, g);
// affiche les objets // affiche les objets
for (Objet obj : m.objets) { for (Objet obj : m.objets) {
......
package afficheur;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import javax.imageio.ImageIO;
//distributeur de sprites
public class DecorVariable {
//IMage
BufferedImage im;
//taille
int wx,wy;
//construit le sprite
public DecorVariable()
{
try {
im=ImageIO.read(new File("background.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("erreur lecture background");
}
wx=im.getWidth();
wy=im.getHeight();
}
public void changeImage(String image)
{
try {
im=ImageIO.read(new File(image));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("erreur lecture background");
}
wx=im.getWidth();
wy=im.getHeight();
}
//afficheur de decor
//declae en x seulement
public void affiche(int x,Graphics g)
{
//on se ramene au repere du plan
x=(x%wx);
//on affiche sur l'ecran 0 ==> wx-x image source de x � wx
g.drawImage(im, 0 ,0 , wx-x, wy, x, 0, wx, wy,null);
//on affiche sur l'ecran wx-x ==> wx image source de 0 � x
g.drawImage(im, wx-x ,0 , wx, wy, 0, 0, x, wy,null);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment