Giter VIP home page Giter VIP logo

comora's Introduction

logo

Comora

A simple 2D camera for Monogame.

Install

Available on NuGet

NuGet

Quickstart

private Camera camera;

protected override void Initialize()
{
	this.camera = new Camera(this.graphics);
	
	base.Initialize();
}

protected override void Update(GameTime gameTime)
{
	this.camera.Update(gameTime);
	
	this.camera.Position = Mouse.GetState().Position.ToVector2();
	
	base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
    graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
    
	spriteBatch.Begin(this.camera);
	// Draw here
	spriteBatch.End();

	base.Draw(gameTime);
}

Draw

Through the SpriteBatch extension methods, simply call Begin as usual, but with your camera :

spriteBatch.Begin(this.camera);

You can add a parralax factor too :

spriteBatch.Begin(this.camera, new Vector2(0.85f,0.85f));

Animations

You can add animation by applying Transform velocities or tweens onto the the camera's Transform property.

Conversion

You can convert a point from screen unit to world :

var screenPosition = Vector.Zero;
var worldPosition = Vector.Zero;
camera.ToWorld(ref screenPosition, out worldPosition);

Converting world coordinates to screen coordinates is also possible.

var screenPosition = Vector.Zero;
var worldPosition = Vector.Zero;
camera.ToScreen(ref worldPosition, out screenPosition);

Debug tools

The framework provide several tools for debugging purpose.

camera.Debug.IsVisible = Keyboard.GetState().IsKeyDown(Keys.F1);

Make sure to load content too :

this.camera.LoadContent(GraphicsDevice);

And then draw it with Draw extension method. You don't have to call spriteBatch.Begin and spriteBatch.End which are already invoked by the method.

this.spriteBatch.Draw(this.camera.Debug);

FPS

The number of frame per seconds will be displayed on the layer.

Grid

A visual grid for world units.

// To draw a white line of size 2 every 50 world units
// and a red one of size 4 every 200 world units.
camera.Debug.Grid.AddLines(50, Color.White, 2);
camera.Debug.Grid.AddLines(200, Color.Red, 4);

Roadmap / Ideas

  • Integrate shaders for easy screen effects.
  • Add more built-in animations.
  • Clean and improve debug layer.

Why?

"Seriously, just a camera ?" ... Yes! I often see full engines with tons of stuff I never need. I'm looking about modularity and easy APIs (like many awesome LÖVE libraries) and that's why I created Comora. I'm sure this could be useful for someone else.

Thanks

Contributions

Contributions are welcome! If you find a bug please report it and if you want a feature please report it.

If you want to contribute code please file an issue and create a branch off of the current dev branch and file a pull request.

License

MIT © Aloïs Deniel

comora's People

Contributors

nedlanon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

comora's Issues

parralax property missing

The documentation states that there is spriteBatch extension method that allows for a parallaxmode to be set.
However, there is no such extension.

Camera.ToWorld returns wrong result.

I make a Vector2(0,0), and if I render a sprite in this position, the sprite will rendered at center of screen, but, if I use camera.ToWorld with mouse position, it return the wrong value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.