GPE Engine Functions

1.Summary

The GPE is filled with many useful functions to make your game work quick and nicely.

Take a moment to discover all of the functions the “gpe object” contains.

2.Audio Functions

gpe.check_audio_playing( audioId)

-Returns true or false if the audio is playing

 

gpe.loop_audio( audioId)

-Plays the audio in a continuous loop[Useful for background music]

 

gpe.play_audio( audioId)

-Plays the audio once.

 

gpe.pause_audio( audioId)

-Pauses the Audio

 

gpe_stop_all_audio()

-Pauses all audio playing

 

gpe.stop_audio( audioId)

-Stops the Audio

 

gpe_stop_all_audio()

-Stops all audio from playing

3.Camera Functons

 

The Game Pencil Engine was created around these functions not being called within the rendering functions of your game. Unexpected results may occur if these are called during the render-state of GPE.

 

gpe.camera_on(cameraId)

-Returns true or false if the camera is in use. If the camera is out of bounds returns IS_NULL;

 

 

gpe.center_camera( cameraId, centerX, centerY)

-Centers the indexed camera[From 0 to 7] around the coordinates(centerX, centerY). In the event the position is off the screen the Game Pencil Engine automatically attempts to readjust it to stay within the scene boundaries.

 

gpe.disable_camera ( cameraId)

-Disables the indexed camera[ From 0 to 7].

 

gpe.enable_camera ( cameraId)

-Enables the index camera[ From 0 to 7].

 

gpe.move_camera(cameraId, newX, newY)

–Places the indexed camera[From 0 to 7] at the coordinates(newX, newY). In the event the position is off the screen the Game Pencil Engine automatically attempts to readjust it to stay within the scene boundaries.

 

gpe.setup_camera(cameraId, cameraX,cameraY, cameraW, cameraH);
-This function is used to place the location box of the camera(if enabled) on the screen.
-cameraId( From 0 to 7).

 

 For more details on the camera system seehere.

4.Input Functions

Keyboard Functions

 

gpe.check_keyboard_down = function(keyId)

-Returns true or false if the key is being pressed now.

gpe.check_keyboard_pressed = function(keyId)
-Returns true or false if the key was just pressed in frame.

gpe.check_keyboard_released(keyId)
-Returns true or false if the key was just released in frame.

 

You can find the complete list of keyboard constants here.

 

Mouse Functions

 

gpe.check_mouse_button_down = function(buttonId)

-Returns true or false if the mouse button is being pressed now.

gpe.check_mouse_button_pressed = function(buttonId)
-Returns true or false if the mouse buttonwas just pressed in frame.

gpe.check_mouse_button_released(buttonId)
-Returns true or false if the mouse button was just released in frame.

gpe.get_mouse_x()

-Returns the x-coordinate of the mouse within the game screen.

gpe.get_mouse_y()

-Returns the x-coordinate of the mouse within the game screen.

 

Mouse buttons are indexed from 0 to 2.

 

 For more details on game input see here.

 

5.Math functions

gpe.abs(x)

-Returns a positive or zero value of x.

 

gpe.bound_number( numbIn,  xMin, xMax)

-Limits the number to be greater than or equal to XMin and less than or equal to xMax.

 

gpe.get_direction( x1, y1, x2, y2)

-Returns the direction of (x1,y1) facing (x2,y2).

 

gpe.get_distance( x1,  y1,  x2,  y2)

-Returns the distance between (x1,y1) and (x2,y2).

 

gpe.get_random(min,max)

-Returns a random number between min and max.

 

gpe.sign( x)

-Returns  -1, 0, or 1 if inputted with a number otherwise returns NaN.

 

gpe.to_bool(strToProcess)

-Returns true or false if the input can be considered a boolean(English standard)

 

6.Rendering Functions

 

gpe.render_circle( x, y, radius, circleColor, isOutline,oulineWidth, renderImmediately)
-Renders a circle with (x,y,r)  and renders immediately or is placed in the shape rendering queue in the frame.
gpe.render_line( x1, y1, x2, y2, lineColor, lineWidth, renderImmediately)
-Renders a line from (x1,y1) to (x2,y2)  with lineColor and lineWidth and renders immediately or is placed in the shape rendering queue in the frame.

 

gpe.render_rectangle(x1, y1, x2, y2,rectColor, outline,rectLineWidth ,renderImmediately)

-Renders a rectangle with rectColor, outline(boolean) with rectLineWidth(pixel outline size)  and renders immediately or is placed in the shape rendering queue in the frame.

 

gpe.render_sprite(spriteId, frameNumb, xOn, yOn, scaleX, scaleY)

-Renders a sprite with the id of spriteId with frameNumb animation id with scaleX/ScaleY(optional) scaling.

 

gpe.render_sprite_rotated(spriteId, frameNumb, xOn, yOn, rotationAngle, scaleX, scaleY)

-Renders a sprite with the id of spriteId with frameNumb animation id rotated by rotationAngle[Degrees] with scaleX/ScaleY(optional) scaling.

 

 

gpe.render_square(x, y, squareSize,squareColor, outline,squareLineWidth ,renderImmediately)

-Renders a square of squareSize pixels with squareColor, outline(boolean) with squareLineWidth(pixel outline size)  and renders immediately or is placed in the shape rendering queue in the frame.

 

gpe.render_text(fontId x, y, text, fontColor, fontHalign, fontValign)

-Renders text using fontId at (x,y) with fontColor.

FontHalign takes in fa_left, fa_center and fa_right;

FontValign takes in fa_top, fa_middle and fa_bottom;

 

gpe.render_texture(texureId,  xDraw, yDraw)

-Renders the textureId at (xDraw,yDraw).

 

gpe.render_texture_scaled( texureId, xDraw, yDraw, width, height )

-Renders the textureId at (xDraw,yDraw) scaled to (width,height) in pixels

 

this.render_texture_clipped( texureIdIn,xDraw, yDraw, clipBox )

-Renders the textureId at (xDraw,yDraw) scaled to (width,height) in pixels with only the clipBox(GPE_Rect) part visible

 

gpe.render_triangle (x1, y1, x2, y2, x3, y3, triangleColor, outline, outlineSize, renderImmediately)

-Renders the triangle using the three points with outlineSize(optional if outline=true) and renders immediately or is placed in the shape rendering queue in the frame.

 

gpe.set_render_alpha( alphaValue)

-Sets the global alpha for all rendering functions within the current render phase.

The value is either between 0(fully transparent) and 255(fully visible).

 

7.Operational Functions

gpe.get_fps()

-Returns the recent frame rate( capped at 60 FPS from browser).

 

8.Saving and Loading Data

gpe.erase_data( dataIdentifier, dataTitle);
-Sends in the data related to the dataIdentifier( number or string) by dataTitle(string) to the GPE’s shadowrealm.

gpe.load_data( dataIdentifier, dataTitle);
-Loads in the data related to the dataIdentifier( number or string) by dataTitle(string).

gpe.save_data( dataIdentifier, dataTitle, actualData);
-Saves the actualData(Any data type) related to the dataIdentifier( number or string)’s dataTitle(string) block.

 For more details on saving and loading see here.

9.Statistical Functions

Documentation coming soon

10.Video Functions

When using these video functions, be aware that the video does not begin to play, pause or stop until the completion of the current game loop.

 

gpe.check_video_playing( videoId)

-Returns true or false if the video is playing

 

gpe.loop_video( videoId)

-Plays the video in a continuous loop[Useful for opening cutscenes] and is skippable.

 

gpe.play_video( videoId, loops, isSkippable)

-Plays the video or (loops) is. Set isSkippable to true if you will like for the user to press a key to stop viewing the video.

 

gpe.pause_video( videoId)

-Pauses the video

 

gpe_stop_all_video()

-Pauses all video playing

 

gpe.stop_video( videoId)

-Stops the video

 

gpe_stop_all_video()

-Stops all video from playing

Suggest Edit