Hello
Please tell me what to do about stop image flickering in attach files.
Thank you.
Printable View
Hello
Please tell me what to do about stop image flickering in attach files.
Thank you.
Post the code in question, and highlight the errors for us. People tend not to download & fix
That's true, but in this case you ought to download the sample and look at the boats flickering. You have to see the effect to get the impression. There is no actual error in the code.
I think the problem comes from the fact that the ships are image controls which lie directly on the surface of the picturebox with the water.
Blitting the water erases all ships. Triggering pic1.Refresh repaints the water and then triggers all refresh events of the boats, making them appear to flicker.
I am not a game programmer, but maybe the use of the refresh event of an image control is not fast enough.
You could redesign the concept, so that the picture of the ship is residing in one small picturebox outside pic1.
Then you change the timer event accordingly to that:
a) BitBlt the water like before
b) TransparentBlt the ships to their positions where they are currently meant to be.
c) Do pic1.refresh
To do b) you have to have an array of UDT or class Ship which holds its current X and Y position, so as you can use TransparentBlt to paint the ships onto the water.
Although If I'd be guessing, you'd want to drag and drop the ships to other locations, so this cannot be done anymore by the standard drag and drop mechanism featured by the image control. But you can use the pic1_MouseDown and MouseMove events to scan if the mouse is on one of the ships and change their positions accordingly.
Thanks alot Wof, but please, could you show me a small example with one Ship?
Well yes. It is rather simple. I have modified your sample and added the use of TransparentBlt. Look at the attached project.
a) Note that I have removed all image controls from the water picturebox.
b) I have added a picturebox to hold the image of the ship. As I transfered the image from your Nava() images it appeared to be higher stretched as seen, but this is compensated during the TransparentBlt
c) I have defined the Usertype Ship, which holds an x and y position on the water, and a reference to the boat picture to be used. You could then use different boat images for each ship on the water.
d) I declared an array of max 8 ships (Dim Ships(7) As Ship)
In Form_Load() I have initialized 4 ships somewhere on the water.
Please run the program and see how smooth and flickerfree the ships are drawn.
Feel free if you have any more questions.
Lots of tips and tricks in the article section..
Specially these ones..
Animation In VB.NET Interacting with Objects
Animation in VB.NET Part 3
what you will notice on these articles is that you always use a single Image holder, and a buffer that you build behind the scene, and apply over the visible Image..
Oops sorry those are for Vb.NET ...
here's the VB 6 articles..
Animation in VB Part 2
Animation in VB Part 1