###前提・実現したいこと
現在、ボールを放物線のように飛ばし、カゴにボールを入れるゲームを作っています。
###発生している問題・エラーメッセージ
今、ボールを放物線で飛ばし、ボールを初期位置まで戻すことはできたのですが、初期位置に戻ってから動かすことができません。
どのようにすれば、繰り返しボールを飛ばすことができますか?教えてください。
エラーメッセージ
###該当のソースコード
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace _1108_ボール_斜方投射
{
public partial class Formballshoot : Form
{
double ballPos_x; double ballPos_y; double vx = 15; //x座標の初速度 double vy = -30; //y座標の初速度 double g = 1.0; //加速度 int ballRadius = 10; //ボールの半径 Timer timer = new Timer(); public Formballshoot() { this.ballPos_x = 10; //x座標の初期位置 this.ballPos_y = 650; //y座標の初期位置 InitializeComponent(); Timer timer = new Timer(); timer.Interval = 50; timer.Tick += new EventHandler(Update); timer.Start(); } private void Update(object sender, EventArgs e) { ballPos_x += vx; vy += g; ballPos_y += vy; //再描写 Invalidate(); //ボールが画面の下を超えた場合 if (ballPos_y > 650) { this.ballPos_x = 10; //x座標の初期位置に戻す this.ballPos_y = 650; //y座標の初期位置に戻す timer.Stop(); } } private void DrawFiguare(object sender, PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //円を描画する SolidBrush brush = new SolidBrush(Color.Red); float px = (float)this.ballPos_x - this.ballRadius; float py = (float)this.ballPos_y - this.ballRadius; e.Graphics.FillEllipse(brush, px, py, this.ballRadius * 2, this.ballRadius * 2); } private void endEToolStripMenuItem_Click(object sender, EventArgs e) { //ゲーム終了 Close(); } }
}
###試したこと
timerを2つ用いてやってみたのですが、ボールの動きが、連続的にならず、飛び飛びになり上手くいきませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
C# windowsForm
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/15 05:36
2017/11/15 05:44
2017/11/16 05:03
2017/11/27 08:01