d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Visual Basic Question (keydown Function With Pics) > Will Donaate On Solution!
Add Reply New Topic New Poll
Member
Posts: 7,671
Joined: May 24 2012
Gold: Locked
Warn: 30%
Dec 29 2012 10:38am
Hello I got a problem.

What i want is a moving picturebox wich changes gif/pic depending on direction or if i stand still or not.

i cannot make the gif stop looping so it doesnt show up correctly.

I wrote it like this

If e.KeyCode = Keys.W Then
PictureBox1.Image = My.Resources.up
PictureBox1.Top -= 2
else
PictureBox1.Image = My.Resources.xup
End If

If e.KeyCode = Keys.S Then
PictureBox1.Left += 2
PictureBox1.Image = My.Resources.down

else
PictureBox1.Image = My.Resources.xdown
End If

If e.KeyCode = Keys.A Then
PictureBox1.Image = My.Resources.left
PictureBox1.Left -= 2
else
PictureBox1.Image = My.Resources.xleft
End If

If e.KeyCode = Keys.D Then
PictureBox1.Image = My.Resources.right
PictureBox1.Left += 2
else
PictureBox1.Image = My.Resources.xright
------------
i added the recourses correctly and they work.

But i dont want the gif to loop when i hold down a key. i want it to display once and stay that way and loop by itself(the gif is the loop) untill i release the key.

The one without (X& SX is PNG and the others with names without Xmarks is Gifs)

Gif is the walk animation and png is stand still pic.

How should i code it so it starts and stops the gifs properly?

Atm the gif is spammed while i hold down a key and only gets time for the first frame.

Will donate for help!

This post was edited by Alex_Smiter on Dec 29 2012 10:40am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Member
Posts: 7,671
Joined: May 24 2012
Gold: Locked
Warn: 30%
Dec 29 2012 10:50am
Quote (carteblanche @ Dec 29 2012 07:48pm)


yes.

sorry for explaining bad.

Any idea?

I want the gif to display without reinsert it to the first frame on each step i move. and change to the Png once the Key is released

This post was edited by Alex_Smiter on Dec 29 2012 10:51am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Dec 29 2012 11:03am
did you read the link you quoted?

you can also try disabling it to stop the animation. i never tried it.

to fix the spamming issue when you hold down a key, set a flag so your event isn't invoked all the time. or is there a better event you can choose? there's prolly one that only gets invoked when you click it (as opposed to keeping it pressed)
Member
Posts: 7,671
Joined: May 24 2012
Gold: Locked
Warn: 30%
Dec 29 2012 12:02pm
Quote (carteblanche @ Dec 29 2012 08:03pm)
did you read the link you quoted?

you can also try disabling it to stop the animation. i never tried it.

to fix the spamming issue when you hold down a key, set a flag so your event isn't invoked all the time. or is there a better event you can choose? there's prolly one that only gets invoked when you click it (as opposed to keeping it pressed)


I checked the quote, and can you give an example of a flag?

wich one to use and were.

This post was edited by Alex_Smiter on Dec 29 2012 12:08pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Dec 29 2012 12:25pm
Code
onKeyPressed(...){
 if (pressed) return;
 pressed = true;
 // do your stuff
}

onKeyReleased(...){
 pressed = false;
}
Member
Posts: 7,671
Joined: May 24 2012
Gold: Locked
Warn: 30%
Dec 29 2012 01:43pm
Quote (carteblanche @ Dec 29 2012 09:25pm)
Code
onKeyPressed(...){
 if (pressed) return;
 pressed = true;
 // do your stuff
}

onKeyReleased(...){
 pressed = false;
}


this is vb.net
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Dec 29 2012 02:02pm
Quote (Alex_Smiter @ Dec 29 2012 02:43pm)
this is vb.net


are you saying you cannot understand what that pseudocode snippet does? i think you have bigger problems than pausing a gif. im giving up trying to help you now.
Member
Posts: 7,671
Joined: May 24 2012
Gold: Locked
Warn: 30%
Dec 29 2012 02:49pm
Quote (carteblanche @ Dec 29 2012 11:02pm)
are you saying you cannot understand what that pseudocode snippet does? i think you have bigger problems than pausing a gif. im giving up trying to help you now.


I do understand it lol. It wasnt the kind of answer i was looking for though.. ty.
Member
Posts: 4,694
Joined: Sep 21 2008
Gold: 1,231.00
Dec 30 2012 06:29pm
you could also try a loop that sets the animation to a determined frame from frame 0 to X (idk how long are your gifs). Or, if you want a nicer/cleaner/flexible code, you should be able to determine the number of frames your gif has with code. there's functions for that. I actually would recommend doing so, since it would also allow you to change your animation sequences at will without actually having to recode the movements of the character
the loop, of course, would be followed by the desired static png

This post was edited by IamnotZ on Dec 30 2012 06:29pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll