[VB.net]游戏,初学者项目:玩家运动问题 [英] [VB.net]Game, Beginners project: Player Movement Issue's

查看:173
本文介绍了[VB.net]游戏,初学者项目:玩家运动问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我只是想确保您知道这是我正在进行的初学者项目。我没有使用XNA.Framework,DirectX,Unity或任何游戏引擎,我在VB.net中使用Windows窗体从头开始制作我自己的游戏,到目前为止它还好 - 但是:



问题1:当您在屏幕上移动时,窗体的背景图像上会出现一些小问题,屏幕截图。在图片中你可以看到玩家从墙上向下移动 - 但是墙壁稍微跟随了半秒钟。播放器是一个图片框,位于带有背景图像的表单之上。



问题2:有没有办法让图片框以45度角移动?不只是向下?我当前的玩家移动编码:

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:

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!

推荐答案

请看我对这个问题的评论。



你需要的第二件事是停止使用 PictureBox 。在您的情况下,它根本没有帮助,只会产生问题。我会解释做什么。请查看我过去的答案:

在其中附加图片图片框 [ ^ ],

画一个矩形C# [ ^ ],

如何从旧图纸中清除面板 [ ^ ]。



关于图形渲染的其他一些重要细节请看这些答案:

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ];

这个更具体的图形和UI动作互动:如何加快我的vb.net应用程序? [ ^ ]。



现在,关于你的轮换。在此技术中,您不应该旋转任何控件。你需要使用 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 [ ^ ]。



您可能需要使用其他转换。



另一个至关重要的是正确使用线程。请看我过去的答案:

如何将ref参数传递给线程 [ ^ ],

更改线程(生产者)启动后的参数 [ ^ ],

C#中的多线程 [ ^ ],

Control.Invoke()与Control.BeginInvoke() [ ^ ],

Treeview扫描仪和MD5的问题 [ ^ ]。



它应该解决你遇到的大多数问题,如果不是全部的问题。但是合理的整洁代码(请参阅我对这个问题的评论)是你需要先解决的问题。



-SA
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


这篇关于[VB.net]游戏,初学者项目:玩家运动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆