转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> VB.NET程序 >> 正文
Drawing & Animation III         ★★★★

Drawing & Animation III

作者:闵涛 文章来源:闵涛的学习笔记 点击数:4669 更新时间:2009/4/23 16:39:28
p;  ''''Now draw from the beginning again
    BitBlt picBack.hdc, EndScroll, 0, GlueWidth, ABBackHeight, DCABBAck, 0, 0, vbSrcCopy
Else
    BitBlt picBack.hdc, 0, 0, ScrollWidth, ABBackHeight, DCABBAck, X, 0, vbSrcCopy
End If

''''Draw the first back ground
If XBack1 + ScrollWidth > Back1Width Then ''''We ned to glue at the beginnig again

    ''''Calculate the remaining width
    GlueWidth = XBack1 + ScrollWidth - Back1Width
    EndScroll = ScrollWidth - GlueWidth

    ''''Blit the first part
    BitBlt picBack.hdc, 0, ABBackHeight - Back1Height, EndScroll, Back1Height, _
           DCBack1M, XBack1, 0, vbSrcAnd

    BitBlt picBack.hdc, 0, ABBackHeight - Back1Height, EndScroll, Back1Height, _
           DCBack1, XBack1, 0, vbSrcPaint

    ''''Now draw from the beginning again
    BitBlt picBack.hdc, EndScroll, ABBackHeight - Back1Height, GlueWidth, _
           Back1Height, DCBack1M, 0, 0, vbSrcAnd

    BitBlt picBack.hdc, EndScroll, ABBackHeight - Back1Height, GlueWidth, _
           Back1Height, DCBack1, 0, 0, vbSrcPaint
Else

    BitBlt picBack.hdc, 0, ABBackHeight - Back1Height, ScrollWidth, Back1Height, _
           DCBack1M, XBack1, 0, vbSrcAnd

    BitBlt picBack.hdc, 0, ABBackHeight - Back1Height, ScrollWidth, Back1Height, _
           DCBack1, XBack1, 0, vbSrcPaint
End If

''''Draw the sprite
BitBlt picBack.hdc, XSprite, ABBackHeight - SpriteHeight, SpriteWidth, _
           SpriteHeight, DCSpriteM, 0, 0, vbSrcAnd

BitBlt picBack.hdc, XSprite, ABBackHeight - SpriteHeight, SpriteWidth, _
           SpriteHeight, DCSprite, 0, 0, vbSrcPaint

''''Draw the fore ground
If XFore + ScrollWidth > ForeWidth Then ''''We ned to glue at the beginnig again

    ''''Calculate the remaining width
    GlueWidth = XFore + ScrollWidth - ForeWidth
    EndScroll = ScrollWidth - GlueWidth
    ''''Blit the first part

    BitBlt picBack.hdc, 0, ABBackHeight - ForeHeight, EndScroll, ForeHeight, _
           DCForeM, XFore, 0, vbSrcAnd

    BitBlt picBack.hdc, 0, ABBackHeight - ForeHeight, EndScroll, ForeHeight, _
           DCFore, XFore, 0, vbSrcPaint

    ''''Now draw from the beginning again
    BitBlt picBack.hdc, EndScroll, ABBackHeight - ForeHeight, GlueWidth, ForeHeight, _
           DCForeM, 0, 0, vbSrcAnd

    BitBlt picBack.hdc, EndScroll, ABBackHeight - ForeHeight, GlueWidth, ForeHeight, _
           DCFore, 0, 0, vbSrcPaint
Else
    BitBlt picBack.hdc, 0, ABBackHeight - ForeHeight, ScrollWidth, ForeHeight, _
           DCForeM, XFore, 0, vbSrcAnd

    BitBlt picBack.hdc, 0, ABBackHeight - ForeHeight, ScrollWidth, ForeHeight, _
           DCFore, XFore, 0, vbSrcPaint
End If

''''Draw the back buffer onto the display
BitBlt Me.hdc, 0, 0, ScrollWidth, ABBackHeight, picBack.hdc, 0, 0, vbSrcCopy

Me.Refresh

''''Modify the positions.
X = (X Mod ABBAckWidth) + 1
XBack1 = (XBack1 Mod Back1Width) + 8
XFore = (XFore Mod ForeWidth) + 25

End Sub

The X position on the different layers is controlled by a separate variable. This enables us to move the layers with different speeds, which further enhances the illusion of depth and distance.

Star field background

Another often-used background is a star field background, which as the name implies simulates a moving star field. The most efficient method when it comes to speed is of course to make a bitmap and then draw it directly onto the gaming as the absolute background. Another and more fun method is to randomly generate dots and small circles on the drawing area.

The sample project STARFIELD in STARFIELD.ZIP demonstrates how to create a simple star field of small circles and dots. To represent a star we create a type called Star and declare it as follows:


Private Type Star
    X As Long
    Y As Long
    Speed As Long
    Size As Long
    Color As Long
 End Type

 

The X and Y members are the position of the star. The size is the diameter of the star in pixels. The Speed is the amount of pixels the star moves each turn. The color is the color of the star.

To represent the stars in this sample project we have an array of Star Types (called Stars). This array is initialized in the Load event of the form:

Private Sub Form_Load()

Dim I As Long

Randomize
''''Generate the 100 stars
For I = LBound(Stars) To UBound(Stars)
   
    Stars(I).X = Me.ScaleWidth * Rnd + 1
    Stars(I).Y = Me.ScaleHeight * Rnd + 1
    Stars(I).Size = MaxSize * Rnd + 1
    Stars(I).Speed = MaxSpeed * Rnd + 1
    Stars(I).Color = RGB(Rnd * 255 + 1, Rnd * 255 + 1, Rnd * 255 + 1)
Next I

End Sub

 


Each individual star is initialized to a random value within the bounds of the window.

The stars are drawn in the timer event, using the Ellipse API function.


Private Sub TimerStarField_Timer()

Dim I As Long

''''clear the form
BitBlt Me.hdc, 0, 0, Me.ScaleWidth, Me.ScaleHeight, 0, 0, 0, vbBlackness

For I = 0 To UBound(Stars)
   
    ''''Move the star
    Stars(I).Y = (Stars(I).Y Mod Me.ScaleHeight) + Stars(I).Speed
    ''''Relocate the X position
    If Stars(I).Y > Me.ScaleHeight Then
      Stars(I).X = Me.ScaleWidth * Rnd + 1
    End If
    ''''Set the color
    Me.FillColor = Stars(I).Color
    Me.ForeColor = Stars(I).Color
    ''''Draw the star
    Ellipse Me.hdc, Stars(I).X, Stars(I).Y, Stars(I).X + Stars(I).Size, Stars(I).Y + Stars(I).Size

Next I

End Sub

 

The BitBlt outside the loop makes the background of the window black, using the vbBlackness raster operation. The stars are moved using the usual operation. If a star goes out of bounds, compared to the scale height of the window, the X position of the star will be changed, in order to created more randomness. The Ellipse function simply takes two parameters, the first pair defining the upper-left 慶orner?of the circle, the second defining the lower-right 慶orner?

 

The Game Loop

So far we have been using the timer control to continuously execute the so-called game loop. The Game Loop is where everything is being controlle

上一页  [1] [2] [3] [4] [5] [6]  下一页


[Sql Server]Sql精妙语句--各种求值函数  [网页制作]网页表格之---多个表格纵向排列
[网页制作]JavaScript另类用法--读取和写入cookie  [网页制作]号称非常安全的上网工具---360安全浏览器介绍
[办公软件]信息技术教学篇---Word工具栏的显示、隐藏及四种菜…  [操作系统]开始菜单---运行命令大总结
[操作系统]网络转载---64位操作系统与32位的区别  [操作系统]ldap:///(没有响应)Windows无法访问指定设备、路径…
[网络技术]安全篇---交换机设置方法介绍  [聊天工具]Real10 & Xpdf installation on Linux Box
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台