【发布时间】:2023-03-10 23:18:01
【问题描述】:
我必须添加第二个视口(= 像分屏一样)以允许玩家在当前关卡的其他地方看到事件。
有没有可能在不重新绘制所有已经绘制的东西的情况下绘制活动区域?
[编辑] RenderTarget2D 是关键。感谢所有的 User1459910。
几乎成功了。
新问题:
- 我找了一阵子还是没有找到“Xna 2D camera with source and destination rectangle”的教程,如果有链接,我想看看,请♥
-
目前,绘图代码如下:
protected override void Draw(GameTime gameTime) { /* ... here is the code to "draw" in the renderTarget2D renderAllScene object ... */ //Let's draw into the 2 viewports spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, camera1.transform); spriteBatch.Draw(renderAllScene, viewport1.Bounds, Color.White); spriteBatch.End(); if (EventIsRunning) { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, camera2.transform); spriteBatch.Draw(renderAllScene, viewport2.Bounds, Color.White); spriteBatch.End(); }
*Viewport 1 很棒。相机跟随角色,但在将相机移动一小段距离后,我认为地图被切割为 1280 像素。所以它只绘制了所有地图的 1280 像素。我不知道为什么。也许是因为我在创建 renderAllScene = new RenderTarget2D 时失败了。 :x
renderAllScene = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
*对于视口 2:我需要源矩形。我明天试试。
【问题讨论】:
-
有人说您实际上可以移动视口而不是移动世界上的所有对象,尽管我自己还没有尝试过。我想基本上你需要找出在两个视口中都可以看到哪些对象,用 spritebatch 将它们全部绘制出来,然后用你的视口做一些事情。或者为第一个视口绘制东西,然后为另一个视口绘制东西,我不确定。
标签: c# xna camera draw viewport