- XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
- Kurt Jaegers
- 265字
- 2021-08-20 15:50:42
Time for action – fading pieces
- Add a new class to the Flood Control project called
FadingPiece
. - Add the following line to indicate that
FadingPiece
also inherits fromGamePiece
:Inherits GamePiece
- Add the following declarations to the
FadingPiece
class:Public AlphaLevel As Single = 1.0 Public Shared AlphaChangeRate As Single = 0.02
- Add a constructor for the
FadingPiece
class as follows:Public Sub New(type As String, suffix As String) MyBase.New(type, suffix) End Sub
- Add a method to update the piece:
Public Sub UpdatePiece() AlphaLevel = MathHelper.Max(0, AlphaLevel - AlphaChangeRate) End Sub
What just happened?
The simplest of our animated pieces, the FadingPiece
only requires an alpha value (which always starts at 1.0f
, or fully opaque) and a rate of change. The FadingPiece
constructor simply passes the parameters along to the base constructor.
When a FadingPiece
is updated, alphaLevel
is reduced by alphaChangeRate
, making the piece more transparent.
Managing animated pieces
Now that we can create animated pieces, it will be the responsibility of the GameBoard
class to keep track of them. In order to do that, we will define a Dictionary
object for each type of piece.
A Dictionary
is a collection object similar to a List
, except that instead of being organized by an index number, a Dictionary
consists of a set of key and value pairs. In an array or a List
, you might access an entity by referencing its index as in dataValues(2) = 12
. With a Dictionary
, the index is replaced with your desired key type. Most commonly, this will be a string value. This way, you can do something like fruitColors("Apple")="red"
.
- Python數(shù)據(jù)分析入門:從數(shù)據(jù)獲取到可視化
- 大數(shù)據(jù)算法
- 數(shù)據(jù)化網(wǎng)站運營深度剖析
- WS-BPEL 2.0 Beginner's Guide
- 深度剖析Hadoop HDFS
- Remote Usability Testing
- 圖數(shù)據(jù)實戰(zhàn):用圖思維和圖技術解決復雜問題
- 視覺大數(shù)據(jù)智能分析算法實戰(zhàn)
- 區(qū)塊鏈技術應用與實踐案例
- 二進制分析實戰(zhàn)
- 實現(xiàn)領域驅(qū)動設計
- 企業(yè)級大數(shù)據(jù)項目實戰(zhàn):用戶搜索行為分析系統(tǒng)從0到1
- 區(qū)塊鏈應用開發(fā)指南:業(yè)務場景剖析與實戰(zhàn)
- 云原生架構(gòu):從技術演進到最佳實踐
- 標簽類目體系:面向業(yè)務的數(shù)據(jù)資產(chǎn)設計方法論