开发者

Java - Paint vs Image for performance?

开发者 https://www.devze.com 2023-02-18 05:36 出处:网络
Lets say I have to draw a truck on a game I am making. Which would be better performance wise? Drawing the truck开发者_StackOverflow社区 with lines and filling and color changes

Lets say I have to draw a truck on a game I am making. Which would be better performance wise?

  • Drawing the truck开发者_StackOverflow社区 with lines and filling and color changes
  • Finding an image/making an image of the truck and drawing it on the game and moving the image around.

Thanks for any input


I suspect that the image would be easier to code.

You'd have to test your two examples to see, but I'd be surprised if there was a measurable difference. All of the pixels on the screen have to be redrawn, no matter which method you choose.


The image would be faster, as all it has to do is copy the pixels over to the buffer, and display them.

Painting the truck would provide greater flexibility over what you can do with it. Ultimately, there will be VERY LITTLE difference, especially if all you're drawing is a few shapes.

I've made something similar a few months ago, basically a bomber man game in java. It was so much easier to just use Java's built in Image class. There game was very smooth and lag free, despite loading a few hundred pictures, and displaying ~40 or so at once (and repainting them, including gis)


I'll bet the performance will be more or less the same, unless the filling algorithm is slow.

0

精彩评论

暂无评论...
验证码 换一张
取 消