移動
Storyboard storyboard = new Storyboard();//建立X軸方向動畫DoubleAnimation doubleAnimation = new DoubleAnimation(0,100,new Duration(TimeSpan.FromMilliseconds(500)));Storyboard.SetTarget(doubleAnimation, rect);Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Left)"));storyboard.Children.Add(doubleAnimation);
storyboard.Begin();
//註冊介面重新整理事件Loaded
CompositionTarget.Rendering +=newEventHandler(Timer_Tick); //勻速
rivatevoid Timer_Tick(object sender,EventArgs e) { }
//定義線程 迴圈
DispatcherTimer dispatcherTimer =newDispatcherTimer(DispatcherPriority.Normal);
dispatcherTimer.Tick +=newEventHandler(Timer_Tick);
dispatcherTimer.Interval =TimeSpan.FromMilliseconds(50);//重複間隔
dispatcherTimer.Start();
-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------------------------------
圖片截取
image.Soruce=new BitmapImage(new Uri(@"Player\" + count + ".png", UriKind.Relative));private BitmapSource cutImage(string imgaddress, int x, int y, int width, int height) { return new CroppedBitmap( BitmapFrame.Create(new Uri(imgaddress, UriKind.Relative)), new Int32Rect(x, y, width, height) );}
迴圈給二維數組賦值
privatebyte[,] Matrix =
newbyte[1024, 1024];
for (int y = 0; y < Matrix.GetUpperBound(1); y++) {
for (int x = 0; x < Matrix.GetUpperBound(0); x++) {
Matrix[x, y] = 1;
}
}
SL游標
public
static Cursor[] GameCursors =
new Cursor[4];
///<summary>
///返回指定標號游標
///</summary>
///<param name="sign">標號</param>
///<returns>游標</returns>
public
static Cursor getCursor(int sign) {
if (GameCursors[sign] ==
null) {
GameCursors[sign] = new
Cursor(new
FileStream(string.Format(@"Cursors\{0}.ani", sign),
FileMode.Open, FileAccess.Read,
FileShare.Read));
}
return GameCursors[sign];
}