本文整理汇总了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();
}
}
示例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);
}
示例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();
}
}
}