Rotation d'une image sur une autre image de fond
Bonsoir,
J’essaie de faire un jeu en java. Il y a une image en fond d'écran, une image de tonneau sur laquelle j'applique une rotation, un tonneau qui ne tourne pas, et un personnage.
Mes problèmes sont les suivants:
La rotation de l'image n'est pas parfaite, l'image subit un étirement puis un écrasement, et une trace reste au fil de la rotation. Comment faire une bonne rotation, et sans la rémanence des images précédentes.
J'ai repris le code de ce poste:
http://www.developpez.net/forums/d17...tation-dimage/
Le bug suivant dépends surement du dernier, mais quand j'ajoute les deux autres images sur mon frame, ce sont plus les bonnes images qui sont affichées... Au lieu du tonneau j'ai le coin du background.
Mes image sont au format gif avec transparence.
Voici mes bouts de code:
Code qui se trouve dans chaque objet qui est paint
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
public void rotate(double scale)
{
AffineTransform transform = new AffineTransform();
transform.rotate(scale, originalImage.getWidth()/2, originalImage.getHeight()/2);
AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC);
image = op.filter(originalImage, null);
//Don't work at all
//this.setBounds(x,y, image.getWidth()/2, image.getHeight()/2);
this.width = image.getWidth()/2;
this.height = image.getHeight()/2;
this.repaint();
}
public void paint(Graphics g){
g.drawImage(this.image,this.x,this.y, this.width, this.height, this);
} |
Code qui se trouve dans le gui
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
public GameGui(Integer width, Integer height, LevelBackground levelBackground,
Monkey player, Barrel source, Barrel dest)
{
this.levelBackground = levelBackground;
this.player = player;
this.source = source;
this.dest = dest;
this.setSize(width, height);
this.setVisible(true);
this.setLocationRelativeTo(null); //Center window on screen
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add components to the frame
add(levelBackground);
add(source);
add(dest);
add(player);
//Set objects positions with their absolutes coordinates
levelBackground.setBounds();
source.setBounds();
dest.setBounds();
player.setBounds();
//Test annimation
try {
for(double i = 0; i < 3.14*8; i+= 0.2)
{
dest.rotate(i);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void paint (Graphics g) {
super.paintComponents(g);
//Paint the background
levelBackground.paint(g);
//Paint the turning barrel
dest.paint(g);
//Paint others
source.paint(g);
player.paint(g);
} |
J'aurais besoin d'une méthode fiable et efficace pour faire la rotation de l'image du tonneaux, sans qu'elle se déforme.
Merci immensément pour votre aide
Dominique