performance - Character walks slow in my C# game -
performance - Character walks slow in my C# game -
the issue i can't figure out why character moves slow when draw image. timers set 1 interval , never changed. help appreciated. here entire project:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace rice_boy_tester_2 { public partial class form1 : form { bool iggy = false; bool left2 = false; bool right2 = false; bool up2 = false; bool down2 = false; bool check2 = false; bool left = false; bool right = false; bool = false; bool downwards = false; bool check = false; public form1() { initializecomponent(); } private void form1_load(object sender, eventargs e) { // empty block } private void refresh_tick(object sender, eventargs e) { this.refresh(); } private void priceboywalk_tick(object sender, eventargs e) { if (left) // goes left player.left -= 1; if (player.left < 170 & check == false) { // checks how far away player form left = false; = true; } if (up & player.left < 170) { // goes player.top -= 1; check = true; } if (player.top < 100 & check) { = false; downwards = true; } if (right) // goes right player.left += 1; if (down) // goes downwards player.top += 1; if (player.top + 150 > this.clientsize.height) { check = false; downwards = false; right = true; } if (player.left + 150 > this.clientsize.width) right = false; } private void b1_click(object sender, eventargs e) { this.paint += new painteventhandler(form1_pad1_rice); riceboywalkgif.enabled = true; left = true; left2 = true; riceboywalk.enabled = true; } private void timer1_tick(object sender, eventargs e) { if (left2) { player.image = image.fromfile("rice-boy-walking-left-bouncing.gif"); // animates riceboywalkingleft left2 = false; } if (player.left < 170 & check2 == false) { // checks how far away player form left2 = false; up2 = true; } if (up2 & player.left < 170) { // goes this.player.size = new system.drawing.size(36, 76); // changes size of image box maintain quality player.image = image.fromfile("rice-boy-walking-up-bouncing.gif"); // animates riceboywalkingup check2 = true; up2 = false; } if (player.top < 101 & check2) { // player.top < 101 must +1 greater riceboywalktimer up2 = false; down2 = true; } if (right2) { this.player.size = new system.drawing.size(53, 77); // changes size of image box maintain quality player.image = image.fromfile("rice-boy-walking-right-bouncing.gif"); // animates riceboywalkingright right2 = false; } if (down2) { // goes downwards player.image = image.fromfile("rice-boy-walking-down.gif"); down2 = false; } if (player.top + 150 > this.clientsize.height) { iggy = true; // shows riceboy approaching starting point check2 = false; down2 = false; right2 = true; } if (player.left + 150 > this.clientsize.width & iggy) { right2 = false; player.image = properties.resources.rice_boy_standing_left; } } private void form1_pad1_rice(object sender, system.windows.forms.painteventargs e) { e.graphics.drawimage(properties.resources.corn_cobs, 120, 58, 50, 50); // draws corn cobs character goes slower when corn drawing // (x(-left), y(-up), w, h) }
start this:
player.image = image.fromfile("rice-boy-walking-down.gif");
(and other load routines).
on every tick? seriously?
load them 1 time during initialization, store them in variables, reuse images. ever played computer game? not trashing disc trying load graphics asset every frame.
disc access slow. image decoding slow. , uncertainty alter images while programme runs.
c# performance draw
Comments
Post a Comment