Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help
Go Back  Xtreme Visual Basic Talk > > > Wheel of Fortune -Flickering Animation Help


Reply
 
Thread Tools Display Modes
  #1  
Old 06-05-2009, 07:35 AM
SFMK SFMK is offline
Newcomer
 
Join Date: May 2009
Posts: 6
Default Wheel of Fortune -Flickering Animation Help


Hi... I am designing Wheel of Fortune in Visual Basic 6.0 and am currently trying to animate the wheel. It is 24 frames and so I have 24 image boxes on top of each other, and they are visible/invisible when a timer executes. The image boxes are in a control array (if this has any effect).

My problem is that when I play the animation, it will not stop flickering, which makes the form really ugly. I have tried picture boxes, and that did not work. I've also heard something about a BitBlt function, but I do not understand how it works.

Any help in solving this problem would be greatly appreciated.
Reply With Quote
  #2  
Old 06-05-2009, 02:27 PM
Euroclydon's Avatar
Euroclydon Euroclydon is offline
Regular
 
Join Date: May 2009
Location: Northern Indiana, USA
Posts: 70
Default

Have you tried putting all of your frames into invisible image boxes, and
setting the Picture properties to a visible picture box's? This will likely not
eliminate flicker. So...

VB4 came with a help file for the Windows API, (which had a section on
BitBlt,) but it's written for C.

Here's the declare for VB (make sure it stays on one line!) and some
constants. Put them in the (Declarations) section of a module:
Code:
Declare Function BitBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As
	Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As
	Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As
	Long, ByVal dwRop As Long) As Long

Global Const BLT_NORMAL = &HCC0020
Global Const BLT_OR = &HEE0086
Global Const BLT_AND = &H8800C6
Global Const BLT_INVERT = &H660046
Here's how you call it (all on one line, too):
Code:
ReturnN% = BitBlt(picDest.hdc, DestX%, DestY%, Width%, Height%,
	picSource.hdc, SourceX%, SourceY%, BLT_NORMAL)
picDest
Destination Picture Box
DestX%, DestY%
Location (in pixels) for the top-left corner of the image chunk
Width%, Height%
Size (in pixels) of the section you're using from the image.
picSource
Picture Box you're getting the image from
SourceX%, SourceY%
Location (in pixels) of the top-left corner of the source image chunk in picSource
Blt_Normal
Bit operation flag. This simply copies directly.

Of course, you can call your Picture Boxes anything you like, just don't
neglect the ".hdc"! Your source box can be hidden, but you must set
AutoRedraw to True for it to work. Setting the ScaleMode to 3 (Pixel) for
all the boxes also makes things easier on you.

Set AutoRedraw to true for the destination, too, and use "picDest.cls"
before each frame you blit. At least for me, this took care of flicker.

If you use a separate source box for each frame, an indexed control
array helps. SourceX% and SourceY% will both be 0, and Width/Height
will be equal to the box's ScaleWidth/ScaleHeight -1. (So long as it's set
to ScaleMode 3!)

For transparent backgrounds, you have to use a mask. A mask is a
second version of your image in black and white: black where the image
will be opaque, white where it should be clear. Blit this in with the
BLT_AND setting. Then, in the exact same place, blit the actual image,
which must have black in all the places that will be clear, using BLT_OR.

Hope this helps. Need more info? Just ask.
__________________
"Have a place for everything and keep the thing somewhere else; this is not a piece of advice, it is merely a custom." - Mark Twain
Reply With Quote
  #3  
Old 06-06-2009, 06:16 PM
SFMK SFMK is offline
Newcomer
 
Join Date: May 2009
Posts: 6
Default

Thanks for the code Euroclydon, however I have a few more questions.

1) When I try input the declarations, it will not allow global, only private constants. Is this okay?

2) When I try run the program with these declarations, a compile error appears saying that declare is not allowed as public members of an object module. Am I putting this in the wrong place? It is at the top with the under general declarations.

3) I am going to go the route with a different picture box for each frame. Where do I put this ReturnN% code?

Thanks again for your help.
Reply With Quote
  #4  
Old 06-06-2009, 09:50 PM
Flamespewer Flamespewer is offline
Freshman
 
Join Date: Sep 2008
Posts: 35
Default


MAKE SURE TO SET YOUR FORM AND ALL YOUR PICTUREBOXES SCALEMODE TO 3-PIXEL AND AUTOREDRAW PROPERTY TO TRUE

try putting this into a module
Code:
Public Declare Function BitBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As
	Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As
	Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As
	Long, ByVal dwRop As Long) As Long
also add this
Code:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
i'd make a spin function that way everytime you want to spin the wheel you just have to call that function

Code:
Private Sub spinWheel()
    i = 0 'variable for the number the control array is on
    While i < 25'less than max of control array
         BitBlt Form1.hdc, 0, 0, 16, 16, Frame(i).hdc, 0, 0, vbSrcCopy'copy the image from the frame to the form
        Form1.Refresh'refresh the form
        sleep(100)'add a delay so you can see animation
        i = i + 1'increase i 
    Wend
End Sub
Form1.hDC-this part is the the destination of the image, in this case the form but it can be a picturebox too. .hdc must be added.

0, 0,-this is where, on the destination, we want to put the desired image. 0

16, 16 ,frame(i).hDC- this is the size of the image you want to blt, followed by the source of the image with .hdc.

0, 0-this is the x and y point you want to start bitblting from the source. just leave these at 0,0 to get the whole image.

vbSrcCopy-Copies an image exactly onto the form


here's a working example.
if you stretch the form out you can see the frames i used
Attached Files
File Type: zip Spin.zip (4.2 KB, 32 views)

Last edited by Flamespewer; 06-06-2009 at 10:11 PM.
Reply With Quote
  #5  
Old 06-06-2009, 11:40 PM
SFMK SFMK is offline
Newcomer
 
Join Date: May 2009
Posts: 6
Default

Thanks Flamespewer for that code - it worked!
Reply With Quote
  #6  
Old 06-07-2009, 02:08 PM
Euroclydon's Avatar
Euroclydon Euroclydon is offline
Regular
 
Join Date: May 2009
Location: Northern Indiana, USA
Posts: 70
Default

Awesome! "It works!" is possibly my favorite phrase in programming.

Besides, of course, "it's finished..."

Thanks to Flamespewer from me, too.
__________________
"Have a place for everything and keep the thing somewhere else; this is not a piece of advice, it is merely a custom." - Mark Twain
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help
 
Wheel of Fortune -Flickering Animation Help
Wheel of Fortune -Flickering Animation Help
 
-->