J'utilise Java pour créer un jeu et j'utilise TexturePaint pour texturer des zones en arrière-plan. La performance est bien à l'aide java.awt.TexturePaint, cependant, je veux avoir des zones ayant une rotation inhérente, donc j'ai essayé la mise en œuvre d'une peinture appelée OrientedTexturePaint personnalisée:Problème de performance d'implémentation de Paint personnalisé Java
public class OrientableTexturePaint implements Paint {
private TexturePaint texture;
private float orientation;
public OrientableTexturePaint(TexturePaint paint, float orientation)
{
texture = paint;
this.orientation = HelperMethods.clampRadians((float)Math.toRadians(orientation));
}
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
{
AffineTransform newTransform = (AffineTransform)xform.clone();
newTransform.rotate(orientation);
return texture.createContext(cm, deviceBounds, userBounds, newTransform, hints);
}
public int getTransparency()
{
return texture.getTransparency();
}
}
Le seul problème est, il y a une performance énorme succès: le taux de trame tombe d'un confortable (plafonné) 60fps à environ 3fps. De plus, si j'implémente ceci comme un wrapper pur à TexturePaint - sans créer la nouvelle transformation, en passant simplement les arguments aux méthodes de TexturePaint et en retournant ce que TexturePaint renvoie, j'obtiens le même résultat.
i.e. .:
public class MyTexturePaint implements Paint {
private TexturePaint texture;
public OrientableTexturePaint(TexturePaint paint, float orientation)
{
texture = paint;
}
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
{
return texture.createContext(cm, deviceBounds, userBounds, xform, hints);
}
public int getTransparency()
{
return texture.getTransparency();
}
}
massivement pire que réalise TexturePaint ne. Comment se fait-il, et y a-t-il un moyen de contourner cela?