Results 1 to 11 of 11

Thread: Animation of character

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2002
    Posts
    5

    Unhappy Animation of character

    I dont know how the hell to make a character move with a series of animations.

    I want it to run 3 or 4 pictures in a row when i push a key, seperated by about a half a second. I also want it to rerun the series for as long as the key is pushed. I know how to loop it but I want it to stop when I release the key.

    I know this is dumb but, hey, Im new at this stuff

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    You could use the getkeystate API, use it like this.

    VB Code:
    1. If GetKeyState(vbKeyLeft) < 0 Then MsgBox "The Left arrow key is pressed"


    To achieve what you want, you could perhaps, put it in your loop and have it exit the loop (exit do/while) if it's >0 (i.e. not pressed).
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  3. #3
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Sorry, forgot the declaration.

    VB Code:
    1. Public Declare Function GetKeyState Lib "user32" Alias "GetKeyState" (ByVal nVirtKey As Long) As Integer
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  4. #4
    Addicted Member
    Join Date
    Apr 2002
    Location
    Israel
    Posts
    152
    try this out(API)
    Attached Files Attached Files

  5. #5
    Lively Member slx47's Avatar
    Join Date
    Apr 2002
    Location
    US
    Posts
    127

    I did this once ...

    add a picture and a timer, the rest is up to you, just fill in the blanks
    VB Code:
    1. Dim a As Integer 'fram number
    2.  
    3. 'raster operations
    4. Const BLACKNESS = &H42
    5. Const DSTINVERT = &H550009
    6. Const MERGECOPY = &HC000CA
    7. Const MERGEPAINT = &HBB0226
    8. Const NOTSRCCOPY = &H330008
    9. Const NOTSRCERASE = &H1100A6
    10. Const PATCOPY = &HF00021
    11. Const PATINVERT = &H5A0049
    12. Const PATPAINT = &HFB0A09
    13. Const SRCAND = &H8800C6
    14. Const SRCCOPY = &HCC0020
    15. Const SRCERASE = &H440328
    16. Const SRCINVERT = &H660046
    17. Const SRCPAINT = &HEE0086
    18. Const WHITENESS = &HFF0062
    19. '=======================================
    20. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    21. a = a + 1
    22.  
    23. 'frame number
    24. Select Case a
    25. Case 1:
    26. Picture1.Picture = LoadPicture("filenamehere")
    27. Case 2:
    28. Picture1.Picture = LoadPicture("filenamehere")
    29. Case 3:
    30. Picture1.Picture = LoadPicture("filenamehere")
    31. Case 4:
    32. Picture1.Picture = LoadPicture("filenamehere")
    33.  
    34. End Select
    35.  
    36. If a > 5 Then '5 is the number of pics
    37. a = 0
    38. End If
    39.  
    40. End Sub
    41.  
    42. Private Sub Form_Load()
    43. Timer1.Interval = 500 '1/2 a sec
    44. Me.AutoRedraw = True
    45. End Sub
    46.  
    47. Private Sub Timer1_Timer()
    48. Me.Cls
    49. Me.PaintPicture Picture1.Picture, x, y, 100, 100, 0, 0, 100, 100, SRCCOPY
    50. End Sub

  6. #6
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    A timer is not a good thing for a game...
    Involved in: Sentience

  7. #7
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Look into the gettickcount api, there are lots of examples in this forum.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  8. #8
    Lively Member slx47's Avatar
    Join Date
    Apr 2002
    Location
    US
    Posts
    127
    A timer works fine for me.

  9. #9
    Member Yhoko's Avatar
    Join Date
    May 2002
    Posts
    47
    It works, yes, but a loop is more accurate and you can better manage the timing. By the way: VB has pre-defined constants for all those ROPs like vbSrcCopy or vbSrcPaint.

    Yhoko

  10. #10
    Zaei
    Guest
    Originally posted by Yhoko
    It works, yes, but a loop is more accurate and you can better manage the timing. By the way: VB has pre-defined constants for all those ROPs like vbSrcCopy or vbSrcPaint.

    Yhoko
    Someone other then me has pointed the constant thing out, finally =).

    Yes, when writing games, Timers are simply one of the worst things that you can use. They are inaccurate, inflexible, and a pain in the arse to do anything moderatly complex with. For reference, here is a standard game loop:
    Code:
    While running
      CheckInput()
      Update()
      Render()
    
      DoEvents
    Wend
    You can expand the above to limit frame rates:
    Code:
    Const Delay As Long = 25
    Dim lt as Long
    lt = GetTickCount()
    While running
       If lt + Delay > GetTickCount()
         CheckInput()
         Update()
         Render()
         
         lt = GetTickCount()
       End If
       DoEvents
    Wend
    Z.

  11. #11
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    [worthless post]

    Code:
            'Slow down the FPS...
            Do Until GetTickCount() >= LastTick + TicksPerFrame
                DoEvents
            Loop
            DebugMsg "Frame delay: " & GetTickCount() - LastTick - TicksPerFrame 'Show the delay
            LastTick = GetTickCount()
    This is the code I always use... This way you don't have to encapsulate everything in that IF, in my first game I had so many nested blocks in the main loop that I couldn't have my comments bigger than 30 characters (or I would have to manually word-wrap them and that's very annoying when you're concentrating on the coding). Hmm... ok... so it's not a very good excuse. Wait, it shows the frame delay When the game is ok it varies from 0 to 5 every frame. If it's slow it will of course go up. DebugMsg just shows a line of text on the screen. It's a good reference because when you're limiting the FPS you usually don't measure it

    [/worthless post]
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width