WPF实时渲染 [英] WPF real-time rendering

查看:30
本文介绍了WPF实时渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一款游戏并考虑使用 WPF 制作基本游戏玩法的简单原型.

I'm designing a game and thinking about using WPF for making a simple prototype of the basic gameplay.

是否可以在 WPF 中实时渲染基本的 2d 图形?基本图形是指简单的形状,例如线条、圆形等.实时"是指根据速度、加速度等参数渲染事物,这些参数会根据玩家输入而变化 - 我认为这意味着我可以不要在动画中使用故事板.

Is it possible to render basic 2d-graphics in WPF in real-time? By basic graphics I mean simple shapes such as lines, circles, etc. By "real-time" I mean things are rendered based on parameters such as velocity, acceleration, etc. that changes depending on player input - which I assume means I can't use storyboards for the animations.

谢谢

推荐答案

查看上一个问题 使用 WPF 视觉层的高性能图形 进行了很好的相关讨论.虽然 WPF 为丰富的矢量图形提供了一个很好的框架,但它在实时 2D 性能方面有所欠缺.

Check out the previous question High Performance Graphics using the WPF Visual Layer for a good related discussion. While WPF provides a great framework for rich vector graphics, it lacks somewhat for real-time 2D performance.

例如,根据您的场景复杂性,您可以使用DrawingVisuals 或虚拟化的 Shape 类(WPF 矢量图形)来绘制您的精灵.再低一点,您可以使用 BitmapCache 模式在 .NET4.0 中可用,或者将它们预渲染到位图并使用各种 优化模式 以提高吞吐量.

There are workarounds, for instance, depending on your scene complexity you may get away with using DrawingVisuals or virtualized Shape classes (WPF Vector graphics) to draw your sprites. Going a little lower level, you could cache sprites using the BitmapCache mode available in .NET4.0, or pre-prendering them to Bitmaps and using various optimization patterns to improve throughput.

再低一点,您可以使用出色的 WriteableBitmapEx 项目或矢量混合矢量/光栅图形/GPU 图形使用 D3DImage.

Going lower level still, you can mix Vector/Raster graphics using the fantantastic WriteableBitmapEx project, or Vector/GPU graphics using the D3DImage.

关于如何更新场景,您需要在 CompositionTarget.Rendering 事件(在屏幕重绘时触发)您将获得更新的参数并计算精灵的位置/方向.这个伟大的 codeplex 项目 可能对此有所帮助,它集成了 WPF/Silverlight 和 Farseer 物理.

Regarding how to update your scene, you'll need to write a primitive game engine where on the CompositionTarget.Rendering event (fired on redraw of the screen) you get the updated parameters and compute positions/orientations of your sprites. Something that might help with this is this great codeplex project which integrates WPF/Silverlight and Farseer physics.

这篇关于WPF实时渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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