アニメの初歩


初の心  2009-09-03 17:44:24  No: 146269

PictureBox1を右方向に動かそうと思いましたがこのコードでは
ウンともスンともいいません。どこがちがうのでしょうか?

Public Class Form1
    Dim mx As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        mx = PictureBox1.Left
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        If mx > 0 And mx < Me.Width Then
            mx += 5
        End If

    End Sub
End Class


オショウ  2009-09-03 17:49:07  No: 146270

mxが変化しているだけで、PictureBox1.Leftが変化しない
からです。

mx += 5

の部分を

PictureBox1.Left += 5

にでも修正してみて下さい。

以上。


オショウ  2009-09-03 17:50:35  No: 146271

追伸・・・

        If PictureBox1.Left < Me.Width Then
            PictureBox1.Left += 5
        End If

※  mxは不必要・・・

以上。


初の心  2009-09-03 18:40:05  No: 146272

mx = PictureBox1.Left
 PictureBox1の位置を変数mxに代入していることになると
思うのですが?
実際、サンプル(シューティングゲーム)でこのような記述が
あったのですが


bakanisuruhito  2009-09-03 18:55:24  No: 146273

> mx = PictureBox1.Left
>  PictureBox1の位置を変数mxに代入していることになると
> 思うのですが?

うん、それはあってる。
だけど、mxを変化させても、もとのPictureBox1の位置を変化させているわけじゃない。

銀行にあるお金の残高を確認して明細書に印字した。
印字した明細書の数字を書き換えた。
でも、銀行の中にあるお金の残高は変わらない。
そんな感じ。


初の心  2009-09-03 20:39:10  No: 146274

わかりました。とんだ勘違いをしてました。ありがとうございました。


れお  2009-09-07 10:44:12  No: 146275

こんなん作りました。
小学生のママゴト的ですけど。
参考になるかな?
Public Class Form1
    Dim x%, y%, s%
    Dim ransuu As System.Random

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Size = New Size(500, 320)
        PictureBox1.Size = New Size(500, 320)
        PictureBox1.Location = New Point(0, 0)
        PictureBox1.BackColor = Color.Black
        x% = 250 : y% = 250
        ransuu = New System.Random()
        Timer1.Interval = 100
        Timer1.Start()
    End Sub

    Private Sub PictureBox1_Paint1(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        'キャラクター表示
        e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        s = ransuu.Next(2)
        For i As Integer = 0 To 2
            e.Graphics.FillEllipse(Brushes.SkyBlue, x + i * 8, y, 10 + s * 2, 10)
        Next
        e.Graphics.FillEllipse(Brushes.SkyBlue, x + 1, y - 22, 27, 30)
        e.Graphics.FillEllipse(Brushes.White, x + 3, y - 15, 12, 11)
        e.Graphics.FillEllipse(Brushes.Black, x + 5 + s, y - 10, 5, 5)
        '壁
        e.Graphics.FillRectangle(Brushes.Yellow, 0, 220, 40, 43)
        e.Graphics.FillRectangle(Brushes.Yellow, 445, 220, 40, 43)
        e.Graphics.FillRectangle(Brushes.Blue, 0, 260, 490, 25)

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        x -= 3
        If x < 10 Then x = 445
        PictureBox1.Invalidate()
    End Sub
End Class


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加