通过触摸移动纹理 [英] Moving a Texture via Touch
本文介绍了通过触摸移动纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
Hi guys,
我对编程很感兴趣,虽然了解基础知识。
I relitivly new to programming although do understand the basics.
全部我想要的是基本上通过触摸/手势移动特定图像。由于我将在屏幕上显示多个图像,我需要以某种方式使触摸仅移动触摸的形状。
All im wanting to is basically move a particular image via touch/gestures. As i am going to have more than one image on the screen I need to somehow make the touch only move the shapes which are touched.
可能声音如此
简单但我已经在这一周了一段时间并且无法理解我的头脑它。
Might sound so simple but ive been on this for a week and cant get my head around it.
这是我到目前为止:
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
TouchCollection currentTouchState = TouchPanel.GetState();
foreach (TouchLocation touchLocation in currentTouchState)
{
// The Unique ID of this location
//int touchID = touchLocation.Id;
//Vector2 touchPosition = touchLocation.Position;
TouchLocation currentLocation = currentTouchState[0];
//TouchLocationState touchState = touchLocation.State;
Rectangle shapeArea = new Rectangle((int)(spritePosition.X + 0.5f), (int)(spritePosition.Y + 0.5f),
spriteTexture.Width, spriteTexture.Height);
bool shapeActive = false;
TouchPanel.EnabledGestures = GestureType.DoubleTap | GestureType.FreeDrag;
Point touchPoint = new Point((int)currentLocation.Position.X, (int)currentLocation.Position.Y);
// Loop while there are still gestures to read
while (TouchPanel.IsGestureAvailable)
{
// Read the next gesture
GestureSample gesture = TouchPanel.ReadGesture();
// Switch Statement to determie which gesture has been received
switch (gesture.GestureType)
{
case GestureType.DoubleTap:
rotation += 45 * (MathHelper.Pi / 180);
break;
case GestureType.FreeDrag:
if (shapeArea.Contains(touchPoint))
{
shapeActive = true;
}
else shapeActive = false;
break;
}
if (shapeActive == true)
{
spritePosition = currentLocation.Position;
}
}
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(spriteTexture, spritePosition, null, Color.White,
rotation, spriteCentre, 1, SpriteEffects.None, 0);
spriteBatch.End();
base.Draw(gameTime);
}
推荐答案
Gutted没有人回答这个因为我真的陷入困境并且无法进展直到我拥有这个出问题: - (
Gutted no one has answered to this as really stuck and cant progress till I have this problem out the way :-(
这篇关于通过触摸移动纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文