Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

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:
VB
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
 
Share this answer
 
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
 
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