Results 1 to 8 of 8

Thread: [RESOLVED] Flickering Controls

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    97

    Resolved [RESOLVED] Flickering Controls

    Hey again,

    I think I've recently come a long way in terms of VB knowledge (particularly in terms of moving sprites), and now I'm revisiting an old project to try and get it up to scratch.

    As you can see from the picture, the game consists of:

    • The interface on the left
    • The map on the right which the player moves around
    • The player in the centre of the map (white dot)

    I used to have the "house" as an Autoshape object, but now I'm drawing it at run-time using the "Line" function.

    My problem is, because of having to use the "Cls" and "Refresh" functions to keep moving the house at run-time, the interface (or at least part of it) flickers. I suspect this is just because of the brown Autoshape and yellow and black labels.

    My question is this:

    Is there a way around this "flicker", or, if not, will drawing the Autoshape and labels at run-time be good enough - i.e. will the other controls cope ok with the clear screen function (and if not, what can I do about them)?

    Also, is all this re-drawing really the best way? It seems like it ought to be a lot of hard work, but then again maybe computers can cope with more than I give them credit for.

    Thanks,

    - Danjb
    Attached Images Attached Images  

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Flickering Controls

    Please post the code that you are using! Thank you.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    97

    Re: Flickering Controls

    There's really not a lot to it, other than the 2 functions I mentioned. When you click somewhere, the house "moves" to simulate the player moving, while keeping the player central.

    Code:
        Me.Cls
        House.X1 = House.X1 - (MoveSpeedX)
        House.X2 = House.X2 - (MoveSpeedX)
        House.Y1 = House.Y1 - (MoveSpeedY)
        House.Y2 = House.Y2 - (MoveSpeedY)
        DrawHouse
        Me.Refresh
    This moves the house just fine, but the interface flickers.

    Again, I suspect that the best solution is to draw the interface at run-time, I just wanted a bit of advice / reassurance that this is the best way to do it, and that the other controls won't flicker (since I don't know how to "draw" them at run-time).

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Flickering Controls

    The simple way to solve this is not to draw on the form itself, but to create a PictureBox for the playing area and draw on to that (it has .Cls and all of the other methods a form has).

  5. #5
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: Flickering Controls

    Rather than Drawing the house with Line Statements have a Control represent the house and then use;

    MyControl.Move newX,newY

    MyControl could be just about any type of Control but a Shape Control with its Shape property set to Rectangle will give very similar results to those you have now.

    You will no longer need the Cls which I expect is the cause of your flicker.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    97

    Re: Flickering Controls

    Si, you've done it again! That's EXACTLY what I needed, thank you

    Rather than Drawing the house with Line Statements have a Control represent the house
    I would do that (I used to) but I've always been told that using controls is very inefficient when there are lots of them, so now I always draw things when possible.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Flickering Controls

    Quote Originally Posted by Magic Ink
    You will no longer need the Cls which I expect is the cause of your flicker.
    In terms of frequently moved items like this (especially when there is more than one object moving on screen at a time), using controls is a sure fire way to get the worst flicker you can without specifically trying to get flicker.

    Having a mixture of controls and drawn items on the same parent object isn't good either (for one moving item it is probably the same as controls, but better for multiple items). Thankfully it is easy to create separate parent objects (using something like a PictureBox or Frame) to avoid the issue.
    Quote Originally Posted by Danjb View Post
    Si, you've done it again! That's EXACTLY what I needed, thank you
    Excellent, nice and easy!!

    As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    97

    Re: [RESOLVED] Flickering Controls

    Thanks for the advice.

    Oh yeah, sure thing

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