如何将1个picbox移到另一个picbox上? [英] how to move 1 picbox on top of another picbox?

查看:135
本文介绍了如何将1个picbox移到另一个picbox上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...
对不起我的英语.我来自葡萄牙

我正在vb 2008中制作格斗游戏,并且我有Picturebox 1和Picturebox 2,它们带有
2名战士.当picbox 1移到picbox 2的顶部时,第二个picbox不出现
里面的战士.如何将1个picbox移到另一个顶部并查看图像
当他们发生冲突时,两者都在里面吗?

hello guys...
sorry my english. i''m from portugal

i''m making a fight game in vb 2008, and i have picturebox 1 and picturebox 2 with
2 fighters. when picbox 1 goes on top of picbox 2, the second picbox does not apear
the fighter inside. how to move 1 picbox on top of another and see the image
inside of both when they colide? thanks for helping.

推荐答案

首先,请尽量避免使用PictureBox控件.直接从Panel或什至UserControl派生的控件表面上绘制,效果会更好.

BackColor属性设置为透明(从Web颜色而不是系统颜色),然后在控件的构造函数中添加:
Firstly, try to avoid using the PictureBox control if you can. You will be far better off drawing directly onto the surface of a control derived from a Panel or even a UserControl.

Set the BackColor property to Transparent (From Web Colors not System Colors) then in the constructor for your control add:
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)


您永远不应使用PictireBox渲染复杂的运动场景,尤其是动画场景.这是许多CodeProject问题中展示的典型设计错误之一.大多数专家建议避免这种情况.我个人看到许多项目由于此设计错误而无济于事.

有一种替代方法可以使用与您要执行的操作类似的方法:WPF.使用WPF,您可以将对象放置在Canvas上并对其进行动画处理.对于像您这样的游戏,我强烈建议您这样做.但是,这对于System.Windows.Forms不起作用.

您需要以某种控件(或形式)渲染整个场景,并通过Control.Invalidate触发渲染更改.完整的场景显示在我最近的答案中:在之后绘制矩形按时间加载的表单 [ ^ ].您可能会认为它描述了过于简化的情况.没关系,您的问题需要完全相同的方法.您需要强烈区分游戏及其渲染的数据模型.所有更改都应仅在模型上进行,渲染在无效状态下触发,并且渲染过程应该完全相同,无论游戏状态机的语义状态是:模型进入,渲染出来.

祝你好运,
—SA
You should never use PictireBox for rendering complicated moving scenes, especially animated. This is one of the typical design mistakes demonstrated in many CodeProject Questions. Most experts advised to avoid it. I personally saw a number of projects which went nowhere due to this design mistake.

There is one alternative where the approach similar to what you want to do can be used: WPF. With WPF you can place objects on Canvas and animate them. I would highly recommend this for the games like yours. This does not work for System.Windows.Forms though.

You need to render whole scene in some control (or form) and trigger changes in rendering via Control.Invalidate. The complete scenario is shown in my recent Answer here: draw rectangle after form loaded by time[^]. You may think it describes overly simplified case. No matter, your problem requires exact same approach. You need to strongly separate data model of the game and its rendering. All changes should be done only on the model, rendering triggered in invalidation, and the rendering procedure should be exactly the same regardless the semantic state of your game''s state machine: model in, rendering out.

Good luck,
—SA


这篇关于如何将1个picbox移到另一个picbox上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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