3

現在、 MonoGame サンプルの例と同様に、2 つの for ループを使用して Texture2D をタイル張りしています。

私はいくつかの読書をしていましたが、2 の累乗のテクスチャ (幅と高さで 2、4、8、16、32 など) を使用すると、1 回の SpriteBatch.Draw 呼び出しでタイルを張ることができることがわかりました。

これは iOS のモノゲームでサポートされていますか?

何度か試してみましたが、画像をタイリングするのではなく、引き伸ばすだけでした。

SpriteBatch.Begin() で SamplerState.LinearWrap を使用しており、2048x128 の png を使用して、512x32 で 1/4 サイズを試してみましたが、うまくいきませんでした。(大きなサイズを使用すると、b/c ゲームは 2400x で実行されます。何かをズームアウトすると、b/c カメラで 2.5 倍にズームインできます)

4

1 に答える 1

2

You can use the SourceRectangle parameter in the draw method. To define what part of the Texture you want to display. Lets say you have a 128x128 Texture. If you supply Rect(0, 0, 128, 128) you tell the draw method to use the whole texture, the same if you would pass null to the draw method. If you supply Rect(0, 0, 64, 64) you would use the upper left part of the texture. Your sprite will display this portion, no matter how big the sprite itself is. So if your sprite is drawn with the size of 128x128 the 64x64 texture part would be scaled.

Now you can use that for animations. If you store in your texture a sequence of animation like this, you just need to recalc the source rectangle everytime you want to display the next image in your sequence.

Besides that, you could pass in a bigger value, than your source texture. XNA now needs to wrap or clamp your texture. That way you can achieve a simple tiling. If you need more than that my guess is you need to use a manual approach, like your foreach loops. Please note that Wrap is only supported if you use power of two textures.

于 2011-11-14T14:27:03.433 に答える