Skip to content

DillonKyleDev/FlatEngine2D

Repository files navigation

FlatEngine - 2D Game Engine

engine

UPDATE

There is now a published release for FlatEngine2D! Please see the "Releases" section on the right-hand side for a download link and read up on the ReadMe for details on how to use FlatEngine.

I've included a sample project inside FlatEngine2D called FlatSpace. With it, hopefully you can get an idea of how to use FlatEngine. But remember, FlatSpace is only one way to make a game using FlatEngine. Get creative! You are welcome to use any art assets I created that are in the release for anything you want but the audio is audio I purchased on the Unity asset store so that can't be used as far as I know, except to experiment with.

As a note, FlatSpace was made before the implementation of persistant GameObjects which enable you to have some GameObjects stick around even when changing scenes. Creation of new persistant GameObjects is located in the Assets dropdown menu. Persistant objects are tied to the Project, so make sure to save your Scenes AND your Projects often to keep your progress saved!

Building and using FlatEngine2D from source

If you are using the Release build of FlatEngine2D found in Releases you can safely ignore this section.

To build FlatEngine2D yourself and get the benefit of editing the source code directly:

  1. Download the .zip and extract

  2. Go into these three files and change the targetdir and objdir variables to locations you want FlatEngine2D to be built to (if default location is undesired) and of course be sure to change <UserName> to your users name path on your computer:

    FlatEngine-Core/Build-Core.lua
    FlatEngine-Editor/Build-Editor.lua
    FlatEngine-Runtime/Build-Runtime.lua

Change these to desired output location in each .lua file above.

targetdir ("C:/Users/<UserName>/Desktop/FlatEngine2D_Build/" .. OutputDir .. "/%{prj.name}")
objdir ("C:/Users/<UserName>/Desktop/FlatEngine2D_Build/Intermediates/" .. OutputDir .. "/%{prj.name}")

  1. Run the Premake batch file by double clicking it located at Premake/Setup-Windows.bat to generate the Visual Studio solution file.
  2. Open the solution file that was created in the root directory and build it. The default project is set to FlatEngine-Editor. After the Editor is built, change the start-up project in the solution properties to FlatEngine-Runtime and build again.
  3. After building, move the .dll files from the DLLFiles directory to each of these built directories (the ones you see will be based on how you built the project, debug or release):

FlatEngine2DBuild/windows-x86_64/Debug/FlatEngine-Editor/
FlatEngine2DBuild/windows-x86_64/Debug/FlatEngine-Runtime/
FlatEngine2DBuild/windows-x86_64/Release/FlatEngine-Editor/
FlatEngine2DBuild/windows-x86_64/Release/FlatEngine-Runtime/

You're now set up to use the engine and edit it's source code as you wish. To open the Editor, you'll need to change the start-up project back to FlatEngine-Editor in the solution properties. From here, you can edit and debug source code from the solution. (You can also create and edit entire projects and assets entirely from the source solution's Editor, but if you do so just remember to copy over the projects/ directory from the solution directory to the build location when you're done and ready to build the final game project, as outlined below.) building a finished project is slightly different than in the Release version of FlatEngine2D (and more complicated). When you build a finished project, the FlatEngine-Editor code is not built into the release. You'll notice there are three projects in the solution: Core, Editor, and Runtime. The Core project is a static library that both the Editor and Runtime use to function. The Editor project is only code that is used for the display and functionality of the Editor which is not needed once the game logic is hooked up and scenes are made. The Runtime project just uses the Core library and reads the game project files (scenes, scripts, etc.) to load and run the final game project.

When you are finished editing the source code, you need to build the Editor project and the Runtime project in Release mode again. If you've made changes to the Core library, the Runtime project needs to know about those changes.

After building, if this is your first time building you'll also need to copy over these directories from the solution directory and put them in the built Release/ directory:

engine/
projects/
Vendor/
And to carry over the ImGui editor layout, you'll also need to copy the imgui.ini file from FlatEngine-Editor/ in the solution directory to Release/FlatEngine-Editor/.

(If it is not your first time building, you don't need to copy any of the above folders or the imgui.ini file unless you were making changes to project assets from the solution that you want to keep, in which case you'll just need to copy the projects/ folder to the built Release/ directory.)

Now you should be able to go into the build location and open the FlatEngine-Editor.exe with all of your source code changes and project asset changes (if you made any) present in the build. From here, you can follow the project building guide found in the quick links below to build your project normally.

Disclaimer

This project is in active development.

This is a hobby project. It will likely crash eventually so save often. THERE IS NO AUTOSAVE. Things will change with updates. Your results and the usefulness of FlatEngine may vary. Some key systems are not optimized.


Quick links:

  1. Viewports
  2. Engine Components
  3. Quick Start Guide
  4. Building a completed Project
  5. Lua Scripting in FlatEngine2D
  6. Lua-FlatEngine2D scripting functions
  7. FlatEngine2D classes exposed to Lua (Lua usertypes)

About:

FlatEngine2D is a 2D game engine made using SDL2 and ImGui. It is a passion project and is intended to replace Unity in all my future 2D game development projects. Maybe you will find it useful as well. I will also be using the bones of the engine I develop here to create a full 3D game engine in the future. See the license for details about using the engine and code, but as far as code I have written and assets I've created, you are free to use them as you wish, and you are also free to credit me if you would like to but it is not required. Additionally, I would love to see any projects you are working on or have used any of the engine code for if you would be willing to share it.

I've spent a lot of time with the Unity game engine and so have found comfort in it's design philosophy. I will be adopting many of Unity's methods for handling various things within my engine.


Libraries / Utilities

Library used Features supported
SDL_2 The engine is built using SDL_2 as a base, along with several other SDL libraries including SDL_ttf for fonts, SDL_Image, and SDL_Mixer for audio.
ImGui The entire user interface, including all of the interactions within the scene view, are handled using ImGui_Docking.
nlohmann Json Formatter nlohmann Json Formatter is used for saving various types of data for later use including Scene data (GameObjects and components), Project data, and Animation data.
Lua/Sol Lua/Sol is the scripting language embedded in FlatEngine2D. Scripts are contained in files with the extension ".scp.lua" in order to be controlled as needed within the engine. See "Using FlatEngine" below for a detailed walkthrough of how to use Lua in FlatEngine.

Viewports

All available viewports can be seen in the Viewports dropdown menu on the main top bar menu. Here you can toggle each one visible or invisible. You can freely drag each viewport to whatever location in the engine you want and can dock them inside each other. Just grab a viewport by the top tab bar and put it where you want it.


viewports


Scene View

The Scene View is the viewport where you'll be spending most of your time. Here you will layout your GameObjects and set up your Scenes and are able to see the active boundaries of GameObject components like Canvases, Cameras, BoxColliders and Buttons.


sceneView

Game View

The Game View displays the actual final look your game will have when it is built and running. There are no widgets displayed here, only the final result of all your hard work.


gameView

Inspector

The Inspector viewport is where you will edit all of the values of each GameObject's components. Click on a GameObject either in the Scene Hierarchy, Persistant GameObject Hierarchy, or within the Scene View to focus it in the Inspector window. Once focused, each component attached to the object will be shown and editable and you are able to rename the GameObject. Each component can be collapsed to conserve space within the view and you can even collapse them all at the same time by clicking the button to the left of the "Tags" button.


inspector


The final and perhaps most important feature of the Inspector window is the ability to add new components to GameObjects. You can do this either by clicking the three dots expand button on the top right or using the big purple "Add Component" button on the very bottom of the viewport.


addComponent

Hierarchy

The Hierarchies are where you will find the list of all GameObjects in your Scene and in your Project. Individual Scenes each hold their own set of GameObjects. In addition to those objects there are also a set of Persistant GameObjects that belong to each Project. These objects don't get unloaded when you change Scenes and they are visible in the Persistant Hierarchy. All regular Scene objects are found in the Hierarchy viewport. These viewports function identically to one another and allow you to visually see the structure of your Scene. Each GameObject can have many nested children that will appear in a collapsable section under each parent object. You can click and drag GameObjects onto other GameObjects to set them as children of those objects. Remove a GameObject as a child by dragging it into a space between two GameObjects in the Hierarchy.


hierarchies

Log

Where all text output and error messages are displayed. Messages from the engine are prefixed [C++] and messages from Lua scripts you've written are prefixed [LUA]. All logging functions available to you are in the Lua sections of this README toward the bottom.


logger

Animator & Keyframe Editor

The Animator lets you animate component properties of GameObjects. You can select a component property to animate in the dropdown menu and add it to the Animation to cause it to pop up in the timeline window with a new keyframe to edit. If you select the keyframe with the Keyframe Editor open like it is in the photo, you can see all of the properties you are able to edit on the selected keyframe. If you want to animate a specific property, make sure the checkbox is checked next to it. You can move the keyframe pip inside the Animation Timeline directly to change the time it is played by clicking and dragging it or you can directly input the keyframe time in the Keyframe Editor window. Don't forget to save any changes made to the Animation using the three dots expand button in the main Animation viewport.


animatorKeyFrameEditor

File Explorer

The File Explorer is a real-time representation of the folder structure in the current Project directory. The currently loaded Project's asset directory will be displayed in the Directories hierarchy on the left-hand panel. It is navigable either via the directory tree or by double clicking folders in the right-hand panel.


fileExplorerLayout


The File Explorer supports creation and deletion of assets through the right-click context menu. Files deleted here are well and truly deleted from your computer.


rightClickContext


You can also drag and drop assets directly into the Scene View to create GameObjects from them like prefabs and images. You can also drag images, animation files, audio files, and font (.tff) files directly from the File Explorer into GameObject components to use them as references in Sprite, Text, Animation and Audio compnonents.

Project File Structure in FlatEngine2D

When a Project is created in FlatEngine2D, a new directory with the Project's name is created inside the projects/ directory. Each project folder is created with the same set of directories upon creation:

  1. animations/
  2. audio/
  3. images/
  4. images/tileTextures/
  5. mappingContexts/
  6. prefabs/
  7. scenes/
  8. scripts/
  9. tileSets/

When a game Project is finished and built, only the Project that is currently open in the editor will be copied over to the build location, so please only put assets you are using for the current Project in the directory with the Project's name. Don't use assets in other Project folders.


Mapping Context Editor

Using the Mapping Context Editor you can bind input actions to specific keys and buttons and save them to be accessed through Lua scripts. You can either create new Mapping Contexts through the editor or through the right-click context menu in the File Explorer window. Doing so will automatically open the editor with the new Mapping Context opened and ready to edit. Don't forget to save all your changes after adding your input actions!


mappingContextEditor

TileSet Editor

Using the TileSet Editor you can create the TileSets that you'll use inside the TileMap components. All you have to do is create a new TileSet either in the TileSet Editor or in the File Explorer right-click context menu and drag and drop an image from the File Explorer into the input as your tiling image. This component is still early in development so it only allows a 16x16 selection for each tile for now. Once an image is chosen, click on each tile you want to be included in your TileSet and if your TileSet is selected in a TileMap component, you should see them start to appear as available tiles to paint with.


tileSetEditor


Change your brush mode to Tile Drawing mode by clicking on the brush icon in the top left corner of the Scene View. Your other options are:

  1. Translate mode (default, for moving GameObjects around within the Scene View)
  2. Tile Brush mode: For drawing selected tiles on a selected TileMap
  3. Erase mode: For erasing tiles drawn
  4. BoxCollider draw mode: This mode allows you to create collision areas for your TileMaps that line up with the tile grid nicely. It's still a very young feature and is pretty unpolished, but it works in it's current state.
  5. Tile Select mode: For selecting multiple tiles in order to move them to somewhere else within the TileMap using the Tile Move mode.
  6. Tile Move mode: For moving selected groups of tiles within the TileMap. This feature is also very unpolished and I don't recommend relying on it too much.

Once you're in Tile Brush mode, click on the tile you want to draw in the TileMap component and start drawing!

brushModeSelect

If you want to try out the collision area drawing feature, great! Scroll down to the bottom of the TileMap component to create a Collision Area. Then either click "Draw Collision Areas" or choose the BoxCollision Draw Mode brush in the top right of the Scene View again:

boxCollisionDrawMode

Click and drag to create as many BoxColliders as you wish:


collisionAreaDrawn


When you're done, back in the TileMap component click "Generate Colliders" and your Collision Areas will be combined into one big collider. You can then give the attached GameObject any Tags (just like any other GameObject) and the Collision system will respect those Tags. Remember, the TileMap system is still underdeveloped, so your experience with it will vary.


collisionAreaGenerated


Engine Assets

There are several key assets that you will be spending a lot of time with in FlatEngine2D. Most of these can be created in several ways, but the main two are through the main menu top bar: Create -> Asset files -> asset_type, and through the right-click context menue in the File Explorer window.


createAssets1 or newAssets2

Scenes
Projects contain all the data associated with a particular game-in-progress including the Scene to load up at the start of a game and the list of Persistant GameObjects in the game, (game managers, etc.), but mostly information that is not relevant to the end user. Project files are saved in JSON format. New Projects are made in the Project Hub when you first launch the engine.

Scenes
Scenes are the container for all GameObjects and are saved in JSON format using a JSON Formatting library for simple parsing.

TileSet
TileSets are used by the TileMap system to allow them to draw texture tiles onto TileMap components in the Scene View.

Script
Lua script files are for scripting. In FlatEngine, these files have the extension ".scp.lua" in order to be seen and processed by the engine correctly. You create new Script files in the File Explorer window by right clicking and adding the new asset or inside a Script component in the Inspector window.

newScript

Mapping Context
Mapping Contexts (and the Mapping Context Editor) are the interface for binding input actions to specific controls. Currently mouse/keyboard and XInput (Xbox controller) are supported with more planned to be added in the future. You can programmatically change bindings using Lua Scripts.

Animation
Animations are what the Animation components use to play component Animations. Animations are edited using the Animator window in combination with the Keyframe Editor and Animation Timeline. If you have used Unity then you should be familiar with how this functions.

Prefab

Prefabs are saved GameObjects (including any children and components) that can be instantiated at runtime, or at any time, into the Scene. To create a new Prefab, right click a GameObject in either of the two Hierarchy windows and select Create Prefab. GameObjects that are already Prefabs will show more options to select when right clicking. You will be able to save changes made to this object and extend those changes to all other Prefabs of the same name, unpack the Prefab (Remove it from the Prefab system without changing any of it's properties so that any changes made to it can be saved without effecting the Prefab family), or create a brand new Prefab with a new name based on that GameObject. Creating a new Prefab from an existing Prefab won't change any Prefabs that were made using the old Prefab name. You can drag and drop Prefabs from the File Explorer into the Scene or create them from the top menu bar in Create -> Prefabs -> your_existing_prefab. You can also instantiate prefabs using Lua with Instantiate(std::string prefabName, Vector2 position) where the position is the (x,y) position to instantiate the Prefab in the Scene.

createPrefabs


Engine Components

Tags

Tags are a list of arbitrary properties that a GameObject can have that can be queried using

GameObject::HasTag("tagName")

You can set a GameObject to have a specific tag using GameObject::SetTag("tagName", true); or, more conveniently, set it in the Inspector viewport by clicking the Tags button below the object's name:


tagsbutton --->>>> availableTags


The Tags system is also used by the collision detection system to prevent objects that should not interact from interacting, based on the Tags each GameObject has and is set to Ignore. Tags are completely customizeable by opening and editing the Tags.lua file found in /engine/scripts/Tags.lua. Here you can freely add and remove available Tags you can choose from for GameObjects and they will appear in the tag list in engine upon either closing and reopening the FlatEngine or by clicking "Reload Tags" in the dropdown menu under Settings -> Reload Tags on the main menu bar. This is also how you reload any customizations you've made to the color scheme of FlatEngine2D in the Colors.lua file or engine icons in Textures.lua located in the same directory as Tags.lua. (Your changes will also go into effect upon relaunching the engine)

reloadTags


Tags must remain in the format present in the Tags.lua file: Comma-separated strings inside a Lua table named F_Tags

F_Tags = { "Tagname", "Tagname2", "Tagname3" }
or
F_Tags = {
"Tagname",
"Tagname2",
"Tagname3"
}

Components

FlatEngine2D's GameObjects require components be attached for their functionality. The current list of components included in FlatEngine are:

  1. Transform
  2. Sprite
  3. Camera
  4. Script
  5. Button
  6. Canvas
  7. Camera
  8. Animation
  9. Audio
  10. Text
  11. BoxCollider
  12. CircleCollider (work in progress -> CircleColliders currently do not support Solid collision and can only be used as triggers)
  13. CompositeCollider (work in progress -> Currently removed from the engine)
  14. RigidBody
  15. CharacterController
  16. TileMap (work in progress)

Transform

All GameObjects MUST have a Transform and are created with one that cannot be removed. Transforms handle:

Property Description
Origin The reference point for all position changes.
Position An (x,y) Vector2 that holds position relative to the Origin point.
Scale The Scale of the entire object and its components (seperate from any additional component scale parameters, ie.. Sprite scale). Children are not yet affected by the scale of their parent. I am still working out how I want this aspect of scaling to be handled.
Rotation The rotation in degrees of the object. Currently the collision system does not account for rotations of objects so Sprites are all that are affected by this.

Sprite

Sprites are the visual representation of GameObjects in the Scenes. Supported image formats for Sprites are:

  • .png
  • .jpg
  • .tif
  • .webp
  • .jxl

Sprites have the following properties:

Property Description
Scale The scale of the image (separate from the scale of the Transform).
Offset The position of the Sprite relative to the Transforms position, usually just (0,0).
Render Order Determines what other images the image will be rendererd in front of or behind. The lower the render order, the farther back it will be rendered in the scene.
Tint color The tint color that will be applied to the texture.
Pivot Point The point at which all scaling and positioning of the texture is relative to. If you manually change the Offset of the Sprite, that value will override the Pivot Point offset.

Script

Scripts in FlatEngine are written in Lua in ".scp.lua" files. The Script component is a container for a script reference and allows you to expose variables to the lua script from the inspector window for customizeability across GameObjects using the same Script. See the more detailed explanation further down on how to use the Script components and Lua in FlatEngine2D.

Button

Buttons are simple UI elements for enabling mouse interaction in a scene. Buttons are meant to be used in combination with Canvas components in order to block Buttons underneath them, but it is not strictly necessary. Currently they are only natively supported with mouse controls, but it shouldn't be too difficult to enable gamepad support through Lua scripting. Buttons have the following properties

Property Description
Active Layer The layer that the Button is active on. If another Button is on the layer above this one and you hover over it, the Button on the lower level will not be activatable. Similarly, if you use a Canvas component and set the Button to be on the layer of or above the Canvas, the Canvas will completely block, (if enabled), all Button interactions below the Canvas layer.
Active Dimensions The width and height of the button in grid spaces.
Active Offset The position of the Button relative to the Transforms position.

Canvas

Canvases are meant to support the use of Buttons when making UIs. Canvases, (if enabled), block all Button interactions of Buttons that are below the layer of the Canvas. Canvases have the following properties

Property Description
Active Layer As discussed, Buttons below this layer and within the bounds (width and height) of the Canvas will be blocked from interaction.
Dimensions The width and height of the Canvas.

Camera

The Camera component is how the scene is viewed in the GameView. Even without a Camera, the GameView is still viewable, but it will be locked to the center (0,0) of the world at a fixed zoom level. You can have multiple Cameras per scene and switch between them freely using the b_isPrimaryCamera check. Objects that are outside the viewing width and height of the primary scene Camera are not rendered. Cameras have the following properties

Property Description
Dimensions The with and height of the Camera, determines where the cutoff is for objects being rendered.
Is Primary Camera? Determines which Camera the GameView will be rendered through.
Zoom Determines how zoomed in the Camera is.
Follow Smoothing Determines how quickly the camera snaps to its follow target.
Follow Target The GameObject, if any, this Camera will follow, if enabled.
Should Follow? Toggles whether the Camera should follow the Follow Target or stay where it is.

Animation

Animation components are one of the most powerful components that can be attached to a GameObject. Animations are attached to Animation components of a GameObject and can be called through the Animation::Play() method at runtime. Animations currently support animation of Transform, Sprite, Text, and Audio components, and Events. Animation Events allow you to call Lua functions at a particular keyframe and pass up to 5 parameters to it, (string, int, long, float, double, bool, or Vector2). These are extremely powerful and useful to take advantage of. I plan to add more components to the list of components you can animate, but I believe this is a very versitile grouping and likely you are able to do most of what you need to with them. I will update this with more detailed information in the future.

Audio

The Audio component allows you to attach several different audio clips and music files to a single GameObject and call them by name in Lua, or play them from the Animation component. Each sound clip in an Audio component has the following properties:

Property Description
Name The name used to play the Audio clip.
Filepath The path of the audio file to be played.
Sounds An unlimited number of sounds can be attached to each Audio component and can be accessed using their individual names.

Text

Text components function very similarly to Sprite components except they render text. Text components have the following properties:

Property Description
Text The actual text to be rendered.
Font The font that will be used
Scale The scale of the text (separate from the scale of the Transform).
Offset The position of the Text relative to the Transforms position, usually just (0,0).
Render Order Determines what other images the image will be rendererd in front of or behind. The lower the render order, the farther back it will be rendered in the scene.
Color The color that will be applied to the texture.
Pivot Point The point at which all scaling and positioning of the texture is relative to. If you manually change the Offset of the Text, that value will override the Pivot Point offset.

Collision Components

The Collision components are not all complete. The BoxCollider component is complete but it does not take rotation into account. This is a feature I will be working on in the near future. The CircleCollider can detect collisions, but it does not yet know how to handle positioning based on collisions. The CompositeCollider I am waiting until the other Collision components are finished to continue work on it. As a result, I have disabled the use of Composite colliders from the engine temporarily, and CircleColliders cannot be made solid and can only really function as a trigger because of it. The BoxCollider uses a simple AABB collision detection approach. The collision system is connected to the Tags system and will not check collisions between GameObjects that are ignoring each other based on the Tags they pocess. The BoxCollider component has the following properties:

Property Description
Dimensions The width and height of the collision box.
Offset The position relative to the Transforms position
Active Layer This feature is neglected due to the Tags system being in place, but it will be updated when I do the necessary overhaul of the collision system as a whole. Colliders should only interact with other colliders on the same layer.
Is Continuous? Determines how often this collider needs to be checked for collision. Currently it is set to every 10 frames for non continuous colliders, this is subject to change.
Is Static? If a collider is static it may not need to be checked or updated as often as non static colliders, this saves on performance.
Is Solid? Determines whether other collisiders should pass through this collider or if it is just a trigger. (isSolid is disabled for CircleColliders at the moment but they can be used as triggers instead.)
Is Composite? For adding this Collider to the CompositeCollider component on the GameObject (work in progress).
Show Active Radius? Before the AABB testing occurs, each tested collision is tested using a less expensive radius check, this enables you to see that radius for each particular collider.

RigidBody

The RigidBody component is responsible for handling all of the physics that an object can be subjected to. Using the RigidBody, you can add forces and torques to an object to manipulate its velocity and rotation. The RigidBody component has the following properties:

Property Description
Mass Determines how difficult it is to change the velocity of the object.
Gravity Determines how much gravity the GameObject experiences.
Falling Gravity Falling gravity is used if you would like your GameObject to have a different gravity going down than it has going down. This is useful for fine tuning the feeling of a jump or could be used to add a glide or hover mechanic. Both this and regular Gravity Scale can be freely changed.
Terminal Velocity The maximum speed a GameObject can fall due to gravity.
Wind Resistance The amount that a GameObject is slowed while not grounded.
Friction The amount that a GameObejct is slowed while grounded.
Angular Drag The amount that a GameObject is slowed while rotating.
Equilibrium Force I believe this will be removed in a future update. I am unsure if this value should be exposed to the end user.

CharacterController

Note: This component is due for a rework. The exposed variables don't make much sense and are not intuitive to use. Max Acceleration is essentially the max speed, or the maximum amount of velocity that is added each frame.

The CharacterController is a bundle of functionallity that is meant to make it easier to manipulate a character GameObjects RigidBody component. The CharacterController has the following properties:

Property Description
Max Speed Determines the maximum speed a GameObject can move.
Max Acceleration Determines how fast the GameObject gets to its Max Speed (not really, see note above)
Air Control Determines how freely this GameObject can move while not grounded.

TileMap

Note: The TileMap component is in working condition but it does need some improvements to the user experience and optimization to be considered complete. I am including it in the release for testing purposes.

The TileMap component allows the user to quickly draw scenes using TileSets created in the engine. Each TileMap can have multiple TileSets (palettes) that it can use to draw in the scene. Eventually I would like to add layers to each TileMap, but for now, in order to have layered tiles you must create another GameObject with a TileMap and place them on top of each other. I recommend having one parent object and then as many child GameObjects as needed for the layers needed. The TileMap currently supports a rudimentary BoxCollider drawing system that can be used to add collisions to the TileMap. It is surely in need of a user experience overhaul but it is functional. As noted above, there are several optimizations that still need to be made to this system to be considered complete. The TileMap component contains the following properties:

Property Description
Dimensions The width and height of the TileMap drawing canvas.
Tile Dimensions The dimensions of the actual texture tiles you are drawing with in pixels. (default 16px)
Render Order Just like with the Sprite and Text component, this determines what other textures will be drawn over and under the TileMap.
TileSets The list of available TileSets you can use to draw with for this TileMap.
Collision Areas Sets of colliders that the user can draw in the TileMap that function identically to the BoxCollider components (because they are under the hood).

Using FlatEngine

WARNING: FlatEngine is NOT a complete engine and as such, it will almost certainly crash and cause you to lose unsaved progress so please save both your Scenes and your Project often. There's a handy dropdown in both of the Hierarchies that lets you "Save all", which will save both the loaded Scene and the Project in one click. If you do experience a crash, which you likely will eventually, if you are willing, please submit an issue in the repository with the details on how to recreate it. That would be extremely helpful to me and I would greatly appreciate it! If not, that's okay too.

With the warning out of the way... FlatEngine is intended to be very straightforward to use and very fast to get up and running on a project.

In FlatEngine, the general flow is:

Project Creation

Create a project using the Project Hub

Scene Creation

Create a scene and open it. You can do this in two ways:
  1. File > New Scene
  2. Open the File Explorer viewport:

Viewports > File Explorer

Then, in an empty space in the File Explorer, (preferably in the scenes folder), Right click > Add New > Scene ... Then double click the new scene to open it.

Add GameObjects to the Scene

You can add GameObjects to the Scene using the top menu bar in several ways:


Create > GameObject
Create > Components (allows for quick creation of GameObject with a default component) Create > Prefabs (once you have created a Prefab by right clicking on an existing GameObject, you can instantiate them from here)

Add Components to the GameObjects

If the Inspector window is open, (Viewports -> Inspector) you can click on a GameObject to focus on it and view its components in the Inspecor viewport. Here you have two options to add components:
  1. Three dots expand button under the GameObjects name then click "Add Component"
  2. The purple Add Component button at the bottom of the Inspector viewport

Add Controls

Create a Mapping Context in one of two ways:
  1. Create > Asset files > Mapping Context
  2. In empty space in the File Explorer viewport, Right click > Add new > Mapping Context

After you have created a new Mapping Context, you can double click it in the File Explorer to open the Mapping Context Editor or open the editor using:


Viewports > Mapping Context Editor

Select the Mapping Context you'd like to edit and add an input action name along with the button you'd like to associate it with. Click "Add" and don't forget to "Save" in the top right of the viewport.

In order to access these newly created bindings, you will need to add a Script component to the GameObject you want to have access to it. In the Inspector window for the GameObject, Add a new Script component. In the Script component click "New Script" and give it a name, then select the newly created script file in the Script components dropdown menu. Now open up the Script in your favorite text editor and in Awake() (inside the data variable) add a mapping context variable and assign it to the mapping context you just created. This can be done like so:

NOTE: Please see "Lua Scripting in FlatEngine" below for a more detailed explanation of scripting in FlatEngine.

-- Assume the Script name is "PlayerController" and the Mapping Context is named "MC_Player".

-- PlayerController.scp.lua

function Awake() 
    PlayerController[my_id] = 
    {
        mappingContext = GetMappingContext("MC_Player")
    }        
end 

You can then in a later function access the mappingContext variable to query the input action. There are two ways to query an input action:

function Update()
    local data = PlayerController[my_id]

    if data.mappingContext:ActionPressed("IA_MoveForward") then
        -- do moving things
    end

    if data.mappingContext:Fired("IA_Jump") then
        -- do moving things
    end
end

bool ActionPressed() - returns true if the button is currently being pressed bool Fired() - returns true only on the initial press of the button

Add Animations

Animations can be used to do nearly everything sequencial you need to accomplish in your game, you just need a little creativity. You can create an Animation in two ways:
  1. Create > Asset files > Animation
  2. In the File Explorer in empty space Right click > Add new > Animation

Open the newly created Animation by double clicking the file in the File Explorer or by opening the Animator window (Viewports > Animator) along with the Keyframe Editor (Viewports > Keyframe Editor).

From here you can open your Animation file using the expand button menu in the Animator window. (If you double clicked it should be opened in the Animator by default). Add properties to the new Animation using the dropdown menu. Select Transform from the dropdown and click "Add". To add keyframes, click on the new Transform button that appeared and click "Add Keyframe" just above the Animator Timeline. To edit the new keyframe, be sure you have the Keyframe Editor open and click on the keyframe diamond pip in the Animation timeline. You are free to drag each animation keyframe along the timeline grid to change the time the keyframe is played. You can also zoom in and out in the timeline window for more precision.

In the Keyframe Editor, the properties you can animate for any component are listed with a checkbox next to them. If you would like to animate a property you must check the box next to it to enable it. Change the scale property from x = 1, y = 1 to x = 2, y = 2 and save the animation using the same expand button menu you used to load the Animation.

Now we have to attach the Animation to a GameObject. Create a new GameObject with a Sprite component and add an image path to the Sprite by dragging one from the File Explorer viewport or by using the folder button next to the input. Now add an Animation component to the GameObject and drag our new Animation into the input or click the folder button next to the input and give the Animation a name that we can use to reference it, then click "Add Animation" to officially add the animation to our GameObject. Don't forget to save the scene using File > Save Scene ... or click on the expand button menu in the top right of the Hierarchy viewport and click "Save Scene" or "Save all". Now that our GameObject has the Animation attached to it we can click "Preview" in the Animation component to preview the Animation on our GameObject in the SceneView while the game loop is running.

To call this animation and play it using scripts we can use:


GameObject:GetAnimation():Play("nameOfAnimation")

Where nameOfAnimation is the name we gave it in the Animation component of the GameObject.


Building The Final Project

To build a game Project, open the Project Settings by clicking Settings -> Project Settings:


navigateToProjectSettings


Then make sure to set the Game start Scene path and the Final project build path. The Game start Scene path must be relative to the FlatEngine-Runtime folder. ie. ../projects/project_name/scenes/scene_name.scn. The build path can be an absolute path. Neither paths should contain quotation marks.


projectSettings


Then, you can build your final game by clicking the Settings -> Build Project button in the main menu bar. FlatEngine2D will create a directory in the location you specified and move all the required files over.


buildproject


If you've configured the settings correctly as stated above, you should end up with a folder containing something like this:


finalBuildDirectory


Go into the Runtime folder and you'll see:


executable


All of these files are important for your game to work properly except for the log_output.txt files and the .pdb files, which can safely be deleted. You can now rename the .exe file to anything you want and run it. Your game is now ready to be zipped up and distributed! Congratulations!


That is the general intended work flow of FlatEngine2D. This will be updated as development progresses but I hope this is enough to get you started. Read on for specifics about scripting in FlatEngine2D using Lua.


Lua Scripting in FlatEngine

Please see the section at the very bottom where every engine and class function exposed to Lua is listed along with a description of what it does and what it returns.

Scripting in FlatEngine2D is done in a specific way due to how Lua is implemented in it. Before each script is run, a Lua table is created for each Lua Script that exists. These tables will be used by each script of the same name to keep track of and access each instance of the GameObject that "owns" a copy, using the GameObjects ID. For example:

A Script named "Health" is created. At time of creation, a new Lua table is made called Health. Then, in the Awake() function of the PlayerController.scp.lua script file, a new index in the Health table is created using the ID of the GameObject. This means that each GameObject can only have ONE script component for each script that exists. You cannot have two script components that have the same Script attached in one GameObject (I am not sure why you would want to anyway). IMPORTANT: All data that is specific to this script that needs to be tracked and accessed on a per-object basis MUST be put inside this table if you want to access it later in the script and from other script files. This is because of the global nature of the Lua implementation. Every Script sees every other Script and every other function.

Note: GameObject IDs can be viewed by hovering over a GameObject in the Hierarchies and holding left alt. The same can be done to view the IDs of components in the Inspector View.

Let us say that you want to track the health of whatever GameObject that is using this script. In the Awake() function of this script you would add your health variables like so:

-- Health.scp.lua

function Awake() 
    Health[my_id] = 
    {
        totalHealth = 20,
        currentHealth = 20
    }        
end 

If you then needed to access these values for the specific GameObject, you need to access the Health table using the id of the specific GameObject you are interested in. Now, there are two different ways a script can be accessed in FlatEngine:

  1. Through the engine, either via the main script functions: Awake, Start, and Update, or through an Animation Event call.
  2. From other scripts

When a script is called in the first way, the script is "initialized" by FlatEngine, which just means it sets some variables that you can access with Lua to specific values. It sets the variable this_object to the GameObject that is calling the function, and it sets the variable my_id to the ID of the GameObject that is being called. If the Script is called via the engine you can use the my_id variable in conjunction with the script table to access the data of the specific script instance (in the Update() function of the Health script, for example) like so:

-- Health.scp.lua

function Update()
    local data = Health[my_id]
    
    if data.currentHealth == 0 then
        -- do death things
    end
end

-- ignore this for now
function Damage(id, amount)
    local data = Health[id]
    data.currentHealth = data.currentHealth - amount
end

The data variable is a convenient way to not have to type Health[my_id].currentHealth every time and it is local because the default for Lua variables is global and we want to keep this variable only accessable to this Update function.

For the second way a script can be called, through another script, you must ensure that the ID you are referencing belongs to the script you actually want to perform actions on before you do so. Let's say you have a BlasterRound script that when OnBoxCollisionEnter is called it needs to tell whoever it collided with that it has done damage:

-- BlasterRound.scp.lua

function OnBoxCollisionEnter(collidedWith)
     local data = BlasterRound[my_id]
     local collidedID = collidedWith:GetParentID()

     if collidedWith:GetParent():HasTag("Enemy") then          
          Damage(collidedID, 5)          
     end     
end

There is a lot going on here so let's break it down:

This function, OnBoxCollisionEnter(), is one of many functions that are called during specific events by FlatEngine. It is called whenever this object collides with another GameObject. Because it is a function that is called by the engine, it is guaranteed that the my_id and this_object variables will contain the data associated with this scripts instance so we can freely use my_id to access its data. However, because we need to communicate with another script to tell it to do damage, we have to get ahold of that objects ID. To do that we can use the GetParentID() function. This function is a function of the Component class and can be used on any component to get the ID of the GameObject that owns it. Convenient! Let's continue:

local data = BlasterRound[my_id]
We saw this earlier. We are using the my_id variable to gain access to the script instances data and storing it in the local data variable.

local collidedID = collidedWith:GetParentID()
collidedWith is a of type BoxCollider, which like all components, has a GetParentID() function. We assign the BoxColliders parent ID to a local variable collidedID.

if collidedWith:GetParent():HasTag("Enemy") then
GetParent() is a Component function that gets the actual GameObject that owns this component. HasTag() is a boolean function that checks for a specific Tag on a GameObject (not as important to this demonstration).

Damage(collidedID, 5)
This is a call to a function in another Script file. The Damage function lives in the Health script file we saw above. It takes two parameters: id and amount. Because this function is intended to be called by other script files, we require an ID be passed to it to specify which script instance we are doing damage to. From the BlasterRound script, we call the Damage() function using the ID of the GameObject that we want to do damage to along with the damage amount, 5. This way the Health script knows the data it is operating on is the intended data. If we were to have used the my_id variable inside the Damage() function like this (DON'T DO THIS):

function Damage(amount)
    -- DON'T DO THIS --
    local data = Health[my_id]
    data.currentHealth = data.currentHealth - amount
end

Then when the Damage function is called from BlasterRound in the OnBoxCollisionEnter() function, the engine will have assigned the variables my_id and this_object with references to the BlasterRound object (in this case), the Damage() function would be doing damage to the BlasterRound GameObject because it is accessing the table using its ID. That is also assuming there is any data to access in the first place, as the BlasterRound GameObject may not even have a Health script with data to access.

Hopefully this distinction makes sense because it is essential in understanding how Lua operates on GameObjects within FlatEngine.

If this doesn't make sense, I recommend looking into Lua and what is really happening when a Lua script file is opened. The short of it is that the script files are just for show. All Lua is run within the same environment so all of the functions in every script (except those that live inside of other functions) are accessable by all other functions in all other script files at any time. So every time a script is loaded, it is just pooling the functions in that script into a table to be operated on within the same global environment as all the other scripts. That is why we need to enclose the data specific to each object in a table that is only accessable via Script name tables with GameObject IDs as keys. Otherwise there would be no way to know whose data any given function needs to access at any given moment.

Here is a list of every function that is called by the engine at specific times and therefore is guaranteed to have the my_id and this_object variables set to whatever GameObject is currently being referred to by the script:

Awake() -- Called upon instantiation of the GameObject
Start() -- Called after all Awake functions have been called upon instantiation of the GameObject
Update() -- Called once per frame
OnBoxCollision(collidedWith) -- Called every frame there is a collision happening on an object that has a BoxCollider that is colliding
OnBoxCollisionEnter(collidedWith) -- Called on the first frame a collision happens on an object that has a BoxCollider that is colliding
OnBoxCollisionLeave(collidedWith) -- Called when a collision ceases on an object that has a BoxCollider that is now no longer colliding
OnCircleCollision(collidedWith) -- Called every frame there is a collision happening on an object that has a CircleCollider that is colliding
OnCircleCollisionEnter(collidedWith) -- Called on the first frame a collision happens on an object that has a CircleCollider that is colliding
OnCircleCollisionLeave(collidedWith) -- Called when a collision ceases on an object that has a CircleCollider that is now no longer colliding
OnButtonMouseOver() -- Called every frame the mouse is hovering a Button
OnButtonMouseEnter() -- Called on the first frame a mouse is hovering a Button
OnButtonMouseLeave() -- Called when the mouse stops hovering a Button
OnButtonLeftClick() -- Called when a Button is left clicked
OnButtonRightClick() -- Called when a Button is right clicked
Animation Events -- Any Animation Event function that is called during an Animation


Lua Functions Available

This is a comprehensive list of all functions that can be called in Lua to interact with FlatEngine2D, GameObjects, and their components:

CreateGameObject(long parentID = -1)
Action: Creates a GameObject.
Parameters: long parentID = -1 - ID of the GameObject to parent it to. defaults to -1 by default for no parent.
Returns: GameObject* - pointer to the new GameObject

CreateStringVector()
Action: Creates a new std::vector<std::string>().
Parameters: None
Returns: std::vector<std::string>()

CreateIntVector()
Action: Creates a new std::vector<int>().
Parameters: None
Returns: std::vector<int>()

CreateLongVector()
Action: Creates a new std::vector<long>().
Parameters: None
Returns: std::vector<long>()

CreateFloatVector()
Action: Creates a new std::vector<float>().
Parameters: None
Returns: std::vector<float>()

CreateDoubleVector()
Action: Creates a new std::vector<double>().
Parameters: None
Returns: std::vector<double>()

CreateBoolVector()
Action: Creates a new std::vector<bool>().
Parameters: None
Returns: std::vector<bool>()

IntToString(int value)
Action: Converts an int to an std::string.
Parameters: int value
Returns: std::string - the converted value.

LongToString(long value)
Action: Converts a long to an std::string.
Parameters: long value
Returns: std::string - the converted value.

FloatToString(float value)
Action: Converts a float to an std::string.
Parameters: float value
Returns: std::string - the converted value.

DoubleToString(double value)
Action: Converts a double to an std::string.
Parameters: double value
Returns: std::string - the converted value.

GetInstanceData(std::string scriptName, long ID)
Action: Gets the data table associated with a given Script instance.
Parameters: std::string scriptName, long ID - ID: ID of the GameObject that owns the Script component.
Returns: table instanceData - a Lua table with the data.

ContainsData(std::string scriptName, long ID)
Action: Checks whether a Lua table of instance data exists for a specified Script name with specified GameObject ID.
Parameters: std::string scriptName, long ID
Returns: bool - Whether a table entry exists or not.

GetScriptParam(std::string paramName, long ID, std::string scriptName = calling_script_name)
Action: Gets the specified ScriptParameter from the ParameterList on a specified Script component owned by a GameObject.
Parameters: std::string paramName, long ID, std::string scriptName
Returns: ScriptParameter - The requested parameter or empty ScriptParameter with type = empty if it doesn't exist. scriptName defaults to the calling script.

LoadGameObject(long ID)
Action: Sets the specified GameObject as the loaded GameObject. This sets the this_object and myID Lua variables to that GameObject.
Parameters: long ID - The desired GameObjects ID.
Returns: void

GetObjectByID(long ID)
Action: Gets a GameObject based on ID.
Parameters: long ID - The desired GameObjects ID.
Returns: GameObject* - The GameObject with specified ID or nullptr if it doesn't exist.

GetObjectByName(std::string objectName)
Action: Gets a GameObject in the loaded scene by name.
Parameters: std::string objectName - name of the object you want.
Returns: GameObject*

LoadScene(std::string sceneName)
Action: Loads a scene
Parameters: std::string sceneName - name of the scene to load.
Returns: void

ReloadScene()
Action: Reload the currently loaded scene.
Parameters: std::string sceneName - name of the scene to reload.
Returns: void

GetLoadedScene()
Action: Gets the currently loaded scene.
Parameters: none
Returns: Scene* - The current Scene or nullptr if no Scene is loaded.

LogString(std::string line)
Action: Log a string to the console.
Parameters: std::string line - string to log
Returns: void

LogInt(int value, std::string line = "")
Action: Log an int to the console and a string that will be prefixed to the value.
Parameters: int value - value to log, line - (optional) string that will be prefixed to the value
Returns: void

LogFloat(float value, std::string line = "")
Action: Log an float to the console and a string that will be prefixed to the value.
Parameters: float value - value to log, line - (optional) string that will be prefixed to the value
Returns: void

LogDouble(double value, std::string line = "")
Action: Log an double to the console and a string that will be prefixed to the value.
Parameters: double value - value to log, line - (optional) string that will be prefixed to the value
Returns: void

LogLong(long value, std::string line = "")
Action: Log an long to the console and a string that will be prefixed to the value.
Parameters: long value - value to log, line - (optional) string that will be prefixed to the value
Returns: void

GetMappingContext(std::string contextName)
Action: Get a copy of a Mapping Context object by name.
Parameters: std::string contextName - Name of the Mapping Context
Returns: MappingContext* - or nullptr if none exists with that name.

Instantiate(std::string prefabName, Vector2 position)
Action: Instantiate a Prefab at a specific location
Parameters: prefabName - name of the Prefab to spawn, position - the position in the game world to spawn the Prefab.
Returns: GameObject*

CloseProgram()
Action: Closes the game and the editor.
Parameters: none
Returns: void

SceneDrawLine(Vector2 startPoint, Vector2 endPoint, Vector4 color, float thickness)
Action: Draws a debug line inside the Scene View.
Parameters: Vector2 startPoint, Vector2 endPoint, Vector4 color, float thickness
Returns: void

SceneGameLine(Vector2 startPoint, Vector2 endPoint, Vector4 color, float thickness)
Action: Draws a debug line inside the Game View.
Parameters: Vector2 startPoint, Vector2 endPoint, Vector4 color, float thickness
Returns: void

GetTime()
Action: Get the time in milliseconds the gameloop has been active (started and unpaused).
Parameters: none
Returns: Uint32

Destroy(long ID)
Action: Delete a GameObject by ID
Parameters: ID - ID of the GameObject to delete
Returns: void

GetColor(std::string color)
Action: Gets the Vector4 that represents a color in the Colors.lua file in the project directory
Parameters: color - name of the color in the Colors.lua file in FlatEngine -> engine -> scripts -> Colors.lua
Returns: Vector4

RandomInt(int min, int max)
Action: Get a random int between two values.
Parameters: int min, int max
Returns: int

RandomInt(float min, float max)
Action: Get a random float between two values.
Parameters: float min, float max
Returns: float

Remap(std::string contextName, std::string inputAction, int timeoutTime)
Action: Begins a timer that allows the next button press to map to the specified InputAction on the specified MappingContext.
Parameters: std::string contextName, std::string inputAction - InputAction to remap, int timeoutTime - how long in milliseconds to allow for input before timing out.
Returns: void


FlatEngine classes exposed to Lua - Lua usertypes

Class Vector2

Method Details
Vector2(), Vector2(float x,float y) Action: Constructors
Parameters: float x, float y - values to set x and y to.
\Returns: Vector2
SetX(float x) Action: Sets the x-value of the Vector2.
Parameters: float x - the value to set x to.
Returns: void
x() Action: Gets the x component.
Parameters: none
Returns: float
SetY(float y) Action: Sets the y-value of the Vector2.
Parameters: float y - the value to set y to.
Returns: void
y() Action: Gets the y component.
Parameters: none
Returns: float
SetXY(float x, float y) Action: Sets both the x and y components.
Parameters: float x, float y
Returns: none

Class Vector4

Method Details
Vector4(), Vector4(float x, float y, float z, float w) Action: Constructors
Parameters: float x, float y, float z, float w - values to set x, y, z, and w to.
Returns: Vector4
SetX(float x) Action: Sets the x-value of the Vector2.
Parameters: float x - the value to set x to.
Returns: void
x() Action: Gets the x component.
Parameters: none
Returns: float x
SetY(float y) Action: Sets the y-value of the Vector2.
Parameters: float y - the value to set y to.
Returns: void
y() Action: Gets the y component.
Parameters: none
Returns: float y
SetZ() Action: Sets the z component.
Parameters:
Returns: void
z() Action: Gets the z component.
Parameters:
Returns: float z
SetW() Action: Sets the w component.
Parameters:
Returns: void
w() Action: Gets the w component.
Parameters:
Returns: float w
SetXYZW() Action: Sets all four components.
Parameters:
Returns: void

Class Scene

Method Details
SetName(std::string name) Action: Sets the name of calling Scene.
Parameters: std::string name
Returns: void
GetName() Action: Gets the name of calling Scene.
Parameters: none
Returns: std::string
GetPath() Action: Returns the filepath of the calling Scene.
Parameters: none
Returns: std::string

Class GameObject

Method Details
GetID() Action: Gets GameObject ID.
Parameters: none
Returns: long
GetName() Action: Gets GameObject name.
Parameters: none
Returns: std::string
SetName(std::string name) Action: Sets GameObject name.
Parameters: std::string name
Returns: void
IsActive() Action: Returns whether the GameObject is set to Active.
Parameters: none
Returns: bool
SetActive(bool isActive) Action: Sets the GameObject as active or inactive.
Parameters: bool isActive
Returns: void
GetParent() Action: Gets the GameObjects parent.
Parameters: none
Returns: GameObject or nullptr if it doesn't have one.
GetParentID() Action: Gets the GameObjects parent ID.
Parameters: none
Returns: long
HasTag(std::string tag) Action: Returns whether the GameObject has a Tag.
Parameters: std::string tag
Returns: bool
SetTag(std::string tag, bool hasTag) Action: Sets specified Tag for the GameObject.
Parameters: std::string tag, bool hasTag
Returns: void
SetIgnore(std::string, bool ignores) Action: Sets specified Tag for the GameObject to ignore.
Parameters: std::string ignoreTag, bool ignores
Returns: void
GetTransform() Action: Gets the Transform Component.
Parameters: none
Returns: Transform* or nullptr
GetSprite() Action: Gets the Sprite Component.
Parameters: none
Returns: Sprite* or nullptr
GetCamera() Action: Gets the Camera Component.
Parameters: none
Returns: Camera* or nullptr
GetScript() Action: Gets the Script Component.
Parameters: none
Returns: Script* or nullptr
GetAnimation() Action: Gets the Animation Component.
Parameters: none
Returns: Animation* or nullptr
GetAudio() Action: Gets the Audio Component.
Parameters: none
Returns: Audio* or nullptr
GetButton() Action: Gets the Button Component.
Parameters: none
Returns: Button* or nullptr
GetCanvas() Action: Gets the Canvas Component.
Parameters: none
Returns: Canvas* or nullptr
GetText() Action: Gets the Text Component.
Parameters: none
Returns: Text* or nullptr
GetCharacterController() Action: Gets the CharacterController Component.
Parameters: CharacterController
Returns: CharacterController* or nullptr
GetRigidBody() Action: Gets the RigidBody Component.
Parameters: none
Returns: RigidBody* or nullptr
GetBoxCollider() Action: Gets the BoxCollider Component.
Parameters: none
Returns: BoxCollider* or nullptr
GetCircleCollider() Action: Gets the CircleCollider Component.
Parameters: none
Returns: CircleCollider* or nullptr
GetTileMap() Action: Gets the TileMap Component.
Parameters: none
Returns: TileMap* or nullptr
AddSprite() Action: Adds and returns a Sprite component to the GameObject if one doesn't already exist.
Parameters: none
Returns: Sprite* or nullptr
AddScript() Action: Adds and returns a Script component to the GameObject.
Parameters: none
Returns: Script* or nullptr
AddCamera() Action: Adds and returns a Camera component to the GameObject if one doesn't already exist.
Parameters: none
Returns: Camera* or nullptr
AddAnimation() Action: Adds and returns an Animation component to the GameObject if one doesn't already exist.
Parameters: none
Returns: Animation* or nullptr
AddAudio() Action: Adds and returns an Audio component to the GameObject if one doesn't already exist.
Parameters: none
Returns: Audio* or nullptr
AddButton() Action: Adds and returns a Button component to the GameObject if one doesn't already exist.
Parameters: none
Returns: Button* or nullptr
AddCanvas() Action: Adds and returns a Canvas component to the GameObject if one doesn't already exist.
Parameters: none
Returns: Canvas* or nullptr
AddText() Action: Adds and returns a Text component to the GameObject if one doesn't already exist.
Parameters: none
Returns: Text* or nullptr
AddCharacterController() Action: Adds and returns a CharacterController component to the GameObject if one doesn't already exist.
Parameters: none
Returns: CharacterController* or nullptr
AddRigidBody() Action: Adds and returns a RigidBody component to the GameObject if one doesn't already exist.
Parameters: none
Returns: RigidBody* or nullptr
AddBoxCollider() Action: Adds and returns a BoxCollider component to the GameObject if one doesn't already exist.
Parameters: none
Returns: BoxCollider* or nullptr
AddCircleCollider() Action: Adds and returns a CircleCollider component to the GameObject if one doesn't already exist.
Parameters: none
Returns: CircleCollider* or nullptr
AddTileMap() Action: Adds and returns a TileMap component to the GameObject if one doesn't already exist.
Parameters: none
Returns: TileMap* or nullptr
AddChild(long childID) Action: Adds specified child to GameObject.
Parameters: long childID
Returns: void
RemoveChild() Action: Removes specified child from GameObject.
Parameters: long childID
Returns: void
GetFirstChild() Action: Gets the first child found on a GameObject. Not necessarily the first in the Hierarchy.
Parameters:
Returns:
HasChildren() Action: Returns whether the GameObject has children.
Parameters: none
Returns: bool hasChildren
GetChildren() Action: Gets the GameObjects children.
Parameters: none
Returns: std::vector<long> - IDs of the children.
HasScript() Action: Returns whether a GameObject Has a Script with specified name.
Parameters: std::string scriptName
Returns: bool hasScript
FindChildByName(std::string childName) Action: Gets specified child of GameObject by name.
Parameters: std::string childName
Returns: GameObject* or nullptr if no child exists with that name.

Class Transform

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetPosition(Vector2 scale) Action: Sets the position of the GameObject.
Parameters: Vector2 position
Returns: void
GetPosition() Action: Gets the GameObjects current position relative to it's origin.
Parameters: none
Returns: Vector2 relativePosition
GetTruePosition() Action: Gets the GameObjects current position relative to the center point of the Scene.
Parameters: none
Returns: Vector2 truePosition
SetRotation(float rotation) Action: Sets the rotation in degrees of the GameObjects. Only effects Sprites currently.
Parameters: float rotation
Returns: void
GetRotation() Action: Gets the rotation in degrees of the GameObject.
Parameters: none
Returns: float rotation
SetScale(Vector2 scale) Action: Sets the x and y scale of the GameObject. Should effect all components.
Parameters: Vector2 scale
Returns: void
GetScale() Action: Gets the x and y scale of the GameObject.
Parameters: none
Returns: Vector2 scale
LookAt() Action: Causes the GameObject to rotate at the specified position.
Parameters: Vector2 position
Returns: void

Class Sprite

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetActive(bool isActive) Action: Sets the component as active or inactive.
Parameters: bool isActive
Returns: void
IsActive() Action: Returns whether the component is active.
Parameters: none
Returns: bool isActive
SetTexture(std::string texturePath) Action: Sets the path of the Sprites texture.
Parameters: std::string texturePath
Returns: void
GetPath() Action: Gets the path of the Sprites texture.
Parameters: none
Returns: std::string texturePath
SetScale(Vector2 scale) Action: Sets the x and y scale of the Sprites texture independantly and in addition to the Transform's scale.
Parameters: Vector2 scale
Returns: void
GetScale() Action: Gets the x and y scale of the Sprites texture.
Parameters: none
Returns: Vector2 scale
GetTextureWidth() Action: Gets the actual width of the texture in pixels.
Parameters: none
Returns: int pixelWidth
GetTextureHeight() Action: Gets the actual height of the texture in pixels.
Parameters: none
Returns: int pixelHeight
SetTintColor(Vector4 tintColor) Action: Sets the RGBA color to tint the Sprites texture.
Parameters: Vector4 tintColor - Vector4(x = red, y = green, z = blue, w = alpha)
Returns: void
GetTintColor() Action: Gets the RGBA tintColor of the Sprites texture.
Parameters: none
Returns: Vector4 tintColor - Vector4(x = red, y = green, z = blue, w = alpha)
SetAlpha(float alpha) Action: Set the alpha channel of the texture's tint color.
Parameters: float alpha
Returns: void
GetAlpha() Action: Gets the value of the alpha channel of the texture's tint color.
Parameters: none
Returns: float alpha
SetPivotPoint() Action: Sets the location the texture should pivot on when rotating.
Parameters: std::string pivotPoint - syntax expected for pivot point selection:Parameters: std::string pivotPoint - string syntax expected for pivot point selection: "PivotCenter", "PivotLeft", "PivotRight", "PivotTop", "PivotBottom", "PivotTopLeft", "PivotTopRight", "PivotBottomRight","PivotBottomLeft"
Returns: void

Class Text

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetActive(bool isActive) Action: Sets the component as active or inactive.
Parameters: bool isActive
Returns: void
IsActive() Action: Returns whether the component is active.
Parameters: none
Returns: bool isActive
SetText() Action: Sets the text displayed by the Text component.
Parameters: std::string displayedText
Returns: void
SetPivotPoint() Action: Sets the location the text should pivot on when rotating.
Parameters: std::string pivotPoint - string syntax expected for pivot point selection: "PivotCenter", "PivotLeft", "PivotRight", "PivotTop", "PivotBottom", "PivotTopLeft", "PivotTopRight", "PivotBottomRight","PivotBottomLeft"
Returns: void

Class Audio

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetActive(bool isActive) Action: Sets the component as active or inactive.
Parameters: bool isActive
Returns: void
IsActive() Action: Returns whether the component is active.
Parameters: none
Returns: bool isActive
IsSoundPlaying() Action: Returns true if the specified sound is playing.
Parameters:
Returns: bool isSoundPlaying
Play(std::string soundName) Action: Starts playing the specified sound attached to Audio component.
Parameters: std::string soundName
Returns: void
Pause(std::string soundName) Action: Pauses the specified sound attached to Audio component.
Parameters: std::string soundName
Returns: void
Stop(std::string soundName) Action: Stops playing the specified sound attached to Audio component.
Parameters: std::string soundName
Returns: void
StopAll() Action: Stops all sounds that are currently playing on the Audio component.
Parameters: none
Returns: void

Class Button

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetActive(bool isActive) Action: Sets the component as active or inactive.
Parameters: bool isActive
Returns: void
IsActive() Action: Returns whether the component is active.
Parameters: none
Returns: bool isActive
SetActiveDimensions(float width, float height) Action:
Parameters: float width, float height
Returns: void
SetActiveOffset(Vector2 activeOffset) Action: Set the amount in x and y that the Button is offset from it's Transform's position.
Parameters: Vector2 activeOffset
Returns: void
GetActiveOffset() Action: Gets the anount in x and y the Button is offset from it's Transform's position.
Parameters: none
Returns: Vector2 activeOffset
SetActiveLayer(float activeLayer) Action: Sets the Canvas layer the Button is active on and thus the priority it has over other Buttons on lower layers.
Parameters: float activeLayer
Returns: void
GetActiveLayer() Action: Gets the Buttons active Canvas layer.
Parameters: none
Returns: void
GetActiveWidth() Action: Gets the active width of the Button.
Parameters: none
Returns: float activeWidth
GetActiveHeight() Action: Gets the active height of the Button.
Parameters: none
Returns: float activeHeight
MouseIsOver() Action: Returns true if the mouse is hovering the button and can be clicked.
Parameters: none
Returns: bool mouseIsOver
SetLeftClick(bool leftClickable) Action: Set whether left clicking can activate the Button.
Parameters: bool leftClickable
Returns: void
GetLeftClick() Action: Returns true if the Button can be activated by a left click of the mouse.
Parameters: none
Returns: bool leftClickable
SetRightClick(bool rightClickable) Action: Set whether right clicking can activate the Button.
Parameters: bool rightClickable
Returns: void
GetRightClick() Action: Returns true if the Button can be activated by a right click of the mouse.
Parameters: none
Returns: bool rightClickable
SetLuaFunctionName(std::string functionName) Action: Set the Lua function name that will be called when the Button is activated.
Parameters: std::string functionName
Returns: void
GetLuaFunctionName() Action: Get the Lua function name that will be called when the Button is activated.
Parameters: none
Returns: std::string functionName
SetLuaFunctionParams(ParameterList functionParameters) Action: Set the list of function parameters, (ParameterList), that will be passed to the Button when it is activated.
Parameters: ParameterList functionParameters
Returns: void

Class Script

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetAttachedScript(std::string attachedScriptName) Action: Sets the Script that is attached to the Script component that will run during gameplay.
Parameters: std::string scriptName
Returns: void
GetAttachedScript() Action: Gets the Script that is attached to the Script component.
Parameters: none
Returns: std::string attachedScriptName
RunAwakeAndStart() Action: Run the Awake() and Start() Lua methods on the attached Script.
Parameters: none
Returns: void

Class Animation

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetActive(bool isActive) Action: Sets the component as active or inactive.
Parameters: bool isActive
Returns: none
IsActive() Action: Returns whether the component is active.
Parameters: none
Returns: bool isActive
Play(std::string animationName) Action: Play the specified Animation on the Animation component.
Parameters: std::string animationName
Returns: void
Stop(std::string animationName) Action: Stop the specified Animation on the Animation component.
Parameters: std::string animationName
Returns: void
StopAll() Action: Stops all Animations that are currently playing on the Animation component.
Parameters: none
Returns: void
IsPlaying(std::string animationName) Action: Returns true if the specified Animation is playing.
Parameters: std::string animationName
Returns: bool isPlaying
HasAnimation(std::string animationName) Action: Returns true if the Animation component has an Animation with specified name.
Parameters: std::string animationName
Returns: bool hasAnimation

Class ScriptParameter

Method Details
type() Action: Gets the type of the ScriptParameter. ("string", "int", "float", "double", "long", "bool", "Vector2")
Parameters: none
Returns: std::string type
SetType() Action: Sets the type of the parameter.
Parameters: std::string type - Can be "string", "int", "float", "double", "long", "bool", "Vector2"
Returns: void
string() Action: Gets the string value inside the ScriptParameter.
Parameters: none
Returns: std::string stringValue
int() Action: Gets the string value inside the ScriptParameter.
Parameters: none
Returns: int intValue
long() Action: Gets the long value inside the ScriptParameter.
Parameters: none
Returns: long longValue
float() Action: Gets the float value inside the ScriptParameter.
Parameters: none
Returns: float floatValue
double() Action: Gets the double value inside the ScriptParameter.
Parameters: none
Returns: double doubleValue
bool() Action: Gets the bool value inside the ScriptParameter.
Parameters: none
Returns: bool boolValue
Vector2() Action: Gets the Vector2 value inside the ScriptParameter.
Parameters: none
Returns: Vector2 vector2Value
SetString() Action: Sets the string value inside the ScriptParameter.
Parameters: std::string stringValue
Returns: none
SetInt() Action: Sets the int value inside the ScriptParameter.
Parameters: int intValue
Returns: none
SetLong() Action: Sets the long value inside the ScriptParameter.
Parameters: long longValue
Returns: none
SetFloat() Action: Sets the float value inside the ScriptParameter.
Parameters: float floatValue
Returns: none
SetDouble() Action: Sets the double value inside the ScriptParameter.
Parameters: double doubleValue
Returns: none
SetBool() Action: Sets the bool value inside the ScriptParameter.
Parameters: bool boolValue
Returns: none
SetVector2() Action: Sets the Vector2 value inside the ScriptParameter.
Parameters: Vector2 vector2Value
Returns: none

Class ParameterList

Method Details
SetParameters(std::vector<ScriptParameter> parameters) Action: Sets the ScriptParameters member variable of the ParameterList.
Parameters: std::vector<ScriptParameter> parameters
Returns: void
AddParameter(ScriptParameter parameters) Action: Add a the ScriptParameter to the ParameterList.
Parameters: ScriptParameter parameter
Returns: void

Class RigidBody

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetActive(bool isActive) Action: Sets the component as active or inactive.
Parameters: bool isActive
Returns: none
IsActive() Action: Returns whether the component is active.
Parameters: none
Returns: bool isActive
SetMass(float mass) Action:
Parameters:
Returns: void
GetMass() Action:
Parameters: none
Returns: float mass
SetRisingGravity(float risingGravity) Action: Sets the gravity experienced by the RigidBody in the positive y-direction.
Parameters: float risingGravity
Returns: void
GetRisingGravity() Action: Gets the gravity experienced by the RigidBody in the positive y-direction.
Parameters: none
Returns: float risingGravity
SetFallingGravity(float fallingGravity) Action: Sets the gravity experienced by the RigidBody in the negative y-direction.
Parameters: float fallingGravity
Returns: void
GetFallingGravity() Action: Gets the gravity experienced by the RigidBody in the negative y-direction.
Parameters: none
Returns: float fallingGravity
SetFriction(float friction) Action: Sets the ground friction experienced by the RigidBody.
Parameters: float friction
Returns: void
GetFriction() Action: Gets the ground friction experienced by the RigidBody.
Parameters: none
Returns: float friction
SetAngularDrag(float angularDrag) Action: Sets the rotational drag experienced by the RigidBody.
Parameters: float angularDrag
Returns: void
GetAngularDrag() Action: Gets the rotational drag experienced by the RigidBody.
Parameters: none
Returns: float angularDrag
SetAngularVelocity(float angularVelocity) Action: Set the angular velocity of the RigidBody.
Parameters: float angularVelocity
Returns: void
GetAngularVelocity() Action: Gets the angularVelocity of the RigidBody.
Parameters: none
Returns: float angularVelocity
SetTorquesAllowed(bool torquesAllowed) Action: Sets whether the RigidBody can experience torques (not tied to velocity).
Parameters: bool torquesAllowed
Returns: void
TorquesAllowed() Action: Returns whether the RigidBody can experience torques.
Parameters: none
Returns: bool torquesAllowed
AddForce(Vector2 forceDirection, float scale) Action: Add a force to the RigidBody in specified direction multiplied by scale.
Parameters: Vector2 forceDirection, float scale
Returns: void
AddTorque(float torque, float scale) Action: Add a rotational force to the RigidBody.
Parameters: float torque, float scale - torque can be negative or positive depending on desired direction.
Returns: void
GetVelocity() Action:
Parameters:
Returns:
SetPendingForces() Action: Sets the total combined force that will be applied to the RigidBody this frame.
Parameters: Vector2 pendingForces
Returns: ``void`
GetPendingForces() Action: Gets the total combined force that will be applied to the RigidBody this frame.
Parameters: none
Returns: Vector2 pendingForces
SetTerminalVelocity(float terminalVelocity) Action: Sets the terminal velocity of the RigidBody.
Parameters: float terminalVelocity
Returns: void
GetTerminalVelocity() Action: Gets the terminal velocity of the RigidBody.
Parameters: none
Returns: float terminalVelocity
IsGrounded() Action: Returns whether the GameObject is grounded. (uses attached BoxCollider to determine)
Parameters: none
Returns: bool isGrounded

Class Collider

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetActive(bool isActive) Action: Sets the component as active or inactive.
Parameters: bool isActive
Returns: none
IsActive() Action: Returns whether the component is active.
Parameters: none
Returns: bool isActive

Class BoxCollider - inherits from Collider

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetActive(bool isActive) Action: Sets the component as active or inactive.
Parameters: bool isActive
Returns: none
IsActive() Action: Returns whether the component is active.
Parameters: none
Returns: bool isActive

Class CircleCollider - inherits from Collider

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetActive(bool isActive) Action: Sets the component as active or inactive.
Parameters: bool isActive
Returns: none
IsActive() Action: Returns whether the component is active.
Parameters: none
Returns: bool isActive

Class CharacterController

Method Details
GetParent() Action: Gets the GameObject that the component is attached to.
Parameters: none
Returns: GameObject*
GetParentID() Action: Gets the ID of the GameObject the component is attached to.
Parameters: none
Returns: long ID
GetID() Action: Gets the ID of the component.
Parameters: none
Returns: long ID
SetActive(bool isActive) Action: Sets the component as active or inactive.
Parameters: bool isActive
Returns: none
IsActive() Action: Returns whether the component is active.
Parameters: none
Returns: bool isActive
MoveToward(Vector2 direction) Action: Causes the GameObject to move in specified direction at the maxSpeed indicated inside the component settings.
Parameters: Vector2 direction
Returns: void

Class InputMapping

Method Details
KeyCode() Action: Gets the key code associated with the InputMapping.
Parameters: none
Returns: std::string keyCode
InputActionName() Action: Gets the name of the InputAction associated with the InputMapping.
Parameters: none
Returns: std::string inputActionName

Class MappingContext

Method Details
Fired() Action: Returns true on initial press of InputAction key code.
Parameters: none
Returns: bool inputActionFired
ActionPressed() Action: Returns true if the key code for the InputAction is currently being pressed.
Parameters: none
Returns: bool inputActionPressed
GetName() Action: Gets the name of the MappingContext.
Parameters: none
Returns: std::sting name
GetInputMappings() Action: Gets the InputMappings associated with the MappingContext.
Parameters: none
Returns: std::vector<std::shared_ptr<InputMapping>> inputMappings

Editing Engine Colors and More

You may access and customize the colors of FlatEngine2D by opening and editing the file located at engine/scripts/Colors.lua.
You may access and customize the textures used by FlatEngine2D by opening and editing the file located at engine/scripts/Textures.lua.
You may access and customize the Tags used by FlatEngine2D GameObjects by opening and editing the file located at engine/scripts/Tags.lua.