CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2012
    Posts
    10

    How to stop image flickering

    Hello

    Please tell me what to do about stop image flickering in attach files.

    Thank you.
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How to stop image flickering

    Post the code in question, and highlight the errors for us. People tend not to download & fix

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: How to stop image flickering

    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.
    Last edited by WoF; October 10th, 2012 at 08:52 AM.

  4. #4
    Join Date
    Oct 2012
    Posts
    10

    Re: How to stop image flickering

    Thanks alot Wof, but please, could you show me a small example with one Ship?
    Last edited by nirolf; October 10th, 2012 at 11:13 AM.

  5. #5
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: How to stop image flickering

    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.
    Attached Files Attached Files

  6. #6
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: How to stop image flickering

    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..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  7. #7
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: How to stop image flickering

    Oops sorry those are for Vb.NET ...

    here's the VB 6 articles..

    Animation in VB Part 2
    Animation in VB Part 1
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured