Click to See Complete Forum and Search --> : Anmation Help,Please!!
MHD
Nov 8th, 2002, 10:30 AM
I, being new at visual basic, am seeting out to be a game programmer. and though i have barely scratched the potential of this wonderful program, i need some help! I need a no frills explanation of how to animate sprites very simply. Please, will some helpful person explain??
ChuckB
Nov 8th, 2002, 11:02 AM
Hi,
Here are some general ideas...short and sweet...to get you thinking in the right direction.
Example 1:
Add Picture object to your form. Set the picture property to a BMP you have created (this will be your sprite). Add a timer. Enable it. Set it to act every 1 second (1000 mSec).
Go to the timer event and add something like this....
Picture1.left = picture1.left + 100
Run the program. Your sprite will move from left to right in 100 step increments (twips not pixels).
Eventually the sprite will work to the right side of your form...it will be necessary to reverse direction, go up/down or reset the sprite. Modify the code above to look something like this...
Picture1.left = picture1.left + 100
if Picture1.left > form1.width then picture1.left = 100
All this does is allow the sprite to move to the right by changing the 'left' property until the left property exceeds the width of the form. Once it exceeds this boundary, it is reset to position 100.
This is pretty simple and unexciting but it may get you started. If you are interested go back and look at the thread called by "2D Collision and Avoidance" started by myself to see a crude example.
To move the sprite faster change your timer from 1 second to say 100 mSec.
Oh yeah, once you pick up this animation concepts, it works equally well with other languages such as C++ or QBasic...
This is just the tip of the iceburg...
Regards,
ChuckB
MHD
Nov 8th, 2002, 11:34 AM
Indeed, i thank you for clearing thiis subject up for me. I recognize i have a lot to learn, and i nod my head to you intrepid people who go through these forums and answer all these cries for help. May all your games be grand.
DOE
Nov 8th, 2002, 02:30 PM
CuckB
Can you change the direction of the picture movement? I used
Picture1.Right = Picture1.Right + 100
but I recieved a "compile erorr"
Any idea as to how I can fix this?
Doe
H-Zence
Nov 8th, 2002, 03:09 PM
There is no "Right" property of the picture control. Also, you need to do a bit more than that.
Here are some steps:
1. Add a picture box to your form.
2. Add a Timer control to your form
3. Set the timer's "Enabled" property to true, and set its interval property to oh, I dunno, try 50.
4. Double click on the timer. THis will open your code window and take you to the "Timer1_Timer()" subroutine.
5. Here, type in your code: Picture1.Left = Picture1.Left + 100.
6. If you want to make it go the other way, it's pretty obvious. if "+" makes it go right, then "-" will make it go left.
I know you need to do more because your code says ".Right", and there is not Right property of a picture control.
For a complete list of properties, open your form window, click on the control, and then look at the properties window at the bottom right of your screen.
You have much to learn about development. My advice to you is to not start out trying to make games, start out learning about Visual Basic. Make simple programs first. Not games. You'll crash and burn.
DOE
Nov 8th, 2002, 05:53 PM
H..
I have been using VB for 3 years, I just have not been working with graphics so if that is such a crime, lock me up...
And I need to make a game for a school project...so please, don't be snarky becuase nobody is impressed
NoteMe
Nov 8th, 2002, 06:07 PM
I don't think anyone is trying to be snarky (I have no idea of what that means, but anyway...), so just tell us your problems and we will try to solve them...
H-Zence
Nov 8th, 2002, 10:23 PM
I didn't mean to be "snarky", but I'd assume that if you'd been working with VB for at least 3 years you'd know that pretty much no standard VB control has a Right property...I really don't know what you've been doing if you've been working with it for that long, but that's okay. And I do not mean to "impress" anyone, I really don't know how I would accomplish that.
However, if you wish for us to help you, at least get a decent understand of the picture box control. You can find beginner tutorials all over, and they will help. Most programmers are self taught, and I'm one of them.
So like NoteMe said, we...or at least I...will keep helping you, but get a decent understanding of the VB controls first. Sorry.
DOE
Nov 9th, 2002, 02:21 PM
no problem guys...I was just having a bad day and when I read your posting I just sorta snapped.
No hard feelings at all:)
When I say I've been doing VB for 3 years it is actaully slightly miss-leading..I am still in high-school and I have been in three classes using VB. So I have not really had too much free time to just experiment with various properties and fuctions inside of VB since we have to follow the assignments that we are given in class.
On a whole other note...you mentioned about tutorials and such. I was wondering if anybody has any suggestions on a Visual Basic book that I could buy that will be helpful to me. Any/all suggestions are appreciated.
Thanks and sorry!
Doe
Sastraxi
Nov 9th, 2002, 02:35 PM
Wrox makes excellent tutorial books. O'Reilly makes excellent reference books. I suggest getting one from each publisher, maybe two or three from Wrox (win32 api, vb6 beginners, advanced vb techniques). From O'Reilly just get a good pocket reference, as the 'net is good for that now.
MHD
Nov 14th, 2002, 07:25 AM
Looking at all the other posts, i have learned a great deal from just this thread. I thank all who replied, and will soon emerge with a great game for you all!!!!!!(Well, at least I'll think it's great)
MHD
Nov 14th, 2002, 08:28 AM
Oh, by the way, if i wanted the animation to take place when the program starts, where would i put the code?
NoteMe
Nov 14th, 2002, 08:37 AM
In the
Private Sub Form_Load()
End Sub
event.....
MHD
Nov 14th, 2002, 08:43 AM
Thankee
MHD
Nov 18th, 2002, 08:35 AM
after going throught all of this code, i started experimenting. I want the picture to move to the right, then when it reaches a certain coorinate, reverse itself until it gets to another coordinate. Am i stupid, of just incompetent? Because i cant do It!!
NoteMe
Nov 18th, 2002, 08:57 AM
Make a boolean that is "global". Call it goLeft or something, and make it false.
if goLeft = false then
Pic.left = Pic.left + 1
else
Pic.left = Pic.left - 1
end if
If Pic.left = 300 then 'If 300 is the point you want it to turn
goLEft = true
elseif pic.left = 100 then 'If 100 is the point you want it to turn
goLeft = false
end if
Make this a loop......
MHD
Nov 18th, 2002, 09:19 AM
being a newbie, i dont know where to put the boolean...
NoteMe
Nov 18th, 2002, 09:21 AM
Before the loop in the method. Or on the top (top of our code, it depends on what else you want to do with it).
MHD
Nov 18th, 2002, 09:23 AM
ok, it tells me :
Compile Error:
Statement invalid outside type block
what am i supposed to do?
NoteMe
Nov 18th, 2002, 09:29 AM
I'm not sure what you are doing wrog, but loog at this attachment....
MHD
Nov 18th, 2002, 09:34 AM
OOOHHH... ... ...
i forgot the DIM...
Stupid me...
Thanx for the help.
This unworthy newbie thanks you.
NomadtheGrey
Nov 19th, 2002, 08:19 AM
I couldn't get performance out of pushing a PictureBox around like that.
the BitBlt API works great once you get it going. You get some amazing refresh rates with it.
Wouldn't play with API's yet until you're totally sick of pushing PictureBoxes around.
SmashX
Nov 20th, 2002, 11:42 AM
Picture1.left = Picture1.left + 100
IT MOVES! IT REALLY MOVES! BWAHAHAHAHA!!!
meh...now for another question: how do i make it go up and down?
MHD
Nov 20th, 2002, 12:29 PM
Cange all the .Left suffixes to .top
SIMPLE!!
you could also change the name of the boolean to goUp or something.
SmashX
Nov 20th, 2002, 06:53 PM
SWEET!!!!!!!
THANKS ALOT!!!!
hehehe
now on to find more questions!:D
NomadtheGrey
Nov 20th, 2002, 09:05 PM
Wanna have some fun with people? Put a button down on your form. In the caption, put "Can't catch me!"
Now, in the MouseOver event, put Button1.top = Button1.top + 5 or something like that.
Just let your friends play with it, or wife, or kids, or whatever. They will hate you! Hee!
NoteMe
Nov 21st, 2002, 12:49 AM
SmashX: You should try to play more with the properties. Like .left .width .top .visible, and so on. Try clicking them and see what they do. And take a look in the help file for more information. About the loop too (actually there are 3 of them). You will learn much more by doing that....
SmashX
Nov 21st, 2002, 10:50 AM
ok thanks
FunyBunyFartAHH
Nov 21st, 2002, 11:42 AM
Assuming you have your interface set up ( img control ect..) Type this in, might help ya :)
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case Is = 37
Image1.Left = Image1.Left - 50
Case Is = 38
Image1.Top = Image1.Top - 50
Case Is = 39
Image1.Left = Image1.Left + 50
Case Is = 40
Image1.Top = Image1.Top + 50
End Select
End Sub
Picture 1 = the picture box control that the image is going to move in
image = whats going to be moved with the key codes
Rest if you dont know then read more!:cool:
Copy & Paste if you like :eek: :eek:
FunyBunyFartAHH
Nov 21st, 2002, 11:43 AM
Ohhh and if you need help, click f2 inside vb to see the whole list of things...
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.