c# - How would i create an array of images and then load each image into successive indexes -
c# - How would i create an array of images and then load each image into successive indexes -
as can see i've created array of images, i'm not sure how load each image successive indexes.
someone told me game i'm not sure how or if prepare problem i've made game character walks left so downwards right , few timers load animation , handle motion when draw using code
*e.graphics.drawimage(properties.resources.corn_cobs, 70, 70, 40, 40);*
my character gets laggy/slow when don't draw image works smoothly , character speeds normal.
here code:
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; image[] animations; public form1() { initializecomponent(); } private void form1_load(object sender, eventargs e) { animations = new image[6]; animations[0] = image.fromfile("rice-boy-walking-left-bouncing.gif"); animations[1] = image.fromfile("rice-boy-walking-up-bouncing.gif"); animations[2] = image.fromfile("rice-boy-walking-right-bouncing.gif"); animations[3] = image.fromfile("rice-boy-walking-down.gif"); animations[4] = properties.resources.rice_boy_standing_left; animations[5] = properties.resources.corn_cobs; } 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)// when riceboy goes downwards , hits bottom right = true { check = false; downwards = false; right = true; } if (player.left + 150 > this.clientsize.width)//stops @ starting point { right = false; } } private void b1_click(object sender, eventargs e) { this.paint += new painteventhandler(form1_pad1_corn); riceboywalkgif.enabled = true; left = true; left2 = true; riceboywalk.enabled = true;} } private void form1_pad1_corn(object sender, system.windows.forms.painteventargs e) { e.graphics.drawimage(properties.resources.corn_cobs, 70, 70, 400, 400); } private void timer1_tick(object sender, eventargs e) { if (left2) { player.image = animations[0]; 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 quaility player.image = animations[1];//animates riceboywalkingup check2 = true; up2 = false; } if (player.top < 105 & 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 quaility player.image = animations[2];//animates riceboywalkingright right2 = false; } if (down2)//goes downwards { player.image = animations[3];//animates riceboywalkingdown down2 = false; } if (player.top + 150 > this.clientsize.height)// when riceboy goes downwards , hits bottom riceboy walks right { iggy = true;// shows riceboy approching starting point check2 = false; down2 = false; right2 = true; } if (player.left + 150 > this.clientsize.width & iggy)//stops @ starting point { right2 = false; player.image = animations[4];// rice boy standing left }
c# arrays performance indexing
Comments
Post a Comment