Lada Engine is a small library that allows basic game creation. It works with OpenGL via OpenTK 4 library.
The project is hardly useful, it is easier and better to learn other libs. But I did this library with love, so there will always be one user (me) to enjoy it.
There is an image, it is loaded and rendered, also it is moved and bounces off the edges
You know what pong is. To move left platform use W S, to move right one use I K, to respawn a ball use R key.
You can control a camera with W A S D keys to move around. There is a world with 100000 objects.
This example is done to demonstrate that you have to be careful about Update method on sprite group as it can be very expensive operation.
To use LadaEngine create a class that has event handlers for Render, FixedUpdate and Load. Also you can add Resize and Update handlers.
The basic game class looks something like this
public class Game
{
private Window _window;
public Game()
{
_window = Window.Create(800, 800, "");
_window.Title = "cool title";
_window.Render += RenderEvent;
_window.Load += LoadEvent;
_window.FixedUpdate += FixedUpdateEvent;
_window.VSync = OpenTK.Windowing.Common.VSyncMode.On;
}
private void LoadEvent() { }
private void RenderEvent() { }
private void FixedUpdateEvent() { }
public void Run() => _window.Run();
}In your Main method, create an instance of this class and run it.
Now once the app loads, LoadEvent method will be called, once there is a new frame RenderEvent will be called and FixedUpdateEvent will be called 240 times a second.
To render an image, you will have to
- Create the
TextureAtlaswith the image within - Create
SpriteGroupto contain the image - Create
Spriteobject, that will be the actual object - Put object in the
SpriteGroup - Call
UpdateonSpriteGroupevery time you change the object, to reassemble the vertices - Call
RenderonSpriteGroup
See the example Moving Image Example
SpriteGroup is a class made to contain a large quantity of sprites that will rarely change, for example the world.
There is an example for using it for large quantity of objects, see World Example
There are several methods, but main ones are AddSprite, Render and Update.
Renderis used to render all the sprites on screen. It requires a camera and uses it's zoom and position to move and zoom. (It is done via shader uniforms, so it is only done once for all objects and is quite effective)Updateis used to create vertices. It should usually be called very rarely, for example if something moved or changed size.AddSpriteis used to add sprite to its inner list by reference.
You use SpriteGroup for a group of sprite that either never moves, like world, or things that move quite often, like entities. The more sprites are there in the SpriteGroup, the more costly is the Update operation.
The Controls class contains the basic input things for PC like mouse and keyboard. These are standard OpenTK objects, so you can find how to use them there.
Brief list of methods I used (with examples):
Controls.keyboard.IsKeyPressed(..)- to see if key was pressed during this exact frameControls.keyboard.IsKeyDown(..)- check if key is downControls.mouse.IsButtonDown(..)- check if mouse button is downControls.mouse.IsButtonPressed(..)- check if mouse button was pressed during this exact frame
Also, control_direction_f, control_direction exists, these fields are of type Pos (Vector2 in LadaEngine) and contain direction from W A S D keys.
If you want to get input only for frame key was on (Like restart game on R in Pong Example)
if (Controls.keyboard.IsKeyPressed(Keys.R))
_ball.SetPosition(Pos.Zero);If you want to get input only for frame button was on (Like spawn something one Left mouse button)
if (Controls.mouse.IsButtonPressed(MouseButton.Left))
SpawnStuff();If you want to get input for all frames button is down (Like moving the player (It is better to use control_direction_f for this))
if (Controls.mouse.IsKeyDown(Keys.S))
_player.Position.Y -= speed;Using control_direction_f for the player
_player.Position += Controls.control_direction_f * speed;Want more cats like one above??
Open the cats folder or follow this link
IDK I think that's enough info for you to write the game of your dream
