c# - Most effective way to redraw image -


i'm making simple 2d game. unfortunately ran issue refresh rate when add images. use invalidate on timer tick works fine until change drawrectangle drawimage. 27 objects on screen paint refresh rate drops stable 64 39 on average. images use 2-3kb shouldn't cause issue. please me understand this. why , how happen? causes , issues , how fix it?

perfectly fine:

foreach (ground _en in game.blocks) {     e.graphics.fillrectangle(brushes.green,_en.rec); } 

causes frame drop:

foreach (ground _en in game.blocks) {     e.graphics.drawimage(image.fromfile(_en.background), _en.rec); } 

you're loading file memory hard disk each time call .fromfile(). store image in ground class on instantiation (or whenever, not when calling in draw()) , should fixed.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -