How to use the raylib.SetTargetFPS function in raylib

To help you get started, we’ve selected a few raylib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RobLoach / node-raylib / templates / simple_game / simple_game.js View on Github external
const r = require('raylib')

// Initialization (Note windowTitle is unused on Android)
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450

r.InitWindow(screenWidth, screenHeight, "raylib template - simple game")
var currentScreen = 'LOGO'

// TODO: Initialize all required variables and load all required data here!

var framesCounter = 0          // Useful to count frames

r.SetTargetFPS(60)               // Set desired framerate (frames-per-second)
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())    // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    switch(currentScreen)
    {
        case 'LOGO':
        {
            // TODO: Update LOGO screen variables here!

            framesCounter++    // Count frames

            // Wait for 2 seconds (120 frames) before jumping to TITLE screen
github RobLoach / node-raylib / examples / models / models_billboard.js View on Github external
r.InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards")

// Define the camera to look into our 3d world
const camera = r.Camera()
camera.position = r.Vector3(5.0, 4.0, 5.0)
camera.target = r.Vector3(0.0, 2.0, 0.0)
camera.up = r.Vector3(0.0, 1.0, 0.0)
camera.fovy = 45.0
camera.type = r.CAMERA_PERSPECTIVE

const bill = r.LoadTexture(__dirname + "/resources/billboard.png")     // Our texture billboard
const billPosition = r.Vector3(0.0, 2.0, 0.0)                 // Position where draw billboard

r.SetCameraMode(camera, r.CAMERA_ORBITAL)  // Set an orbital camera mode

r.SetTargetFPS(60)                       // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())            // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    //r.UpdateCamera(camera);              // Update camera
    //----------------------------------------------------------------------------------

    // Draw
    //----------------------------------------------------------------------------------
    r.BeginDrawing()

        r.ClearBackground(r.RAYWHITE)
github taniarascia / chip8 / example.js View on Github external
*   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
 *
 *   Copyright (c) 2014 Ramon Santamaria (@raysan5)
 *
 ********************************************************************************************/

const r = require('raylib')

// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450

r.InitWindow(screenWidth, screenHeight, 'raylib [shapes] example - basic shapes drawing')

r.SetTargetFPS(60)
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose()) {
  // Detect window close button or ESC key
  // Update
  //----------------------------------------------------------------------------------
  // TODO: Update your variables here
  //----------------------------------------------------------------------------------

  // Draw
  //----------------------------------------------------------------------------------
  r.BeginDrawing()

  r.ClearBackground(r.RAYWHITE)
github RobLoach / node-raylib / examples / core / core_random_values.js View on Github external
********************************************************************************************/

const r = require('raylib')

// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450

r.InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values")

var framesCounter = 0  // Variable used to count frames

var randValue = r.GetRandomValue(-8, 5)   // Get a random integer number between -8 and 5 (both included)

r.SetTargetFPS(60)       // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())    // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    framesCounter++

    // Every two seconds (120 frames) a new random value is generated
    if (((framesCounter/120)%2) == 1)
    {
        randValue = r.GetRandomValue(-8, 5)
        framesCounter = 0
    }
    //----------------------------------------------------------------------------------
github taniarascia / chip8 / scripts / native.js View on Github external
const { DISPLAY_HEIGHT, DISPLAY_WIDTH } = require('../data/constants')
const nativeKeyMap = require('../data/nativeKeyMap')

const multiplier = 10
const screenWidth = DISPLAY_WIDTH * multiplier
const screenHeight = DISPLAY_HEIGHT * multiplier

// Instantiation
const cpu = new CPU(cpuInterface)
const romBuffer = new RomBuffer(fileContents)
const cpuInterface = new NativeCpuInterface()

cpu.load(romBuffer)

r.InitWindow(screenWidth, screenHeight, 'Chip8.js')
r.SetTargetFPS(60)
r.ClearBackground(r.BLACK)

let timer = 0

while (!r.WindowShouldClose()) {
  timer++
  if (timer % 5 === 0) {
    cpu.tick()
    timer = 0
  }

  // Interpret key data
  const rawKeyPressed = r.GetKeyPressed()
  const keyIndex = nativeKeyMap.findIndex(key => rawKeyPressed === key)

  // Keydown event
github RobLoach / node-raylib / examples / core / core_world_screen.js View on Github external
// Define the camera to look into our 3d world
const camera = r.Camera(
  r.Vector3(10, 10, 10),
  r.Vector3(0, 0, 0),
  r.Vector3(0, 1, 0),
  45,
  r.CAMERA_PERSPECTIVE
)

const cubePosition = r.Vector3()
let cubeScreenPosition = r.Vector2()

r.SetCameraMode(camera, r.CAMERA_FREE); // Set a free camera mode

r.SetTargetFPS(60);                   // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())        // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    r.UpdateCamera(camera);          // Update camera

    // Calculate cube screen space position (with a little offset to be in top)
    const cubePositionVector = r.Vector3(cubePosition.x, cubePosition.y + 2.5, cubePosition.z)
    cubeScreenPosition = r.GetWorldToScreen(cubePositionVector, camera)
    //----------------------------------------------------------------------------------

    // Draw
    //----------------------------------------------------------------------------------
github RobLoach / node-raylib / examples / core / core_basic_window.js View on Github external
*   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
*   Copyright (c) 2018 Rob Loach (@RobLoach)
*
********************************************************************************************/

const r = require('raylib')

// Initialization
//--------------------------------------------------------------------------------------
var screenWidth = 800
var screenHeight = 450

r.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window")

r.SetTargetFPS(60)
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())    // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    // TODO: Update your variables here
    //----------------------------------------------------------------------------------

    // Draw
    //----------------------------------------------------------------------------------
    r.BeginDrawing()

        r.ClearBackground(r.RAYWHITE)
github RobLoach / node-raylib / examples / audio / audio_sound_loading.js View on Github external
const r = require('raylib')

// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450

r.InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing")

r.InitAudioDevice()      // Initialize audio device

const fxWav = r.LoadSound(__dirname + "/resources/sound.wav")         // Load WAV audio file
const fxOgg = r.LoadSound(__dirname + "/resources/tanatana.ogg")      // Load OGG audio file

r.SetTargetFPS(60)               // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())    // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    if (r.IsKeyPressed(r.KEY_SPACE)) r.PlaySound(fxWav)      // Play WAV sound
    if (r.IsKeyPressed(r.KEY_ENTER)) r.PlaySound(fxOgg)      // Play OGG sound
    //----------------------------------------------------------------------------------

    // Draw
    //----------------------------------------------------------------------------------
    r.BeginDrawing()

        r.ClearBackground(r.RAYWHITE)
github RobLoach / node-raylib / examples / core / core_2d_camera.js View on Github external
-6000 + spacing,
    screenHeight - 130 - height,
    r.GetRandomValue(50, 200),
    height
  )
  spacing += newBuilding.width;
  buildings.push(newBuilding)
  buildColors.push(r.Color(r.GetRandomValue(200, 240), r.GetRandomValue(200, 240), r.GetRandomValue(200, 250), 255))
}

const camera = r.Camera2D(
  r.Vector2(),
  r.Vector2(player.x + 20, player.y + 20),
  0, 1)

r.SetTargetFPS(60);                   // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())        // Detect window close button or ESC key
{
  // Update
  //----------------------------------------------------------------------------------
  if (r.IsKeyDown(r.KEY_RIGHT))
  {
      player.x += 2;              // Player movement
      camera.offset.x -= 2;       // Camera displacement with player movement
  }
  else if (r.IsKeyDown(r.KEY_LEFT))
  {
      player.x -= 2;              // Player movement
      camera.offset.x += 2;       // Camera displacement with player movement
github RobLoach / node-raylib / examples / core / core_input_mouse.js View on Github external
*
********************************************************************************************/

const r = require('raylib')

// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450

r.InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input")

var ballPosition = r.Vector2(-100, -100)
var ballColor = r.DARKBLUE

r.SetTargetFPS(60)
//---------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())    // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    ballPosition = r.GetMousePosition()

    if (r.IsMouseButtonPressed(r.MOUSE_LEFT_BUTTON)) {
        ballColor = r.MAROON
    }
    else if (r.IsMouseButtonPressed(r.MOUSE_MIDDLE_BUTTON)) {
        ballColor = r.LIME
    }
    else if (r.IsMouseButtonPressed(r.MOUSE_RIGHT_BUTTON)) {