Results 1 to 4 of 4

Thread: Quick question abouit flipping sprites *RESOLVED*

  1. #1

    Thread Starter
    Lively Member H-Zence's Avatar
    Join Date
    Jul 2002
    Posts
    94

    Quick question abouit flipping sprites *RESOLVED*

    Okay guys, can someone tell me how you would flip a sprite (in other words make it facing horizontally the other way)? Here's my code:


    Private picWidth As Single ' Picture width.
    Private picHeight As Single ' Picture height.
    Private Xpos As Single ' Sprite's X position.
    Private Ypos As Single ' Sprite's Y position.
    Private FrameCounter As Integer ' Keep track of the current frame.

    ' Declare the bit block transfer function.
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, _
    ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _
    ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

    Private Sub cmdExit_Click()
    ' Close the form.
    Unload Me
    End Sub

    Private Sub cmdAnimate_Click()
    ' Enable sprite's animation.
    tmrAnimate.Enabled = True
    End Sub

    Private Sub cmdFrames_Click()
    AniSprite ' Set the sprite's frames.
    SetSprite ' Show the sprite.
    End Sub

    Private Sub cmdStop_Click()
    ' Disable sprite's animation.
    tmrAnimate.Enabled = False
    End Sub

    Private Sub picDestination_KeyDown(KeyCode As Integer, Shift As Integer)
    ' Check for keypresses
    Select Case KeyCode
    ' Move left
    Case vbKeyLeft
    'Draw the picture normally (left-facing deer)
    Xpos = Xpos - 5 ' Move X position
    SetSprite ' Draw the sprite
    Exit Sub ' Exit the subroutine

    ' Move right
    Case vbKeyRight
    Xpos = Xpos + 5 ' Move X position
    SetSprite ' Draw the sprite
    Exit Sub ' Exit the subroutine

    ' Move up
    Case vbKeyUp
    Ypos = Ypos - 5 ' Move Y position
    SetSprite ' Draw the sprite
    Exit Sub ' Exit the subroutine

    ' Move down
    Case vbKeyDown
    Ypos = Ypos + 5 ' Move Y position
    SetSprite ' Draw the sprite
    Exit Sub ' Exit the subroutine

    End Select
    End Sub

    Private Sub Form_Load()

    With picMask
    .AutoRedraw = True ' Redraw sprite mask
    .AutoSize = True ' Size to source's size
    .BorderStyle = 0 ' No border
    .ScaleMode = 3 ' Pixels
    .Visible = False ' Invisible
    End With

    With picMan
    .AutoRedraw = True ' Redraw sprite mask
    .AutoSize = True ' Size to source's size
    .BorderStyle = 0 ' No border
    .ScaleMode = 3 ' Pixels
    .Visible = False ' Invisible
    End With

    With picDestination
    .AutoRedraw = True ' Redraw sprite mask
    .AutoSize = True ' Size to source's size
    .ScaleMode = 3 ' Pixels
    End With

    With picSource
    .AutoRedraw = True ' Redraw sprite mask
    .AutoSize = True ' Size to source's size
    .BorderStyle = 0 ' No border
    .ScaleMode = 3 ' Pixels
    .Visible = False ' Invisible
    End With

    FrameCounter = -1 ' Animation has not yet begun, set default

    ' Set picture of sprite
    picMan.Picture = ImageList1.ListImages(1).Picture
    picMask.Picture = ImageList1.ListImages(2).Picture

    ' Set sprite's height and width.
    picWidth = picMan.Width
    picHeight = picMan.Height

    Xpos = 178 ' Sprite's X position
    Ypos = 106 ' Sprite's Y position

    SetSprite ' Show the sprite
    End Sub

    Private Sub tmrAnimate_Timer()
    AniSprite ' Set current frame
    SetSprite ' Display sprite update
    End Sub

    Public Sub AniSprite()
    ' Update sprite frame & redraw.
    FrameCounter = FrameCounter + 2
    If FrameCounter = 5 Then FrameCounter = 1
    picMan.Picture = ImageList1.ListImages(FrameCounter).Picture
    picMask.Picture = ImageList1.ListImages(FrameCounter + 1).Picture
    End Sub


    Public Sub SetSprite()
    picDestination.Cls ' Clear frame and prepare for update.

    ' Move the background to the destination bitmap.
    BitBlt picDestination.hDC, Xpos, Ypos, picWidth, picHeight, _
    picSource.hDC, Xpos, Ypos, vbSrcCopy

    ' Move the mask to the destination bitmap.
    BitBlt picDestination.hDC, Xpos, Ypos, picWidth, picHeight, _
    picMask.hDC, 0, 0, vbMergePaint

    ' Move the sprite to the destination bitmap.
    BitBlt picDestination.hDC, Xpos, Ypos, picWidth, picHeight, _
    picMan.hDC, 0, 0, vbSrcAnd

    picDestination.Refresh ' Refresh the background.
    End Sub


    So for example in the "Case Left" statement, what should I do!
    Thanks in advance to anyone who wants to help this n00b.
    Last edited by H-Zence; Dec 9th, 2002 at 05:01 PM.
    www.mindset1.com
    Religious Debate Forums

  2. #2
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    I think there is a built in function to turn pic by 180 but still I wouldn't use it becaues you lose time everytime you do so. I would load the pics two times one that's facing right and a nother one that's facing left. That way you can make sure that the game will run the same speed no matter which direction you go.
    on www.ur.co.nz there is a function enabling you to turn pics anglewise, which might be helpful to you anyways. There might be an explanation on how to flip it too.
    Sanity is a full time job

    Puh das war harter Stoff!

  3. #3

    Thread Starter
    Lively Member H-Zence's Avatar
    Join Date
    Jul 2002
    Posts
    94
    Yea, I was trying to stay away from that, but I guess game speed is a factor i should consider as well.

    Thanks for your help.
    www.mindset1.com
    Religious Debate Forums

  4. #4
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    well a basic rule for games:
    save memory when possible
    if you can get speed from sacrificing memory do it. (as long as it runs on a 256MB machine without having half it's data in the page file)
    Sanity is a full time job

    Puh das war harter Stoff!

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