当前位置: 首页>>代码示例>>C#>>正文


C# RenderWindow.MapPixelToCoords方法代码示例

本文整理汇总了C#中SFML.Graphics.RenderWindow.MapPixelToCoords方法的典型用法代码示例。如果您正苦于以下问题:C# RenderWindow.MapPixelToCoords方法的具体用法?C# RenderWindow.MapPixelToCoords怎么用?C# RenderWindow.MapPixelToCoords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SFML.Graphics.RenderWindow的用法示例。


在下文中一共展示了RenderWindow.MapPixelToCoords方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            Window = new RenderWindow(new VideoMode(1280, 720), "Collapse");
            Window.SetFramerateLimit(60);
            Window.Closed += (sender, eventArgs) => Window.Close();

            Map = new TileMap(200, 90);
            for (var y = 85; y < 100; y++)
            {
                for (var x = 0; x < 200; x++)
                {
                    Map[x, y] = Tile.Floor;
                }
            }

            Window.MouseMoved += (sender, eventArgs) =>
            {
                var mousePosF = Window.MapPixelToCoords(new Vector2i(eventArgs.X, eventArgs.Y));
                var mousePos = new Vector2i((int)mousePosF.X / TileSize, (int)mousePosF.Y / TileSize);

                if (Mouse.IsButtonPressed(Mouse.Button.Left))
                {
                    Map[mousePos.X, mousePos.Y] = Tile.Block;
                }

                if (Mouse.IsButtonPressed(Mouse.Button.Right))
                {
                    Map[mousePos.X, mousePos.Y] = Tile.None;
                }

                if (Mouse.IsButtonPressed(Mouse.Button.Middle))
                {
                    Map[mousePos.X, mousePos.Y] = Tile.Floor;
                }
            };

            while (Window.IsOpen())
            {
                Window.DispatchEvents();

                Window.Clear(new Color(100, 149, 237));
                Window.Draw(Map);
                Window.Display();
            }
        }
开发者ID:Rohansi,项目名称:Collapse,代码行数:45,代码来源:Program.cs

示例2: Draw

        public override void Draw(RenderWindow window) {
            window.SetView(Level.Camera);

            _mousePositionInWorld = window.MapPixelToCoords(Mouse.GetPosition(window), Level.Camera);

            Level.Draw(window);

            window.SetView(window.DefaultView);
        }
开发者ID:Catvert,项目名称:MaryoTheReturn,代码行数:9,代码来源:EditorScene.cs

示例3: input

        public override void input(RenderWindow _window)
        {
            if (Keyboard.IsKeyPressed(Keyboard.Key.A))
            {
                if (mPosition.X > 0)
                    mBody.ApplyLinearImpulse(new Vector2(-0.3f * Delta.mDelta, 0f));
                else
                    mBody.ApplyLinearImpulse(new Vector2(0.3f * Delta.mDelta, 0f));
            }
            else if (Keyboard.IsKeyPressed(Keyboard.Key.D))
            {
                if(mPosition.Y < 1280)
                    mBody.ApplyLinearImpulse(new Vector2( 0.3f * Delta.mDelta, 0f));
                else
                    mBody.ApplyLinearImpulse(new Vector2(-0.3f * Delta.mDelta, 0f));
            }

            if(Keyboard.IsKeyPressed(Keyboard.Key.Return))
            {
                if(!mOnce)
                    invincible();
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.Space))
            {
                if (mPosition.X > 0 && mPosition.X < 1280)
                    mBody.ApplyLinearImpulse(new Vector2(0f, -0.9f * Delta.mDelta));
            }

            if (Mouse.IsButtonPressed(Mouse.Button.Left))
            {
                if (mShoot.ElapsedMilliseconds > 250)
                {
                    Vector2i mousePos   = Mouse.GetPosition(_window);
                    Vector2f translated = _window.MapPixelToCoords(mousePos, _window.GetView());
                    Vector2f aim        = new Vector2f(translated.X - mPosition.X, translated.Y - mPosition.Y);
                    double   angle      = Math.Atan2(aim.Y, aim.X);

                    mWorld.createBullet(mPosition, this, "resources/bullet.png", angle);
                    mShoot.Restart();
                }
            }
        }
开发者ID:Jamsterx1,项目名称:Titan,代码行数:43,代码来源:Player.cs


注:本文中的SFML.Graphics.RenderWindow.MapPixelToCoords方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。