Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list of meteors that I need to rotate individually depending on the rotation speed.
Despite everything I have tried, it doesn't rotate at all.
Note: The image is scaled up by 2.

VB
Private Sub Form1_Paint5(ByVal sender As Object, ByVal e As  _
    System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

    For Each I As Meteor In Meteors ' Rotate Meteors and draw meteors
        e.Graphics.Transform.RotateAt(5, New Point(I.Pos.X + I.Type.Width, I.Pos.Y + I.Type.Height))
        e.Graphics.DrawImage(I.Type, I.Pos.X, I.Pos.Y, I.Type.Width * 2, I.Type.Height * 2)
    Next
End Sub
Posted

1 solution

Because Graphics.Transform returns a copy of the transformation matrix, not the matrix being used. In order to do what you want, you would need to do something like this:

VB
'Inside your loop
e.Graphics.Transform = e.Graphics.Transform.RotateAt(5 ...)


But you would want to save your graphics state between rotations so the previous rotation does not affect the next one, you do this by saving the GraphicsState and restoring it.

VB
Dim graphicsState as GraphicsState = e.Graphics.Save()
'do your transformation here, then draw your image
e.Graphics.Restore(graphicState)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900