こんにちはみんな私は少し問題があります。
私はこの 2 DrawableGameComponets
(bigApple、smallApple) を両方にRenderTarget
持っRenderTarget
ていますDrawableGameComponent
。
私が達成したいことは、両方DrawableGameComponents
が適切に重ねて描画されることです。
このようなもの:
これは、両方の drawableComponent があり、各コンポーネントに rendertargets がない画面です。
しかし、その代わりにこれを取得します。
これは、各コンポーネントに rendertargets を持つ drawableComponent の両方を持つ画面です。
これは、私が取り組んでいる小さなゲーム用です。1 つのドローアブル コンポーネントとカメラからの画像を表示し、もう 1 つのドローアブル ゲーム コンポーネントにゲーム自体を表示する予定です。しかしGameComponent
、コンポーネント リストに別のコンポーネントを追加すると、最後に追加したコンポーネントの上にあるコンポーネントが表示されなくなります。
これは、各描画可能なコンポーネントからのコードです。
スモールアップル:
public class SmallApple:DrawableComponent2D
{
Texture2D apple;
public SmallApple(Game game)
: base(game)
{
//Do nothing
}
protected override void LoadContent()
{
apple = Game.Content.Load<Texture2D>("apple");
this.Size = new Vector2(apple.Width,
apple.Height);
renderTarget = new RenderTarget2D(GraphicsDevice,
(int)Size.X,
(int)Size.Y,
false,
SurfaceFormat.Color,
DepthFormat.None,
this.Game.GraphicsDevice.PresentationParameters.MultiSampleCount,
RenderTargetUsage.PreserveContents);
base.LoadContent();
}
public override void Initialize()
{
base.Initialize();
}
public override void Draw(GameTime gameTime)
{
GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(ClearOptions.Target, Color.Transparent, 1f, 0);
this.SharedSpriteBatch.Begin(SpriteSortMode.Immediate, null);
this.SharedSpriteBatch.Draw(this.apple, this.Position, Color.White);
this.SharedSpriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
this.SharedSpriteBatch.Begin();
this.SharedSpriteBatch.Draw(apple, this.Position,Color.White);
this.SharedSpriteBatch.End();
base.Draw(gameTime);
}
}
-- そして BigApple クラス
public class BigApple:DrawableComponent2D
{
Texture2D apple;
public BigApple(Game game)
: base(game)
{
}
protected override void LoadContent()
{
base.LoadContent();
apple = Game.Content.Load<Texture2D>("apple");
this.Size = new Vector2(apple.Width, apple.Height);
renderTarget = new RenderTarget2D(GraphicsDevice,
(int)Size.X,
(int)Size.Y,
false,
SurfaceFormat.Color,
DepthFormat.None,
this.Game.GraphicsDevice.PresentationParameters.MultiSampleCount,
RenderTargetUsage.PreserveContents);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(ClearOptions.Target, Color.Transparent, 1f, 0);
this.SharedSpriteBatch.Begin(SpriteSortMode.Immediate,null);
this.SharedSpriteBatch.Draw(this.apple, this.Position, Color.White);
this.SharedSpriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
this.SharedSpriteBatch.Begin();
this.SharedSpriteBatch.Draw(renderTarget,new Rectangle((int)Position.X, (int)Position.Y, (int)GraphicsDevice.Viewport.Width, (int)GraphicsDevice.Viewport.Height), Color.White);
this.SharedSpriteBatch.End();
base.Draw(gameTime);
}
}
クラス DrawableComponent2D は、drawablegameComponent から継承されたもので、操作する変数がいくつかあります。