Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello, I just want to make sure you are aware this is a beginners project I am having. I am not using XNA.Framework, DirectX, Unity or any game engines, I am making my own game completely from scratch using windows forms in VB.net, so far its alright- however:

Question 1: When you move around the screen there is a little lagg on the backround image of the form, Screenshot. In the picture you can see the player moving downwards out of a wall- but the wall slightly follows for half a second. The player is a picturebox, on top of a form with a backround image.

Question 2: Is there a way to have the picturebox move at a 45 degree angle? Not just up an down? My current player movement coding:
VB
Public Shared KeyboardKeysPressed As New HashSet(Of Keys)

Public Shared Sub OnFps(sender As Object, e As EventArgs) Handles Framerate.Tick
        If KeyboardKeysPressed.Contains(Keys.W) Then
            mainForm.Player_Picture.Top -= 8
        ElseIf KeyboardKeysPressed.Contains(Keys.A) Then
            mainForm.Player_Picture.Left -= 8
        ElseIf KeyboardKeysPressed.Contains(Keys.D) Then
            mainForm.Player_Picture.Left += 8
        ElseIf KeyboardKeysPressed.Contains(Keys.S) Then
            mainForm.Player_Picture.Top += 8
        End If
    End Sub


Please note I am a beginner at this, so I might not understand a solution right away and such.

Thank you in advance!
Posted
Updated 30-Jan-15 7:18am
v2
Comments
Sergey Alexandrovich Kryukov 30-Jan-15 12:56pm    
To start with, stop writing in so messy style. For example, get rid of hard-coded immediate constants like 8. Imagine what happens if you want to use 12 eventually. This is not maintainable. Use explicitly declared constants.

Also, you need to tag System.Windows.Forms, so people would see immediately what you are using. I recognized it by PictureBox, which you should not use, of course.

—SA

1 solution

Please see my comments to the question.

Second thing you need is to stop using PictureBox. In your case, it is not helpful at all, only creates problems. I'll explain what to do instead. Please see my past answers:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^].

On some other important detail on graphics rendering please see these answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^];
and this one more specific to motion in graphics and UI interaction: How to speed up my vb.net application?[^].

Now, about your rotation. In this technology, you should not rotate any controls. You need to render the whole scene and rotate some elements of it using Graphics.Transform:
https://msdn.microsoft.com/en-us/library/system.drawing.graphics.transform%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.matrix(v=vs.110).aspx[^].

You may need to use other transformations.

Another thing which is critical is correct use of threading. Please see my past answers:
How to pass ref parameter to the thread[^],
Change parameters of thread (producer) after it is started[^],
MultiThreading in C#[^],
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

It should resolve most of the problems you are having, if not all of them. But reasonably neat code (please see my comment to the question) is something you need to address first.

—SA
 
Share this answer
 
v4

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