Animation in C# using several PNGs -



Animation in C# using several PNGs -

i'm trying create click event triggers animation. i've drawn of frames , saved them separate png files (all of them 38 pixels long , 56 pixels wide), can't figure out how run them through picturebox.

i've looked @ lots of posts (here , elsewhere) people talk timers, haven't been able figure out how phone call of these long examples click event. alternatively, exported frames a single animated gif, gifs loop, , want animation play once.

here's have:

private void btnstart_click(object sender, eventargs e) { int delay = 100; box1.image = project.properties.resources.frame1; system.threading.thread.sleep(delay); box1.image = project.properties.resources.frame2; system.threading.thread.sleep(delay); box1.image = project.properties.resources.frame3; system.threading.thread.sleep(delay); box1.image = project.properties.resources.frame4; system.threading.thread.sleep(delay); box1.image = project.properties.resources.frame5; system.threading.thread.sleep(delay); box1.image = project.properties.resources.frame6; system.threading.thread.sleep(delay); box1.image = project.properties.resources.frame7; system.threading.thread.sleep(delay); box1.image = project.properties.resources.frame8; //(and on) }

this waits sec , abruptly switches lastly frame (frame8 in example), no matter delay variable is.

i'm approaching wrong. guys think?

event handler blocks main thread. ui refreshes in main thread.

so, click on button, event handler blocks thread , executes, , whatever alter won't affected on ui until event handler finishes - that's experience.

so in button click event handler need initiate process, process should in separate thread. easiest way, if utilize frame frame animation, utilize timers.

you need set interval in timer, , in timer tick event need load new image in image box. need track current frame index via separate variable. if within tick event realize lastly image - set timer disabled. reset timer , frame variable in button click event.

c# animation png sprite picturebox

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -