加框和PC在XNA缩放 [英] Letterboxing AND Scaling in XNA on PC

查看:172
本文介绍了加框和PC在XNA缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法,我基本上可以发展自己的XNA游戏在1080(或720p)作为我的默认分辨率,然后根据所设置的分辨率只是规模在比赛中适当大小的一切,而不必设置比例因子的方法在每一个雪碧draw()方法?

Is there a way that I could basically develop my XNA game at 1080p (or 720p) as my default resolution and then depending upon the set resolution just scale everything in the game to the proper size, without having to set the scaling factor in every Sprite Draw() method?

我的想法是这样的,我可以开发所有的图形,配置坐标等基于1080的分辨率,但随后为Xbox刚才设置的资源为720p,并通过自动遮幅的决议,认为缩小(这样XBOX看到的一切,是在720,因此在开发者文档中提到处理所有分辨率),并在PC上规模,任何需要的分辨率或宽高比这不是16:9

My thought is that, I could develop all the graphics, configure coordinates, etc based on a resolution of 1080p but then for the XBOX just set the res to 720p and scale down (so that the XBOX sees everything as being at 720 and therefore handles all resolutions as mentioned in the developer docs) and on PC scale to any needed resolution or aspect ratio by automatically letterboxing the view for resolutions that are not 16:9.

我已经有我的游戏设置,使spritebatch.begin()和end()被称为最高级别,周围所有的其他绘制调用,这样我可以在技术上只是调整矩阵传有,但每当我这样做,它会做一些奇怪的喜欢使视图偏离中心,或者只占据屏幕的四分之一。

I already had my game setup so that spritebatch.begin() and end() were called at the highest level, around all the other Draw calls, so that I could technically just pass in the scaling matrix there, but whenever I do that it will do something weird like make the view off center, or only take up a quarter of the screen.

有没有一种最佳实践的方式实现这一目标?

Is there a best practice way for achieving this?

推荐答案

如果您设置一个缩放矩阵 SpriteBatch.Begin ,那么它将缩放大小的和绘制,与每一个精灵的位置 SpriteBatch ,直到你调用结束

If you set a scaling matrix in SpriteBatch.Begin, then it will scale the sizes and positions of every single sprite you draw, with that SpriteBatch, up until you call End.

SpriteBatch 使用客户端的空间,零是视窗的左上角,并且在空间中的一个单位相当于在视口中的一个像素。

SpriteBatch uses a client space where zero is the upper left corner of the Viewport, and one unit in that space is equivalent to one pixel in the viewport.

当你给 SpriteBatch A变换,你画会有这种转变适用于他们对你来说,他们是前精灵画。所以,你可以(也应该)使用相同的技术来的翻译的场景(居中它放在你的播放器,例如)。

When you give SpriteBatch a transformation, the sprites that you draw will have that transformation applied to them for you, before they are drawn. So you can (and should) use this same technique to translate your scene (to centre it on your player, for example).

您的游戏在720p的发展,你使用 SpriteBatch 没有转变。你必须要在右下角为中心的精灵。比方说,它的质地(32,32)像素和精灵的原产地为(16,16)(起点在纹理空间指定的,所以这是精灵的中心)。精灵的位置是(1280,720)。精灵的比例 1,这使得其产生的大小(32,32)。你会看到精灵的左上角季度在屏幕的右下角。

Your game is developed at 720p and you're using SpriteBatch without a transformation. You have a sprite centred at the bottom right corner. Let's say its texture is (32, 32) pixels and the sprite's origin is (16, 16) (origin is specified in texture space, so this is the centre of the sprite). The sprite's position is (1280, 720). The sprite's scale is 1, which makes its resulting size (32, 32). You will see the top left quarter of the sprite at the bottom-right corner of your screen.

现在你移动到屏幕是1080(720p以上的1.5倍)。如果你的的屏幕三分之二添加比例矩阵 SpriteBatch ,你可以看到整个精灵,以其,向右向下。

Now you move to a screen that is 1080p (1.5 times bigger than 720p). If you don't add a scaling matrix to SpriteBatch, you can see the whole sprite, with its at two-thirds of the screen, rightwards and downwards.

不过,要扩大你的整个场面,这样在1080它看起来就像它没有以720p。所以你添加矩阵 Matrix.CreateScale(1.5F,1.5F,1F)(以1为Z轴笔记,因为这是不2D 3D),在 SpriteBatch.Begin ,做的闲来无事

But you want to scale up your whole scene so that at 1080p it looks just like it did at 720p. So you add the matrix Matrix.CreateScale(1.5f, 1.5f, 1f) (note using 1 for Z axis, because this is 2D not 3D) to your SpriteBatch.Begin, and do nothing else.

现在你的精灵的场景将被缩小1.5倍大。而不进行任何更改实际绘图电话,你的精灵会在位置(1920,1080)(屏幕右下角)绘制,其规模将是(更大的48,48)(1.5倍),和它的起源将仍然是中心。你会看到精灵的左上象限在屏幕的右下角,就像你在720P,并在同一相对大小。

Now your scene of sprites will be scaled 1.5 times bigger. Without making any changes to the actual Draw call, your sprite will be drawn at position (1920, 1080) (the bottom right corner of the screen), its size will be (48, 48) (1.5 times bigger), and its origin will still be the centre. You will see the sprite's top-left quadrant at the bottom-right corner of your screen, just like you did at 720p, and at the same relative size.

这篇关于加框和PC在XNA缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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