
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
With this gem you can easily add camera functionality into your games built with Ruby2D. Install it using gem install ruby2d-camera
and then add it into your project with require ruby2d/camera
at the top of your code, just below the line require ruby2d
.
ruby run.rb
to run the demo.
Create your object as if you would create it in Ruby2D except you need to prefix it with Camera::
. For example to create a square you do Camera::Square.new
. Any objects you create this way can be controlled and manipulated the same way that you control and manipulate them in Ruby2D with a few small additions. Any objects that do not have an x/y variable to move it now do have this, so that you may move the objects in the camera. Text objects also have a boolean that you can change named center
which allows you to set the origin to be the horizontal center of the text rather then the edge.
Camera.zoom
Default: 1. This is a multiplier for how much you want the camera to be zoomed in(e.g 2 is 2x zoom, 0.5 is 0.5x zoom)Camera.x
and Camera.y
Default: 0. This is the position the camera is centered on in the "world"Camera.angle
Default: 0. This is the angle of how much the camera is rotated(in degrees). It ranges from 0-360. Giving values outside of this range will automagically convert them to fit within the 0-360 range.Camera.coordinate_to_worldspace(x,y)
You pass in the coordinates on the screen(for example where a player clicked in the window) and it will return the coordinates(in an [x,y] array) what the coordinates are in the worldCamera.coordinate_to_screenspace(x,y)
You pass in the coordinate in the world(for example an enemy in your game) and it will give you the coordinates(in an [x,y] array) of where on the screen this character appears. Note this function may return values that are outside of the screen if the object is not in view of the cameraA single Camera
module exists which keeps track of objects created with it. When you create an object with the camera it creates a special object that inherits the original object from Ruby2D and then adds additional functions. The Camera module then uses these functions to draw the various objects on the screen each frame, using the parameters you gave it.
Under the example
directory you can find a (poorly coded) demo using this gem. Simply ruby run.rb
in the example directory to start the demo.
WASD to move character
Q/E to rotate camera
Hold R to reset the rotation
Space to enter doors
Unfortunately text cannot be resized due to current limitations of Ruby2D, this will fixed when possible. This means zooming with text will look strange, centering the text somewhat alleviates this issue.
FAQs
Unknown package
We found that ruby2d-camera demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.