注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

你想快速掌握安卓编程吗

 
 
 

日志

 
 

[例程]跳动的球体(SpriteAnimator类模块)  

2015-08-19 14:51:08|  分类: B.游戏 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
'SpriteAnimator is a utility class that can move and animate sprites.

Sub Class_Globals
'An array with the source rectangles. This is useful when working with sprite sheets.
Private srcRects() As Rect
'An array with the animation frames.
Private bitmaps() As Bitmap
Private index As Int
Private interval As Int
'Change frame each x ticks
Public AnimationInterval As Int
Public vx, vy As Int
Public width, height As Int
End Sub

Public Sub Initialize
AnimationInterval = 1
End Sub

Public Sub SetFrames(bd As BitmapData, vSrcRects() As Rect, vBitmaps() As Bitmap)
srcRects = vSrcRects
bitmaps = vBitmaps
bd.SrcRect = srcRects(0) 'start with the first frame
bd.Bitmap = bitmaps(0)
index = 0
interval = 0
End Sub

'returns True if the object moved out of the screen (to the bottom).
Public Sub Tick (bd As BitmapData) As Boolean
'move the sprite based on vx and vy
bd.DestRect.Left = bd.DestRect.Left + vx
bd.DestRect.Top = bd.DestRect.Top + vy
'in this game objects that go out of the screen return from the other side:
If vx > 0 AND bd.DestRect.CenterX > 100%x Then 
bd.DestRect.Left = -width / 2
Else If vx < 0 AND bd.DestRect.CenterX < 0 Then
bd.DestRect.Left = 100%x + width / 2
End If
If bd.DestRect.CenterY > 100%y Then
Return False 'moved out of the screen
End If
'Don't forget to update the Right and Bottom properties
bd.DestRect.Right = bd.DestRect.Left + width
bd.DestRect.Bottom = bd.DestRect.Top + height
interval = interval + 1
If AnimationInterval = interval Then
'change the animation frame.
interval = 0
index = (index + 1) Mod bitmaps.Length
bd.SrcRect = srcRects(index)
bd.Bitmap = bitmaps(index)
End If
Return True
End Sub

  评论这张
 
阅读(42)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017