开发者

Java game looks like it runs slow?

开发者 https://www.devze.com 2023-04-11 14:25 出处:网络
I\'m making a game which involves multiple \"balls\" using the same class, I have everything working the way I want it to using a ArrayList but my problem is that the more of the balls I add the slowe

I'm making a game which involves multiple "balls" using the same class, I have everything working the way I want it to using a ArrayList but my problem is that the more of the balls I add the slower it renders them. This makes the game look like it is going slow and it will flicker, I can't provide a video sorry, but I can provide the code I am using the draw the balls:

code:

for(int i=0;i<balls.size(); i++){
    Ball tmp = (Ball) balls.get(i);开发者_开发技巧
    g2d.drawImage(tmp.getImage(), tmp.getX(),tmp.getY(),null);
}   

Could you give me examples or direction for a better way to render the balls?

Thanks.


For the flickering, you'll want to learn about double buffering. If the slowness is something aside from perception due to not double buffering, you'll have to profile it or maybe show some more code.


I'm not sure of the speed ramifications (probably not much), but you should be specifying a type when using an ArrayList (i.e ArrayList<Ball>) instead of typecasting everything as you get it.

0

精彩评论

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

关注公众号