1
A
回答
2
1
當你加載你的形象,你需要一個BoundingBox的或矩形對象來控制它在哪裏。
因此,在手機上的XNA應用程序中,應該爲紋理聲明幾個對象。
Texture2D texture;
BoundingBox bBox;
Vector2 position;
bool selected;
然後,在加載圖像內容後,請使用圖像位置更新邊界框。
bBox.Min = new Vector3(position, 1.0f);
bBox.Max = new Vector3(position.X + texture.Width, position.Y + texture.Height, 0f);
也會顯示在您更新方法,你應該有一個觸摸集合初始化爲從畫面處理輸入,得到了觸摸集合的位置,依次通過他們,看看他們是否相交您的外接矩形框。
foreach (Vector2 pos in touchPositions)
{
BoundingBox bb = new BoundingBox();
bb.Min = new Vector3(pos, 1.0f);
bb.Max = new Vector3(pos, 0f);
if (bb.Intersects(bBox)
{
if (selected)
{
//do something
}
else
{
selected = true;
}
}
}
從那裏,你有你的對象是否被選中或沒有。然後,只需使用手勢事件來確定您想要對紋理對象執行什麼操作。
3
這是另一種簡單的拖動方法。 只需繪製您的圖像(Texture2d)相對於矩形而不是Vector2。 您的圖片變量應該是這樣的
Texture2d image;
Rectangle imageRect;
在draw()方法對於「imageRect」畫出你的形象。
spriteBatch.Draw(image,imageRect,Color.White);
現在在Update()方法中用單點觸摸輸入處理圖像。
//Move your image with your logic
TouchCollection touchLocations = TouchPanel.GetState();
foreach(TouchLocation touchLocation in touchLocations)
{
Rectangle touchRect = new Rectangle
(touchLocation.Position.X,touchLocation.Position.Y,10,10);
if(touchLocation.State == TouchLocationState.Moved
&& imageRect.Intersects(touchRect))
{
imageRect.X = touchRect.X;
imageRect.Y = touchRect.Y;
}
//you can bring more beauty by bringing centre point
//of imageRect instead of initial point by adding width
//and height to X and Y respectively and divide it by 2
相關問題
- 1. 在flex中拖動圖像
- 2. 在WPF中拖動圖像
- 3. 拖動圖像?
- 4. 拖動圖像
- 5. 在UIScrollView上拖動圖像
- 6. 從滾動視圖中拖動圖像
- 7. Android拖動圖像
- 8. 從圖像中動態創建XNA sprite
- 9. 圖像拖動導致按鈕拖動
- 10. 在Unity3d中拖動UI圖像(C#)
- 11. 在Android中觸摸並拖動圖像
- 12. 在拖放中移動圖像
- 13. 在QListView中禁用拖動圖像
- 14. 在GWT 2.4中設置拖動圖像
- 15. 拖動圖像視圖
- 16. XNA正在拖動錯誤的紋理?
- 17. Java拖放圖像並拖動時顯示圖像縮略圖
- 18. 拖動圖片,但從可拖動的圖像中拖放名稱元素
- 19. Android拖放 - 圖像沒有被拖動
- 20. Android的拖放(不能拖動圖像)
- 21. 如何在iOS中拖動圖像時在另一圖像上重疊圖像?
- 22. 在Chrome中拖放圖像
- 23. 在java中拖放圖像
- 24. 插入圖像拖動
- 25. IOS:拖動多個圖像
- 26. 拖動邊界圖像
- 27. 兩個圖像拖動
- 28. 從uitableview拖動圖像
- 29. 圖像拖動父遏制
- 30. 如何拖動圖像
注意這不適用於Windows Phone 7 – Wade