0
我正在開發Windows手機遊戲,並且我在精靈機芯方面遇到困難。 當我只有一個快速觸摸和釋放時,我想要做的是讓精靈逐漸移動到屏幕上觸摸的位置。 現在我所能做的就是讓精靈立刻跳到觸摸位置,或者在觸摸按下時移動到觸摸位置。XNA Windows Phone 7雪碧機芯
代碼跳轉到觸摸的位置:在觸摸的狀態
TouchCollection touchCollection = TouchPanel.GetState();
foreach (TouchLocation tl in touchCollection)
{
if ((tl.State == TouchLocationState.Pressed)
|| (tl.State == TouchLocationState.Moved))
{
Vector2 newPos = new Vector2(tl.Position.X,tl.Position.Y);
if (position != newPos)
{
while (position.X < newPos.X)
{
position.X += (float)theGameTime.ElapsedGameTime.Milliseconds/10.0f * spriteDirectionRight;
}
}
}
}
代碼逐漸沿着移動:
TouchCollection touchCollection = TouchPanel.GetState();
foreach (TouchLocation tl in touchCollection)
{
if ((tl.State == TouchLocationState.Pressed)
|| (tl.State == TouchLocationState.Moved))
{
Vector2 newPos = new Vector2(tl.Position.X,tl.Position.Y);
if (position != newPos)
{
position.X += (float)theGameTime.ElapsedGameTime.Milliseconds/10.0f * spriteDirectionRight;
}
}
}
這些都是在Sprite類的Update()方法。
「操作員‘*’不能應用於類型的操作數‘無效’和‘浮動’」它給我這個錯誤爲Vector2 distanceToMove = delta.Normalize()*(float)theGameTime.ElapsedGameTime.Milliseconds * 10f;「 –
好吧抱歉我修復了它,忘了Normalize修改了現有的Vector2並且沒有返回一個。我去跑它,這一個已經過測試。 –
這很好,謝謝。 –