简体   繁体   English

Java平铺油漆

[英]Java tiled paint

I'm writing a game, and I want an area of the screen to have a tiled paint drawn on it. 我正在写一个游戏,我希望屏幕区域上有一个平铺的油漆。 Using a TexturePaint java supports texturing a Shape with a tiled texture, this is really simple and performs pretty well. 使用TexturePaint java支持使用平铺纹理对Shape进行纹理化,这非常简单并且执行得非常好。 However, I want my tiled texture to be rotated before drawing it as a fill to the shape - this is theoretically possible by subclassing TexturePaint and applying a transform, However, this performs really badly. 但是,我希望我的平铺纹理在将其绘制为形状填充之前进行旋转 - 这在理论上可以通过继承TexturePaint并应用变换来实现,但是,这非常糟糕。

Does java in some way support doing this? java在某种程度上支持这样做吗? If not, is there any reasn that subclassing texturePaint might perform really badly? 如果没有,那么子类化texturePaint可能执行得非常糟糕吗?

Your best off just simply rotating the BufferedImage before throwing it at TexturePaint. 您最好只需旋转BufferedImage,然后再将其投放到TexturePaint。

AffineTransform texture = new AffineTransform();
texture.rotate(radians, bufferedImage.getWidth()/2, bufferedImage.getHeight()/2);

AffineTransformOp op = new AffineTransformOp(texture, AffineTransformOp.TYPE_BILINEAR);
bufferedImage = op.filter(bufferedImage, null);

You should be able to subclass TexturePaint without recieving a preformance drop, I can only assume that your rotation code is causing the drop. 您应该能够在不接收性能下降的情况下继承TexturePaint,我只能假设您的旋转代码导致丢弃。

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM