0
我正在Silverlight中開發簡單的捕捉應用程序(在Blend 4中)。你知道如何簡單地解決墜落物體從頂部到底部進入白色矩形的物體碰撞?圖片 - http://img94.imageshack.us/img94/8200/svlk.jpgSilverlight - 遊戲碰撞對象
感謝
當前代碼:
public partial class MainPage : UserControl
{
int skore=0;
public MainPage()
{
InitializeComponent();
chytac.Visibility=Visibility.Collapsed;
}
private void UserControl_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
String k=e.Key.ToString();
klavesa.Content=k;
if(e.Key.ToString().Equals("Left")){
double x=Canvas.GetLeft(chytac);
x=x-20;
if(x>0){
Canvas.SetLeft(chytac,x);
}
}
if(e.Key.ToString().Equals("Right")){
double x=Canvas.GetLeft(chytac);
x=x+20;
if(x<650){
Canvas.SetLeft(chytac,x);
}
}
}
private void start_Click(object sender, System.Windows.RoutedEventArgs e)
{
chytac.Visibility=Visibility.Visible;
start.Visibility=Visibility.Collapsed;
}
private void random_Click(object sender, System.Windows.RoutedEventArgs e)
{
Random random = new Random();
//pocitadlo++;
//score.Content=pocitadlo.ToString();
telefon novy = new telefon();
LayoutRoot.Children.Add(novy);
Canvas.SetTop(novy, 0);
Canvas.SetLeft(novy, random.Next(0,650));
Canvas.SetZIndex(novy, -50);
bomba bomba=new bomba();
LayoutRoot.Children.Add(bomba);
Canvas.SetTop(bomba, 0);
Canvas.SetLeft(bomba, random.Next(0,650));
Canvas.SetZIndex(bomba, -50);
}
}
你目前有什麼代碼,如果有的話? – ChrisF 2010-12-11 11:45:16
我已經添加了我的代碼 - telefon和bomba是隨機點擊按鈕後生成的對象,chytac是對底部陰影對象的矩形 – Waypoint 2010-12-11 12:22:36
我將「random」的聲明和初始化移出click方法。否則,如果用戶頻繁點擊,您將得到非隨機結果。 – ChrisF 2010-12-11 12:31:14