Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 2D XNA摄像机和固定背景_C#_Windows Phone 7_Xna_Camera - Fatal编程技术网

C# 2D XNA摄像机和固定背景

C# 2D XNA摄像机和固定背景,c#,windows-phone-7,xna,camera,C#,Windows Phone 7,Xna,Camera,我目前正在为Windows Phone创建XNA游戏。我有一个关于2D相机和背景的问题 是否可以移动XNA相机并固定背景,使其不随相机视图移动?此外,我的暂停按钮和菜单栏也在移动,希望可以将它们固定在屏幕顶部 更新: 以下是我在camera类中的移动方法: public void Move(Vector2 amount) { _pos += amount; } 截图: 如图所示,长方体对象自上而下下落,背景向上移动。有没有办法保持背景的静态不变?如果你在

我目前正在为Windows Phone创建XNA游戏。我有一个关于2D相机和背景的问题

是否可以移动XNA相机并固定背景,使其不随相机视图移动?此外,我的暂停按钮和菜单栏也在移动,希望可以将它们固定在屏幕顶部

更新: 以下是我在camera类中的移动方法:

    public void Move(Vector2 amount)
    {
        _pos += amount;
    }
截图:


如图所示,长方体对象自上而下下落,背景向上移动。有没有办法保持背景的静态不变?

如果你在二维空间工作,你可能会遇到如下情况:

spriteBatch.Begin(SomeSortmode,nullnull,etc..., Matrix);
//drawstuff
spriteBatch.End();
spriteBatch.Begin(SomeSortmode,nullnull,etc..., Matrix);
//draw stuff affected by the camera
spriteBatch.End();

spriteBatch.Begin()
//draw stuff which should not be affected by the camera
spriteBatch.End();
如果是这种情况,请将渲染代码移动到另一个Begin()和End()中

我想到这样的事情:

spriteBatch.Begin(SomeSortmode,nullnull,etc..., Matrix);
//drawstuff
spriteBatch.End();
spriteBatch.Begin(SomeSortmode,nullnull,etc..., Matrix);
//draw stuff affected by the camera
spriteBatch.End();

spriteBatch.Begin()
//draw stuff which should not be affected by the camera
spriteBatch.End();

二维还是三维?你能展示一些相关的摄像机代码,或者一张截图吗?记住XNA没有内置的“摄像头”,所以你必须告诉我们你在做什么。2D,我刚刚用截图更新了我的问题!谢谢你没有足够的信息。在DrawCall中,你可以只考虑相机,也可以不考虑。它应该相当简单。请记住,从数学角度来看,摄影机移动或对象向相反方向移动并不重要。只需将相机位置反转每个帧应用到对象。对于UI元素,完全不要应用相机的位置。谢谢你的评论。您是否有示例说明如何不应用摄影机位置?还有一个问题,是否可以在XNA中创建一些层?我认为这会更简单,如果有可能创建一个固定层,它不会移动。