2016-11-23 15 views
0

私はスタックオーバーフローとVB.NET(Cから来ている)の両方に慣れていますので、この1つで私に負担してください:)
私は作っています私のプログラミングクラスの課題としてハングマンのゲームを公開しました。パブリッククラスのキャラクターを作成しました。公共の機能の死()アクションとして プレイヤーは、それぞれ異なる死を持つさまざまなキャラクターから選ぶことができますアニメーション、私は(死をしたいのですが)何度もストップモーションスタイルで文字画像を変更、例えばクラス機能を変更するにはどうすればいいですか?

Death(){ 
    pictureboxchar.image(1.png) 
    pictureboxchar.image(2.png) 
    pictureboxchar.image(3.png) 
    pictureboxchar.image(4.png) 
} 

しかし、私は、私が代わりに参照すべきものにと全くわからないんだけどの "pictureboxchar"。たぶん私はクラス名キャラクター自体を参照する必要がありますか? これを達成したいと思います。キャラクターのカスタムクラスを作成すると、余分なクレジットが得られます。これは私が持っているものである

Public Class Character 
    Public Function Death() As Action 

    End Function 
End Class 

これまで
ありがとうございました!

答えて

0

アニメーションを実現するには、タイマーを使用する必要があります。 Characterクラスはこのように見えます。 4つのPNGファイルは、アプリケーションのスタートアップディレクトリにある必要があります。タイマーの間隔プロパティで遊んで、目的のアニメーション速度を取得します。その値はミリ秒単位であるため、500に設定すると、タイマーのティックイベントは0.5秒ごとに発生します。フォームから

Imports System.IO 
Imports System.Windows.Forms 

Public Class Character 

    Private WithEvents myTimer As New Timer 
    Private iCounter As Int32 
    Private iNumberImages As Int32 = 4 'images must be numbered "1.png", "2.png" etc in the order of animation 
    Private iAnimationSpeed As Int32 = 500 'set to lower value for faster animation 
    Private myPictureBox As PictureBox 
    Private sPictureFileDirectory As String = Application.StartupPath 'the directory where the image files are located 

    Public Sub New(ByVal pictureboxchar As PictureBox) 
     myPictureBox = pictureboxchar 
     myTimer.Interval = iAnimationSpeed 
     myTimer.Enabled = True 
    End Sub 

    Private Sub myTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles myTimer.Tick 
     iCounter += 1 'increment the counter to display the next image in the sequence 
     If iCounter > iNumberImages Then iCounter = 1 'reset the counter to 1 when the maximum number of images is exceeded 
     Dim sFilePath As String = sPictureFileDirectory & "\" & iCounter.ToString & ".png" 
     If File.Exists(sFilePath) = True Then myPictureBox.Image = Image.FromFile(sFilePath) 
    End Sub 

End Class 

、フォームレベルのスコープで文字クラスのインスタンスを作成し、フォームのLoadイベントハンドラでコンストラクタにピクチャボックスを渡します

Private myCharacter As Character 

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load 
    myCharacter = New Character(pictureboxchar) 
End Sub 
関連する問題