Watch
2
0
Fork
You've already forked raylib-cs
0

feat: backporting existing raylib-cs examples and new official raylib examples to WASM, adopting raylib's original code style

This commit is contained in:
tiger tiger tiger 2026-07-17 08:22:54 +02:00
commit 732b7aa346
234 changed files with 38999 additions and 10578 deletions

View file

@ -1,11 +1,15 @@
/*******************************************************************************************
*
* raylib [text] example - Text Writing Animation
* raylib [text] example - writing anim
*
* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example complexity rating: [] 2/4
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
* Example originally created with raylib 1.4, last time updated with raylib 1.4
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2016-2025 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@ -13,60 +17,85 @@ using static Raylib_cs.Raylib;
namespace Examples.Text;
public class WritingAnim
public partial class WritingAnim : IExample
{
private const int screenWidth = 800;
private const int screenHeight = 450;
public string Name => "Text / Writing Animation";
public string Title => "raylib [text] example - writing anim";
private string message;
private int framesCounter;
public void Init()
{
message = "This sample illustrates a text writing\nanimation effect! Check it out! ;)";
framesCounter = 0;
}
public void Update()
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyDown(KeyboardKey.Space))
{
framesCounter += 8;
}
else
{
framesCounter += 1;
}
if (IsKeyPressed(KeyboardKey.Enter))
{
framesCounter = 0;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(Color.RayWhite);
DrawText(message.SubText(0, framesCounter / 10), 210, 160, 20, Color.Maroon);
DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, Color.LightGray);
DrawText("HOLD [SPACE] to SPEED UP!", 239, 300, 20, Color.LightGray);
EndDrawing();
//----------------------------------------------------------------------------------
}
public void Unload()
{
}
public static int Main()
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - writing anim");
InitWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim");
string message = "This sample illustrates a text writing\nanimation effect! Check it out! ;)";
int framesCounter = 0;
SetTargetFPS(60);
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
var game = new WritingAnim();
game.Init();
// Main game loop
while (!WindowShouldClose())
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyDown(KeyboardKey.Space))
{
framesCounter += 8;
}
else
{
framesCounter += 1;
}
if (IsKeyPressed(KeyboardKey.Enter))
{
framesCounter = 0;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(Color.RayWhite);
DrawText(message.SubText(0, framesCounter / 10), 210, 160, 20, Color.Maroon);
DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, Color.LightGray);
DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, Color.LightGray);
EndDrawing();
//----------------------------------------------------------------------------------
game.Update();
}
game.Unload();
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow();
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;