オブジェクトが動くゲームを作りたい場合は、C#/XAML のパフォーマンスが良くないため、XNA や Unity などのゲーム エンジンを使用することを検討する必要があります。
本当に C#/xaml を使用したい場合は、イメージ コントロールの位置を自分で計算する必要があります。位置を設定するには、キャンバス内に画像を配置し、次のように位置を設定します。
Canvas.SetTop(myControl,XPosition);
Canvas.SetLeft(myControl,YPosition);
StoryBoard を使用してオブジェクトをアニメーション化することもできますが、加速度と方向が変化し続けると、おそらくより複雑になります。
ハードウェア アクセラレーションを利用するには、移動するオブジェクトに CacheMode="BitmapCache" を設定する必要があります。
オブジェクトの位置を計算するコードは次のとおりです。
public class ObjectInfo
{
public Vector2 Position { get; set; }
public Vector2 Speed { get; set; }
public Vector2 Acceleration { get; set; }
}
private DispatcherTimer dispatcherTimer;
private int refreshTimeMilisecond = 100;
private ObjectInfo myObject;
public void Init()
{
myObject = new ObjectInfo();
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(refreshTimeMilisecond);
dispatcherTimer.Tick += dispatcherTimer_Tick;
}
void dispatcherTimer_Tick(object sender, EventArgs e)
{
myObject.Position = myObject.Position + myObject.Speed*refreshTimeMilisecond;
myObject.Speed = myObject.Speed + myObject.Acceleration * refreshTimeMilisecond;
Canvas.SetTop(myControl, myObject.Position.X);
Canvas.SetLeft(myControl, myObject.Position.Y);
}
xaml で:
<Canvas>
<Image x:Name="myControl" CacheMode="BitmapCache" Source="SmyleyImagePath"/>
</Canvas>
最適な動作を見つけるには、refreshTimeMilisecond パラメータをいじる必要があります。