0

これが正しいのか、変更する必要があるのか​​ 疑問に思っていますか?

メイン コードで描画しているタイルの数を変更したいとき、またはレンダリング ターゲットを変更したいときはいつでも、これらを呼び出す予定です。基本的に、自由にサーフェスを渡して、任意のタイプのサーフェスを返してもらいたいと思っています。それを開始することを心配する必要はありません

私のこのコードのもう 1 つの質問: 私が返すサーフェスは、新しい COPY をインスタンス化しますか、それとも、それをインスタンス化した関数内から作成されたものと同じインスタンスが与えられますか? ありがとうございました。

また、new_texture を呼び出すかどうかを知る必要があります。次に、そのテクスチャ サーフェスに大量のスプライト バッチを実行してから、レンダリングしたいだけではなく、テクスチャ サーフェスにレンダリングすることにしました。描画ループの最後で描画関数内から base.draw() を呼び出すと、いつ何が起こるか、スプライトバッチを 1 つの表面テクスチャにレンダリングする必要がある game.draw() の前に 2 セットのスプライトバッチを呼び出します。それから別のもの、特定の順序で?レンダリングの順序がめちゃくちゃになりますか、それとも問題になりませんか? これを行う代わりの方法はありますか?提案を受け付けていますか?

もう 1 つの問題として、draw_texture 関数を呼び出すと、グラフィックス デバイスが null であることがわかります。どうしてか分かりません!!!!

これがコードです

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace TileEngine
{
    class Renderer
    {
        GraphicsDevice mydevice;
        public SpriteBatch spriteBatch;



        RenderTarget2D new_texture(int width, int height, RenderTarget2D Mine)
        {
            Texture2D TEX = new Texture2D(mydevice, width, height);   //create the texture to render to
            mydevice.SetRenderTarget(Mine); //set the render device to the reference provided
                //maybe base.draw can be used with spritebatch. Idk. We'll see if the order of operation
                    //works out. Wish I could call base.draw here.
            return Mine;    //I'm hoping that this returns the same instance and not a copy.

        }

        void draw_texture(int width, int height, RenderTarget2D Mine)
        {
            mydevice.SetRenderTarget(null); //Set the renderer to render to the backbuffer again
            Rectangle drawrect = new Rectangle(0, 0, width, height); //Set the rendering size to what we want
            spriteBatch.Begin();                        //This uses spritebatch to draw the texture directly to the screen  
            spriteBatch.Draw(Mine, drawrect, Color.White); //This uses the color white
            spriteBatch.End();      //ends the spritebatch
            //Call base.draw after this since it doesn't seem to recognize inside the function
            //maybe base.draw can be used with spritebatch. Idk. We'll see if the order of operation
            //works out. Wish I could call base.draw here.
        }


    }
}
4

0 に答える 0