0

そのため、レンダー ターゲットからの結果を色の配列に格納して、反復子で個別に操作できるようにしようとしています。何らかの理由で、以下のコードは配列内のすべての値を R=0、G=0、B=0、A=0 に設定します。まるで初期化されていないかのように。GetData メソッドの使い方が間違っていませんか? それは何か他のものですか?それは非常にカラフルな画像でなければならず、絶対に透明ではありません.

問題は、テクスチャが正しく描画されていないことではなく、レンダー ターゲットを設定せずに (デフォルトのバックバッファを使用して) コードを実行したところ、ゲームは完全に正常に実行されました。

            //Creating a new render target and setting it
        RenderTarget2D unprocessed = new RenderTarget2D(graphics.GraphicsDevice, Window.ClientBounds.Width, Window.ClientBounds.Height,false,SurfaceFormat.Color,DepthFormat.Depth24,4,RenderTargetUsage.PreserveContents);
        graphics.GraphicsDevice.SetRenderTarget(unprocessed);

        //Drawing background and main player
        spriteBatch.Draw(bgTex,new Rectangle(0,0,Window.ClientBounds.Width,Window.ClientBounds.Height),Color.White);
        mainPlayer.Draw(spriteBatch);

        //resetting render target
        graphics.GraphicsDevice.SetRenderTarget(null);

        //creating array of Color to copy render to
        Color[] baseImage = new Color[Window.ClientBounds.Width * Window.ClientBounds.Height];
        //I pause the program here and baseImage is an array of black transparent colors
        unprocessed.GetData<Color>(baseImage);

        spriteBatch.End();
4

2 に答える 2

0

問題が解決しました。基本的に、黒である理由は、レンダリングターゲットがデータを取得する前にスプライトバッチを最初に終了する必要があるためです。そのため、スプライトバッチプロセス中、カラー値はまだ黒です。それを修正するために私がしたことは、描画が発生する直前と直後にスプライトバッチを開始および終了させ、それによって問題がすぐに修正されました。

于 2012-06-28T02:59:00.800 に答える
0

いくつか問題があると思います。1つ目は、レンダリングターゲットにアクセスする前にspriteBatch.End()を呼び出す必要があることです。また、spriteBatch.Begin()の呼び出しがないことに気づきました。

RenderTarget2D unprocessed = new RenderTarget2D( /*...*/);
graphics.GraphicsDevice.SetRenderTarget(unprocessed);
graphics.GraphicsDevice.Clear(Color.Black);

//Drawing
spriteBatch.Begin();
spriteBatch.Draw(/*...*/);
spriteBatch.End();

//Getting
graphics.GraphicsDevice.SetRenderTarget(null);

あなたはあなた自身の質問に答えたばかりなので……気にしないでください。

于 2012-06-28T02:59:35.793 に答える