XAML冲突检测 [英] XAML Collision detection

查看:63
本文介绍了XAML冲突检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Windows Phone游戏,并且正在努力减少碰撞检测。

I am working on a Windows Phone game and it is going swimmingly minus collision detection.

有没有一种简单的方法可以建议检测两个XAML对象是否存在在彼此之上?

Is there a simple way that anyone could suggest detecting if two XAML objects are on top of each other?

我知道的唯一方法是创建一个包含游戏中每个可碰撞对象的坐标的列表,然后扫描该列表以确定是否存在碰撞或碰撞。不。

The only method I know of is creating a list that contains the coords of every single collidable object in the game, then scanning the list to determine if there is a collision or not.

借助所有很酷的XAML功能,例如触发器,行为等,我认为可能会有更简单的方法。但是,搜索结果很小。

With all the cool XAML features like triggers, behaviors and such I thought there might be an easier way. However, search results are slim.

有什么想法吗?最简单的就是我要寻找的东西。不需要疯狂。当我的播放器与某个对象碰撞时,它就会消失。

Any ideas? The simplest is what I am looking for. Nothing crazy needed. Just when my player collides with an object it disappears.

我不知道它是否有区别,但是我所有的对象都是图像。

I don't know if it makes a difference but all my objects are images.

推荐答案

没有用于XAML对象冲突检测的内置机制。这很有道理,XAML是为创建应用程序UI而设计的-它不是游戏引擎!

There is no built in mechanism for collision detection with XAML objects. This makes sense, XAML is designed for creating application UIs - it is not a games engine!

您可以尝试Physics Helper框架:

You could try the Physics Helper framework:

http://physicshelper.codeplex.com/

这将添加一个物理引擎,使您可以通过行为将XAML对象转换为物理对象:

This adds a physics engine that allows you to turn XAML objects into 'physics' objects via behaviours:

  <Ellipse Width="100" Height="100" Fill="Red"
            Canvas.Left="80" Canvas.Top="100">
    <!-- make the engine aware of this element -->
    <i:Interaction.Behaviors>
      <pb:PhysicsObjectBehavior />
    </i:Interaction.Behaviors>
  </Ellipse>

我在此框架上玩了很短一段时间:

I had a brief play with this framework a while back:

http://www.scottlogic.co.uk/blog/colin/2011/12/a-festive-and-fun-windows-phone-7-maze-game/

这很好!

这篇关于XAML冲突检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆