JNGL
Easy to use cross-platform 2D game library
|
JNGL's main namespace. More...
Classes | |
struct | Achievement |
Unlockable Achievement (also called Trophy) More... | |
class | Alpha |
Object representing only the Alpha Channel in an RGBA color. More... | |
struct | AppParameters |
Parameters used to initialize the main window. More... | |
class | Channel |
An audio channel, different channels could be for example: "Music", "Speech" and "Sound Effects". More... | |
class | Color |
Object representing a RGB color. More... | |
class | Container |
Helper class to handle multiple instances of Widget. More... | |
class | Controller |
Object representing one Gamepad controller. More... | |
class | Drawable |
Base class for drawable objects with a position and a rectangle size. More... | |
class | Effect |
Base class for effects that can be applied to jngl::Widget. More... | |
class | Executor |
Executes a specific action, e.g. removes the Widget. More... | |
class | Finally |
Helper class which calls a function when being destroyed. More... | |
class | Font |
Font loaded from a TTF or OTF file. More... | |
class | FrameBuffer |
Image framebuffer object which can be rendered on. More... | |
class | ImageData |
Containing the pixel data of an image file. More... | |
class | Job |
Background job which stays part of the main loop independent of the active jngl::Work. More... | |
class | Label |
Simple Widget displaying a line of text. More... | |
class | Mat3 |
3x3 matrix More... | |
class | Mat4 |
4x4 matrix More... | |
class | Move |
class | Pixels |
Scale-dependent pixels, corresponds to actual pixels on the screen. More... | |
struct | Rect |
Simple struct for a rectangle, can be use with jngl::contains. More... | |
class | Rgb |
Object representing a RGB color, new version of jngl::Color (which will be deprecated in the future) More... | |
class | Rgba |
Object representing a RGBA color. More... | |
class | ScaleablePixels |
Scale-independent pixels, also called "screen pixels". More... | |
class | Shader |
Fragment or vertex GLSL shader. More... | |
class | ShaderProgram |
Linked vertex and fragment shaders. More... | |
class | Singleton |
Inherit from this class to create a singleton that will be destroyed when your games exits. More... | |
class | SoundFile |
Sound loaded from an OGG file. More... | |
class | Sprite |
Higher-level representation of an image. More... | |
class | Text |
Rectangle shaped text block. More... | |
class | TextLine |
Rectangle shaped text (in contrast to jngl::Text this only represents one line) More... | |
class | Vec2 |
Two-dimensional vector. More... | |
struct | Vertex |
Position and texture coordinates. More... | |
class | Video |
Ogg Theory video file. More... | |
class | Widget |
class | Work |
Active state of the game, e.g. a menu or the game itself. More... | |
class | WorkFactory |
class | Zoom |
Scales the ModelView matrix. More... | |
Enumerations | |
enum | KeyboardType : uint8_t { Default , Numpad } |
Whether a normal or a numbers-only keyboard should appear. More... | |
enum class | Alignment : uint8_t { LEFT , RIGHT , CENTER } |
How multiple lines should be aligned in a text block. More... | |
enum class | Cursor : uint8_t { ARROW , I } |
Functions | |
Color | interpolate (Color a, Color b, float t) |
Returns a color mix between a (t == 0) and b (t == 1) | |
void | setBackgroundColor (jngl::Rgb) |
Sets the screen's background color which is visible when nothing is drawn. | |
void | setBackgroundColor (unsigned char red, unsigned char green, unsigned char blue) |
Sets the screen's background color which is visible when nothing is drawn. | |
template<class T > | |
void | debug (const T &t) |
template<class T > | |
void | debugLn (const T &t) |
template<class Box > | |
bool | contains (const Box &box, const Vec2 point) |
Pass any class that implements getX(), getY(), getWidth() and getHeight() | |
void | print (const std::string &text, jngl::Vec2 position) |
Print text at position. | |
void | print (const std::string &text, int xposition, int yposition) |
Print text at { xposition, yposition }. | |
void | print (const Mat3 &modelview, const std::string &text) |
Print text using modelview. | |
int | getFontSize () |
Get the font size used by print() | |
void | setFontSize (int size) |
Change the font size used by print() | |
std::string | getFont () |
Returns the currently active font name. | |
void | setFont (const std::string &filename) |
Sets the currently active font to filename. | |
void | setFontByName (const std::string &name) |
Sets the currently active font by a font name. | |
void | setFontColor (Rgba) |
Sets the color and alpha value of the currently active font. | |
void | setFontColor (Rgb, float alpha=1.f) |
Sets the color of the currently active font and the alpha value. | |
void | setFontColor (unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255) |
Sets the color of the currently active font. | |
void | pushFontColor (unsigned char red, unsigned char green, unsigned char blue) |
Pushes the currently active font color on a stack and sets a new one. | |
void | popFontColor () |
Resets the font color on the top of stack which is used by jngl::pushFontColor. | |
double | getLineHeight () |
Get line height used py print() in scale-independent pixel. | |
void | setLineHeight (double) |
Set line height used by print() in scale-independent pixel. | |
double | getTextWidth (const std::string &text) |
Calculates the width of text in scale-independent pixels if it would be drawn with the currently active font. | |
void | setKeyboardVisible (bool) |
Display onscreen keyboard for touch devices. | |
void | setKeyboardType (KeyboardType) |
Type of the onscreen keyboard. | |
KeyboardType | getKeyboardType () |
Currently active type of onscreen keyboard. | |
void | setKeyPressed (const std::string &key, bool) |
Overwrite what keyPressed() should return. | |
void | setKeyPressed (key::KeyType key, bool) |
Overwrite what keyPressed() should return. | |
bool | keyDown (key::KeyType key) |
Whether key is down. | |
bool | keyDown (char key) |
Whether key is down. | |
bool | keyDown (const std::string &key) |
Whether key is down, where key should be exactly one UTF-8 character. | |
bool | keyPressed (key::KeyType key) |
Whether key has been pressed since the next to last call to updateInput() | |
bool | keyPressed (char key) |
Whether key has been pressed since the next to last call to updateInput() | |
bool | keyPressed (const std::string &key) |
Whether key has been pressed since the next to last call to updateInput(), where key should be exactly one UTF-8 character. | |
void | setRelativeMouseMode (bool relative) |
bool | getRelativeMouseMode () |
void | setMouseVisible (bool visible) |
By default the mouse cursor of the OS is visible and can be hidden by passing false. | |
bool | isMouseVisible () |
Returns whether the mouse cursor of the OS is currently visible. | |
bool | isMultitouch () |
Returns true when there's more than one finger touching the screen. | |
std::vector< jngl::Vec2 > | getTouchPositions () |
Returns all positions where a finger touches the screen. | |
Vec2 | getMousePos () |
Mouse position in screen coordinates. | |
optional< Vec2 > | getCursorPos () |
Returns the position of the mouse pointer if a mouse is connected/available. | |
int | getMouseX () |
Retrieve mouse position in pixels. | |
int | getMouseY () |
Retrieve mouse position in pixels. | |
double | getMouseWheel () |
Returns mouse wheel movement between -100 and 100 (0 if the mousewheel doesn't move) | |
bool | mouseDown (mouse::Button button=mouse::Left) |
Returns whether button is currently held down. | |
void | setMouseDown (mouse::Button button, bool) |
Overwrite what mouseDown() should return. | |
bool | mousePressed (mouse::Button button=mouse::Left) |
Whether button has been pressed since the next to last call to updateInput() | |
void | setMousePressed (jngl::mouse::Button, bool) |
Overwrite what mouseDown() should return. | |
void | setMouse (Vec2 position) |
Moves the mouse (does nothing on iOS and Android) | |
std::vector< std::shared_ptr< Controller > > | getConnectedControllers () |
Returns all controllers (gamepads) that are connected. | |
void | onControllerChanged (std::function< void()> callback) |
Specify a function which gets called, whenever a controller gets added or removed. | |
std::string | getTextInput () |
Returns a string of characters that have been pressed since the last call to updateInput() | |
void | addJob (std::shared_ptr< Job > job) |
Add a new Job which will be always be stepped and drawn by App::mainLoop() | |
template<class T , class... Args> | |
void | addJob (Args &&... args) |
The same as addJob(std::shared_ptr<Job>) but creates the Job for you. | |
void | removeJob (Job *) |
Removes the passed Job after all Jobs have been stepped. | |
std::shared_ptr< Job > | getJob (const std::function< bool(Job &)> &predicate) |
Returns the first Job for which predicate returned true. | |
template<class T > | |
std::shared_ptr< T > | getJob () |
Returns the first Job that is a T. | |
void | trace (const std::string &) |
template<class... Args> | |
void | trace (Args &&...) |
void | info (const std::string &) |
template<class... Args> | |
void | info (Args &&...) |
void | warn (const std::string &) |
template<class... Args> | |
void | warn (Args &&...) |
void | error (const std::string &) |
template<class... Args> | |
void | error (Args &&...) |
jngl::Mat3 | modelview () |
Returns a copy of the global ModelView matrix. | |
void | rotate (double degree) |
Multiplies the global ModelView matrix with a rotation matrix. | |
void | translate (double x, double y) |
Multiplies the global ModelView matrix with a translation matrix. | |
template<class Vect > | |
void | translate (Vect v) |
Multiplies the global ModelView matrix with a translation matrix. | |
void | scale (double factor) |
Multiplies the global ModelView matrix by a scaling matrix. | |
void | scale (double xfactor, double yfactor) |
Multiplies the global ModelView matrix by a scaling matrix. | |
void | pushMatrix () |
Pushes the current ModelView matrix on a global stack. | |
void | popMatrix () |
Replaces the current ModelView matrix with the top element of the global stack. | |
void | reset () |
Resets the global ModelView matrix to the identity matrix. | |
void | errorMessage (const std::string &text) |
Shows a message box with an error text. | |
void | printMessage (const std::string &text) |
Prints text on stdout. | |
bool | running () |
Returns true until the main window is closed or quit() has been called. | |
void | updateInput () |
Updates the input state. | |
void | swapBuffers () |
Swaps back and front buffer. | |
void | clearBackBuffer () |
Clears the back buffer and resets the ModelView matrix, see jngl::reset() | |
bool | canQuit () |
Some platforms (e.g. | |
void | quit () noexcept |
Emit a quit event which will exit App::mainLoop() and set running() to false. | |
void | cancelQuit () |
Undo quit() or ignore a quit event caused by the user closing the main window. | |
double | getFPS () |
Calculates FPS if called once per frame. | |
unsigned int | getStepsPerSecond () |
How many times Work::step is called per second (default: 60) | |
void | setStepsPerSecond (unsigned int) |
How many times Work::step should be called per second (default: 60) | |
void | setAntiAliasing (bool enabled) |
Toggles Multisample anti-aliasing (MSAA) | |
bool | getAntiAliasing () |
Returns whether MSAA is enabled. If the device doesn't support it, it will always return false. | |
void | setVerticalSync (bool enabled) |
Toggles V-SYNC. | |
bool | getVerticalSync () |
Returns whether V-SYNC is enabled. Many devices always enable V-SYNC with no way to turn it off. | |
void | setIcon (const std::string &filename) |
Sets the icon for the window (Desktop-only) | |
void | setPrefix (const std::string &path) |
Sets a global prefix which will be prepended whenever images or sounds are loaded. | |
std::string | getPrefix () |
Returns the global prefix set by jngl::setPrefix. | |
void | setConfigPath (const std::string &path) |
std::string | getConfigPath () |
std::string | getBinaryPath () |
Returns the directory of the currently running binary. | |
void | setArgs (std::vector< std::string >) |
Called by JNGL_MAIN_BEGIN to set command line arguments. | |
std::vector< std::string > | getArgs () |
Returns the command line arguments passed to the executable. | |
std::stringstream | readAsset (const std::string &filename) |
Returns a stringstream containing the whole file. This will read from the .apk on Android. | |
std::string | readConfig (const std::string &key) |
Read in a configuration value which has been saved under key. | |
void | writeConfig (const std::string &key, const std::string &value) |
Write value into the persistent storage which can be read in again using jngl::readConfig(key) | |
std::string | getPreferredLanguage () |
Returns user preferred language, i.e. "en" for English, "de" for German. | |
void | openURL (const std::string &) |
Opens a link (e.g. https://bixense.com) in the browser. | |
int | round (double v) |
Rounds a double to an integer, just like std::lround. | |
bool | operator> (jngl::Pixels, jngl::Pixels) |
Pixels | operator/ (Pixels, float) |
Rgb | interpolate (Rgb a, Rgb b, float t) |
Returns a color mix between a (t == 0) and b (t == 1) | |
Rgba | interpolate (Rgba a, Rgba b, float t) |
Returns a color mix between a (t == 0) and b (t == 1) | |
double | getScaleFactor () |
Size of one screen pixel in actual pixels. | |
void | setScaleFactor (double) |
Overwrite the size of one screen pixel. | |
double | getScreenWidth () |
jngl::getScreenSize().x | |
double | getScreenHeight () |
jngl::getScreenSize().y | |
Vec2 | getScreenSize () |
Returns the size of the useable draw area (excluding letter-boxing) in screen pixels. | |
void | setUniform (int location, float v0, float v1) |
void | setColor (Rgb) |
Sets the color which should be used to draw primitives. | |
void | setColor (Rgba) |
Sets the color (including alpha) which should be used to draw primitives. | |
void | setColor (Rgb, unsigned char alpha) |
Sets the color and alpha which should be used to draw primitives. | |
void | setColor (unsigned char red, unsigned char green, unsigned char blue) |
void | setColor (unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha) |
void | setAlpha (uint8_t alpha) |
Sets the alpha value which should be used to draw primitives (0 = fully transparent, 255 = fully opaque) | |
void | pushAlpha (unsigned char alpha) |
void | popAlpha () |
void | setLineWidth (float width) |
void | drawLine (Vec2 start, Vec2 end) |
Draws a line from start to end, the width can be set using setLineWidth. | |
void | drawLine (double xstart, double ystart, double xend, double yend) |
void | drawLine (const Mat3 &modelview, Vec2 end) |
Draws a line from (0, 0) to end. | |
void | drawEllipse (float xmid, float ymid, float width, float height, float startAngle=0) |
void | drawEllipse (Vec2, float width, float height, float startAngle=0) |
void | drawEllipse (Mat3 modelview, float width, float height, float startAngle=0) |
void | drawCircle (Vec2, float radius, float startAngle=0) |
Angles in radian. | |
void | drawCircle (Mat3 modelview, float radius, float startAngle) |
void | drawCircle (Mat3 modelview, float radius) |
void | drawCircle (Mat3 modelview, float radius, Rgba color) |
Draws a circle at (0, 0) with radius in color. | |
void | drawCircle (Mat3 modelview, Rgba color) |
Draws a circle at (0, 0) with radius of 1 in color. | |
void | drawPoint (double x, double y) |
void | drawTriangle (Vec2 a, Vec2 b, Vec2 c) |
Draws the triangle a -> b -> c. | |
void | drawTriangle (double A_x, double A_y, double B_x, double B_y, double C_x, double C_y) |
void | drawRect (double xposition, double yposition, double width, double height) |
Draws a rectangle at { xposition, yposition }. | |
void | drawRect (Vec2 position, Vec2 size) |
Draws a rectangle at position. | |
void | drawRect (const Mat3 &modelview, Vec2 size, Color) |
Draws a rectangle spawning from (0, 0) to (size.x, size.y) with the specified color. | |
void | drawRect (const Mat3 &modelview, Vec2 size, Rgba color) |
Draws a rectangle spawning from (0, 0) to (size.x, size.y) with the specified color. | |
template<class Vect > | |
void | drawRect (Vect pos, Vect size) |
float | getVolume () |
void | play (const std::string &filename) |
Play an OGG audio file once. | |
void | stop (const std::string &filename) |
Stop an OGG audio file if it's currently playing. | |
bool | isPlaying (const std::string &filename) |
std::shared_ptr< SoundFile > | loop (const std::string &filename) |
Play an OGG audio file in a loop. | |
void | setPlaybackSpeed (float speed) |
Set global pitch in (0.0f, ∞]. Default is 1.0f. | |
void | setVolume (float volume) |
Set global volume in [0, ∞]. Default is 1.0f. | |
Finally | pauseAudio () |
Pauses the playback of all audio; destroying the returned Finally object will resume again. | |
void | draw (const std::string &filename, double x, double y) |
template<class Vect > | |
void | draw (const std::string &filename, Vect pos) |
Finally | load (const std::string &filename) |
Starts a thread to load filename and returns a Finally which will join it. | |
void | unload (const std::string &filename) |
void | unloadAll () |
void | drawClipped (const std::string &filename, double xposition, double yposition, float xstart, float xend, float ystart, float yend) |
void | setSpriteColor (unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha) |
void | setSpriteColor (unsigned char red, unsigned char green, unsigned char blue) |
void | setSpriteColor (Rgb) |
Sets the global color used for drawing Sprites, leaves the alpha value untouched. | |
void | setSpriteColor (Rgba) |
Sets the global color used for drawing Sprites. | |
void | setSpriteAlpha (unsigned char alpha) |
void | pushSpriteAlpha (unsigned char alpha=255) |
void | popSpriteAlpha () |
int | getWidth (const std::string &filename) |
int | getHeight (const std::string &filename) |
Finally | disableBlending () |
double | getTime () |
Returns seconds that have passed since program start. | |
void | sleep (int milliseconds) |
Sleep current thread for milliseconds. | |
std::ostream & | operator<< (std::ostream &, const Vec2 &) |
Prints the vector like this: [x=…, y=…]. | |
void | showWindow (const std::string &title, int width, int height, bool fullscreen=false, std::pair< int, int > minAspectRatio={ 4, 3 }, std::pair< int, int > maxAspectRatio={ 16, 9 }) |
Creates the main window. | |
void | hideWindow () |
Cleans up the window and unloads everything. | |
void | atExit (std::function< void()>) |
Call this function once when the window is hidden. | |
int | getWindowWidth () |
Returns the width of the window in actual pixels (i.e. ignoring jngl::getScaleFactor) | |
int | getWindowHeight () |
Returns the height of the window in actual pixels (i.e. ignoring jngl::getScaleFactor) | |
std::array< Pixels, 2 > | getWindowSize () |
Returns {width, height} of the window in actual pixels. | |
int | getDesktopWidth () |
Returns the width of the main display in actual pixels. | |
int | getDesktopHeight () |
Returns the height of the main display in actual pixels. | |
bool | getFullscreen () |
If the window is displayed fullscreen (always true on mobile devices) | |
void | setFullscreen (bool) |
Toggle fullscreen window mode. | |
void | setTitle (const std::string &title) |
Sets the main window title. | |
void | setCursor (Cursor) |
std::vector< float > | readPixels () |
Read red, green and blue values of the whole window frame buffer. | |
std::shared_ptr< Work > | getWork () |
Returns the current active Work or nullptr if none has been set. | |
void | setWork (std::shared_ptr< Work > work) |
Sets the passed Work to be active in App::mainLoop() | |
template<class T , class... Args> | |
void | setWork (Args &&... args) |
The same as setWork(std::shared_ptr<Work>) but creates the Work for you. | |
void | setWork (Work *) |
void | resetFrameLimiter () |
Resets the automatic frame limiter of App::mainLoop(). | |
JNGL's main namespace.
enum KeyboardType : uint8_t |
|
strong |
|
strong |
Definition at line 65 of file window.hpp.
void setBackgroundColor | ( | unsigned char | red, |
unsigned char | green, | ||
unsigned char | blue ) |
Sets the screen's background color which is visible when nothing is drawn.
bool contains | ( | const Box & | box, |
const Vec2 | point ) |
Pass any class that implements getX(), getY(), getWidth() and getHeight()
Definition at line 90 of file Drawable.hpp.
std::string getFont | ( | ) |
Returns the currently active font name.
This will either return a font name if jngl::setFont was used or a font name if jngl::setFontByName was used.
void setFont | ( | const std::string & | filename | ) |
Sets the currently active font to filename.
This can either be a TTF or OTF file.
void setFontByName | ( | const std::string & | name | ) |
Sets the currently active font by a font name.
std::runtime_error | If the font couldn't be found. |
void setFontColor | ( | Rgb | , |
float | alpha = 1.f ) |
Sets the color of the currently active font and the alpha value.
alpha goes from 0.0f to 1.0f (opaque). It's automatically clamped to these values.
void setFontColor | ( | unsigned char | red, |
unsigned char | green, | ||
unsigned char | blue, | ||
unsigned char | alpha = 255 ) |
Sets the color of the currently active font.
If the alpha value isn't specified, it will be set to 255 (opaque).
bool keyDown | ( | const std::string & | key | ) |
Whether key
is down, where key
should be exactly one UTF-8 character.
Example:
bool isMouseVisible | ( | ) |
Returns whether the mouse cursor of the OS is currently visible.
Even when this method returns true, it could still be visible outside of the window or hidden by the OS for other means (e.g. while the user is typing).
bool isMultitouch | ( | ) |
Returns true when there's more than one finger touching the screen.
Equivalent to jngl::getTouchPositions().size() > 1
.
std::vector< jngl::Vec2 > getTouchPositions | ( | ) |
Returns all positions where a finger touches the screen.
Includes the mouse position if the primary mouse button is down.
Vec2 getMousePos | ( | ) |
Mouse position in screen coordinates.
If no mouse is connected will return the last touch position. See jngl::getCursorPos() if you really want the position of the mouse only.
Returns the position of the mouse pointer if a mouse is connected/available.
On Android, iOS and for the Nintendo Switch this will always return std::nullopt. While Android supports connecting mice this isn't supported by JNGL yet.
int getMouseX | ( | ) |
Retrieve mouse position in pixels.
int getMouseY | ( | ) |
Retrieve mouse position in pixels.
std::vector< std::shared_ptr< Controller > > getConnectedControllers | ( | ) |
Returns all controllers (gamepads) that are connected.
Don't call this function every frame for performance reasons, use jngl::onControllerChanged instead to get notified when controlles are being connected or removed.
void onControllerChanged | ( | std::function< void()> | callback | ) |
Specify a function which gets called, whenever a controller gets added or removed.
Whenever the return value of jngl::getConnectedControllers would change, callback gets called.
void addJob | ( | std::shared_ptr< Job > | job | ) |
Add a new Job which will be always be stepped and drawn by App::mainLoop()
Example:
void addJob | ( | Args &&... | args | ) |
The same as addJob(std::shared_ptr<Job>) but creates the Job for you.
Example:
void removeJob | ( | Job * | ) |
std::shared_ptr< T > getJob | ( | ) |
jngl::Mat3 modelview | ( | ) |
Returns a copy of the global ModelView matrix.
This is the matrix which is used in all of JNGL's shaders to position objects. Using this function you can get a local copy of it. This allows you to more precisely position an object without affecting any global state.
A common use-case where you actually want to modify the ModelView matrix for all objects is the camera. So in your drawing loop you would do:
void rotate | ( | double | degree | ) |
Multiplies the global ModelView matrix with a rotation matrix.
void translate | ( | Vect | v | ) |
Multiplies the global ModelView matrix with a translation matrix.
Equivalent to calling jngl::translate(v.x, v.y);
.
Definition at line 45 of file matrix.hpp.
void scale | ( | double | factor | ) |
Multiplies the global ModelView matrix by a scaling matrix.
Equivalent to calling jngl::scale(factor, factor)
.
void printMessage | ( | const std::string & | text | ) |
Prints text on stdout.
Normally this is the same as std::cout << text << std::flush;
. On Android this will use __android_log_print
for example.
void updateInput | ( | ) |
Updates the input state.
App::mainLoop() calls this before Work::step()
Normally you shouldn't call this yourself at all, unless you want to implement your own game loop.
void swapBuffers | ( | ) |
Swaps back and front buffer.
App::mainLoop() calls this after Work::draw()
Also clears the back buffer using jngl::clearBackBuffer().
void clearBackBuffer | ( | ) |
Clears the back buffer and resets the ModelView matrix, see jngl::reset()
jngl::swapBuffers() calls this so there isn't any reason to call this manually most of the time.
bool canQuit | ( | ) |
Some platforms (e.g.
iOS) don't allow apps to quit themselves
If this returns false you should hide any "Quit Game" menu buttons.
|
noexcept |
Emit a quit event which will exit App::mainLoop() and set running() to false.
If the window hasn't been created yet or the loop is already about to quit, this function does nothing
double getFPS | ( | ) |
Calculates FPS if called once per frame.
void setAntiAliasing | ( | bool | enabled | ) |
Toggles Multisample anti-aliasing (MSAA)
Many devices don't support this, so this function will do nothing.
void setConfigPath | ( | const std::string & | path | ) |
std::string getConfigPath | ( | ) |
Returns the directory where to store configuration files and save games.
%AppData%/Display Name/
~/.config/Display Name/
~/Library/Application Support/Display Name/
std::string readConfig | ( | const std::string & | key | ) |
Read in a configuration value which has been saved under key.
On most platforms this will read the contents of a file named key in getConfigPath(). On iOS or tvOS it will use the key/value store provided by the OS.
void writeConfig | ( | const std::string & | key, |
const std::string & | value ) |
Write value into the persistent storage which can be read in again using jngl::readConfig(key)
std::ifstream::failure | if the value couldn't be saved (e.g. jngl::getConfigPath() is read-only) |
std::runtime_error | if key is invalid (it must be a relative file path) |
void setScaleFactor | ( | double | ) |
Overwrite the size of one screen pixel.
Normally you wouldn't use this, but set AppParameters::screenSize to a lower value instead.
void setColor | ( | Rgb | ) |
Sets the color which should be used to draw primitives.
Doesn't change the alpha value currently set by setAlpha()
void setColor | ( | Rgb | , |
unsigned char | alpha ) |
Sets the color and alpha which should be used to draw primitives.
alpha | [0...255] |
void pushAlpha | ( | unsigned char | alpha | ) |
void popAlpha | ( | ) |
void setLineWidth | ( | float | width | ) |
void drawLine | ( | double | xstart, |
double | ystart, | ||
double | xend, | ||
double | yend ) |
void drawEllipse | ( | float | xmid, |
float | ymid, | ||
float | width, | ||
float | height, | ||
float | startAngle = 0 ) |
void drawPoint | ( | double | x, |
double | y ) |
void drawTriangle | ( | double | A_x, |
double | A_y, | ||
double | B_x, | ||
double | B_y, | ||
double | C_x, | ||
double | C_y ) |
void drawRect | ( | double | xposition, |
double | yposition, | ||
double | width, | ||
double | height ) |
Draws a rectangle at { xposition, yposition }.
Draws a rectangle at position.
Use setColor(Rgb) to change the color and setAlpha(uint8_t) to change the translucency.
Draws a rectangle spawning from (0, 0) to (size.x, size.y) with the specified color.
Use setAlpha to set the opacity.
Draws a rectangle spawning from (0, 0) to (size.x, size.y) with the specified color.
Use setAlpha to set the opacity.
void drawRect | ( | Vect | pos, |
Vect | size ) |
Definition at line 112 of file shapes.hpp.
void play | ( | const std::string & | filename | ) |
Play an OGG audio file once.
Might block if the file hasn't been played before. To avoid that use jngl::load before.
bool isPlaying | ( | const std::string & | filename | ) |
When playing a SoundFile multiple times (i.e. calling jngl::play multiple times), this will return true if at least one SoundFile is still playing (i.e. hasn't finished and wasn't stopped).
std::shared_ptr< SoundFile > loop | ( | const std::string & | filename | ) |
Play an OGG audio file in a loop.
If it's already playing, this function won't play it twice, but simply set it to loop and return a pointer to the same SoundFile.
Finally pauseAudio | ( | ) |
Pauses the playback of all audio; destroying the returned Finally object will resume again.
Note that this doesn't change the status of jngl::isPlaying as that only depends on the status of the SoundFile.
Example where you want to pause all audio in a menu:
Or if you want to toggle pausing audio using Space
:
void draw | ( | const std::string & | filename, |
Vect | pos ) |
Definition at line 255 of file sprite.hpp.
Finally load | ( | const std::string & | filename | ) |
Starts a thread to load filename and returns a Finally which will join it.
filename | Name of an image file (extension is optional) or a .ogg sound file. |
void sleep | ( | int | milliseconds | ) |
Sleep current thread for milliseconds.
void showWindow | ( | const std::string & | title, |
int | width, | ||
int | height, | ||
bool | fullscreen = false, | ||
std::pair< int, int > | minAspectRatio = { 4, 3 }, | ||
std::pair< int, int > | maxAspectRatio = { 16, 9 } ) |
Creates the main window.
If you haven't set a display name for your app using AppParameters::displayName, title will set for the display name.
void hideWindow | ( | ) |
Cleans up the window and unloads everything.
Will delete all instances of Singleton before starting to unload everything.
void atExit | ( | std::function< void()> | ) |
Call this function once when the window is hidden.
The function will be called at the next hideWindow() call, if there is a currently active window.
Use this function for any cleanup tasks when you game exits. Note that on Android, the process doesn't exit necessarely and the main function can be reentered - so C functions like atexit or destructors of global objects won't work.
void setWork | ( | Args &&... | args | ) |
The same as setWork(std::shared_ptr<Work>) but creates the Work for you.
void setWork | ( | Work * | ) |
void resetFrameLimiter | ( | ) |
Resets the automatic frame limiter of App::mainLoop().
This is useful after you have done a huge amount of work in Work::draw, e.g. after loading screens.