Draw sprites, transform a camera and check collision
ASPL 0.7.0 · Current release
Native only. 20 frames show tinted, rotated and flipped atlas sprites with a red rectangle intersection. The final frame unloads an alias before presentation and checks that the original is invalid. Success prints texture sprites complete without a trailing newline and returns 0.
On this page
Prepare the native host
Native only, published ASPL 0.7.0. 20 frames show tinted, rotated and flipped atlas sprites with a red rectangle intersection. The final frame unloads an alias before presentation and checks that the original is invalid. Success prints texture sprites complete without a trailing newline and returns 0.
Native installation · Drawing and input guide · API reference.
Download the PNG and its Apache-2.0 OR MIT notice. Preserve docs/examples/assets/raylib-sprites.png relative to the process working directory, including when moving a generated program. The atlas is 32 by 16 RGBA pixels.
The page language is independent of source vocabulary. Download only supplied variants, with original filenames. Mixed-only programs are labelled in both locales; no source translation is generated.
Arabic source
Execution: Native only · ASPL 0.7.0
- Native ASPL 0.7.0 on x86_64 Linux with glibc 2.34 or later.
- Running needs a reachable Wayland/EGL or X11/GLX display and OpenGL 3.3 core; no system Raylib or C compiler is required. Checking and building need no display.
Input: No input lines are required.
Download and prepare the required files before running:
استورد أساسي::رايليب.
دالة ابدأ_الرئيسية() -> ص64 {
دع مفتوح = رايليب::هيئ_نافذة(480, 300, "PNG sprites / صور متحركة").
إذا لا مفتوح::نجاح { اطبع(مفتوح::الخطأ::الرسالة). أرجع 1. }
دع محمل = رايليب::حمل_نسيجا("docs/examples/assets/raylib-sprites.png").
إذا لا محمل::نجاح { اطبع(محمل::الخطأ::الرسالة). أرجع 2. }
دع نسيج = محمل::قيمة.
دع مرادف = نسيج.
إذا رايليب::عرض_النسيج(نسيج)::قيمة لا يطابق 32 أو رايليب::ارتفاع_النسيج(نسيج)::قيمة لا يطابق 16 { أرجع 3. }
دع مرشح = رايليب::اضبط_مرشح_النسيج(نسيج, رايليب::مرشح_نسيج_نقطي).
دع التفاف = رايليب::اضبط_التفاف_النسيج(نسيج, رايليب::التفاف_نسيج_تثبيت).
دع معدل_الإطارات = رايليب::اضبط_معدل_الإطارات(60).
إذا لا مرشح::نجاح أو لا التفاف::نجاح أو لا معدل_الإطارات::نجاح { أرجع 4. }
دع كاميرا = رايليب::كاميرا2 {
إزاحة: رايليب::متجه2 { س: 15.0, ص: 10.0 }, هدف: رايليب::متجه2 { س: 0.0, ص: 0.0 },
دوران: 0.0, تكبير: 1.0
}.
دع أول = رايليب::مستطيل { س: 24.0, ص: 24.0, عرض: 32.0, ارتفاع: 16.0 }.
دع ثان = رايليب::مستطيل { س: 30.0, ص: 28.0, عرض: 32.0, ارتفاع: 16.0 }.
دع تصادم = رايليب::هل_يتداخل_مستطيلان(أول, ثان).
دع تداخل = رايليب::مستطيل_التداخل(أول, ثان).
إذا لا تصادم::نجاح أو لا تداخل::نجاح { أرجع 16. }
إذا لا تصادم::قيمة { أرجع 17. }
متغير إطار: ص32 = 0.
طالما إطار < 20 {
إذا لا رايليب::ابدأ_الرسم()::نجاح أو لا رايليب::امسح_الخلفية(رايليب::أبيض_رايليب)::نجاح { أرجع 5. }
إذا لا رايليب::ابدأ_وضع_ثنائي_الأبعاد(كاميرا)::نجاح { أرجع 6. }
إذا لا رايليب::ارسم_نسيجا(نسيج, 24, 24, رايليب::أبيض)::نجاح { أرجع 7. }
إذا لا رايليب::ارسم_نسيجا_بمتجه(نسيج, رايليب::متجه2 { س: 100.0, ص: 24.0 }, رايليب::أزرق_سماوي)::نجاح { أرجع 8. }
إذا لا رايليب::ارسم_نسيجا_موسعا(نسيج, رايليب::متجه2 { س: 40.0, ص: 110.0 }, -10.0, 4.0, رايليب::أبيض)::نجاح { أرجع 9. }
إذا لا رايليب::ارسم_جزء_نسيج(نسيج, رايليب::مستطيل { س: 16.0, ص: 0.0, عرض: -16.0, ارتفاع: 16.0 },
رايليب::متجه2 { س: 250.0, ص: 24.0 }, رايليب::أبيض)::نجاح { أرجع 10. }
إذا لا رايليب::ارسم_نسيجا_متقدما(نسيج, رايليب::مستطيل { س: 16.0, ص: 0.0, عرض: 16.0, ارتفاع: -16.0 },
رايليب::مستطيل { س: 330.0, ص: 160.0, عرض: -96.0, ارتفاع: 96.0 },
رايليب::متجه2 { س: 48.0, ص: 48.0 }, 25.0, رايليب::لون { أحمر: 255, أخضر: 255, أزرق: 255, ألفا: 210 })::نجاح { أرجع 11. }
إذا لا رايليب::ارسم_محيط_مستطيل_موسعا(تداخل::قيمة, 1.0, رايليب::أحمر)::نجاح { أرجع 18. }
إذا لا رايليب::أنه_وضع_ثنائي_الأبعاد()::نجاح { أرجع 12. }
إذا إطار يطابق 19 {
إذا لا رايليب::حرر_النسيج(مرادف)::نجاح أو رايليب::هل_النسيج_صالح(نسيج) { أرجع 13. }
}
إذا لا رايليب::أنه_الرسم()::نجاح { أرجع 14. }
إطار = إطار + 1.
}
إذا لا رايليب::حرر_النسيج(نسيج)::نجاح أو لا رايليب::أغلق_النافذة()::نجاح { أرجع 15. }
اطبع("texture sprites complete").
أرجع 0.
}
Follow the Linux instructions to run this example. Download the source to keep a copy.
Download صور-وكاميرا.لباتExpected outcomes
{
"native": {
"check": 0,
"status": 0,
"output": "texture sprites complete",
"behavior": {
"en": "20 frames show tinted, rotated and flipped atlas sprites with a red rectangle intersection. The final frame unloads an alias before presentation and checks that the original is invalid. Success prints texture sprites complete without a trailing newline and returns 0.",
"ar": "تعرض 20 إطارا صور الأطلس الملونة والمدورة والمنعكسة مع تقاطع مستطيل أحمر. يحرر الإطار الأخير نسخة المالك قبل العرض ويتحقق من بطلان الأصل. يطبع النجاح texture sprites complete دون سطر جديد ويعيد 0."
}
}
}English source
Execution: Native only · ASPL 0.7.0
- Native ASPL 0.7.0 on x86_64 Linux with glibc 2.34 or later.
- Running needs a reachable Wayland/EGL or X11/GLX display and OpenGL 3.3 core; no system Raylib or C compiler is required. Checking and building need no display.
Input: No input lines are required.
Download and prepare the required files before running:
import core::raylib;
fn start_main() -> i64 {
let opened = raylib::InitWindow(480, 300, "PNG sprites / صور متحركة");
if not opened::ok { print(opened::error::message); return 1; }
let loaded = raylib::LoadTexture("docs/examples/assets/raylib-sprites.png");
if not loaded::ok { print(loaded::error::message); return 2; }
let texture = loaded::value;
let alias = texture;
if raylib::GetTextureWidth(texture)::value not matches 32 or raylib::GetTextureHeight(texture)::value not matches 16 { return 3; }
let filter = raylib::SetTextureFilter(texture, raylib::TEXTURE_FILTER_POINT);
let wrap = raylib::SetTextureWrap(texture, raylib::TEXTURE_WRAP_CLAMP);
let pacing = raylib::SetTargetFPS(60);
if not filter::ok or not wrap::ok or not pacing::ok { return 4; }
let camera = raylib::Camera2D {
offset: raylib::Vector2 { x: 15.0, y: 10.0 }, target: raylib::Vector2 { x: 0.0, y: 0.0 },
rotation: 0.0, zoom: 1.0
};
let first = raylib::Rectangle { x: 24.0, y: 24.0, width: 32.0, height: 16.0 };
let second = raylib::Rectangle { x: 30.0, y: 28.0, width: 32.0, height: 16.0 };
let collision = raylib::CheckCollisionRecs(first, second);
let overlap = raylib::GetCollisionRec(first, second);
if not collision::ok or not overlap::ok { return 16; }
if not collision::value { return 17; }
var frame: i32 = 0;
while frame < 20 {
if not raylib::BeginDrawing()::ok or not raylib::ClearBackground(raylib::RAYWHITE)::ok { return 5; }
if not raylib::BeginMode2D(camera)::ok { return 6; }
if not raylib::DrawTexture(texture, 24, 24, raylib::WHITE)::ok { return 7; }
if not raylib::DrawTextureV(texture, raylib::Vector2 { x: 100.0, y: 24.0 }, raylib::SKYBLUE)::ok { return 8; }
if not raylib::DrawTextureEx(texture, raylib::Vector2 { x: 40.0, y: 110.0 }, -10.0, 4.0, raylib::WHITE)::ok { return 9; }
if not raylib::DrawTextureRec(texture, raylib::Rectangle { x: 16.0, y: 0.0, width: -16.0, height: 16.0 },
raylib::Vector2 { x: 250.0, y: 24.0 }, raylib::WHITE)::ok { return 10; }
if not raylib::DrawTexturePro(texture, raylib::Rectangle { x: 16.0, y: 0.0, width: 16.0, height: -16.0 },
raylib::Rectangle { x: 330.0, y: 160.0, width: -96.0, height: 96.0 },
raylib::Vector2 { x: 48.0, y: 48.0 }, 25.0, raylib::Color { r: 255, g: 255, b: 255, a: 210 })::ok { return 11; }
if not raylib::DrawRectangleLinesEx(overlap::value, 1.0, raylib::RED)::ok { return 18; }
if not raylib::EndMode2D()::ok { return 12; }
if frame matches 19 {
if not raylib::UnloadTexture(alias)::ok or raylib::IsTextureValid(texture) { return 13; }
}
if not raylib::EndDrawing()::ok { return 14; }
frame = frame + 1;
}
if not raylib::UnloadTexture(texture)::ok or not raylib::CloseWindow()::ok { return 15; }
print("texture sprites complete");
return 0;
}
Follow the Linux instructions to run this example. Download the source to keep a copy.
Download sprite-camera.asplExpected outcomes
{
"native": {
"check": 0,
"status": 0,
"output": "texture sprites complete",
"behavior": {
"en": "20 frames show tinted, rotated and flipped atlas sprites with a red rectangle intersection. The final frame unloads an alias before presentation and checks that the original is invalid. Success prints texture sprites complete without a trailing newline and returns 0.",
"ar": "تعرض 20 إطارا صور الأطلس الملونة والمدورة والمنعكسة مع تقاطع مستطيل أحمر. يحرر الإطار الأخير نسخة المالك قبل العرض ويتحقق من بطلان الأصل. يطبع النجاح texture sprites complete دون سطر جديد ويعيد 0."
}
}
}Mixed source
Execution: Native only · ASPL 0.7.0
- Native ASPL 0.7.0 on x86_64 Linux with glibc 2.34 or later.
- Running needs a reachable Wayland/EGL or X11/GLX display and OpenGL 3.3 core; no system Raylib or C compiler is required. Checking and building need no display.
Input: No input lines are required.
Download and prepare the required files before running:
import core::raylib;
استورد أساسي::رايليب.
fn start_main() -> i64 {
let opened = raylib::InitWindow(480, 300, "PNG sprites / صور متحركة");
if not opened::ok { print(opened::error::message); return 1; }
let loaded = رايليب::حمل_نسيجا("docs/examples/assets/raylib-sprites.png");
if not loaded::ok { print(loaded::error::message); return 2; }
let texture = loaded::value;
let alias = texture;
if raylib::GetTextureWidth(texture)::value not matches 32 or رايليب::ارتفاع_النسيج(texture)::value not matches 16 { return 3; }
let filter = raylib::SetTextureFilter(texture, raylib::TEXTURE_FILTER_POINT);
let wrap = raylib::SetTextureWrap(texture, raylib::TEXTURE_WRAP_CLAMP);
let pacing = raylib::SetTargetFPS(60);
if not filter::ok or not wrap::ok or not pacing::ok { return 4; }
let camera = raylib::Camera2D {
offset: raylib::Vector2 { x: 15.0, y: 10.0 }, target: raylib::Vector2 { x: 0.0, y: 0.0 },
rotation: 0.0, zoom: 1.0
};
let first = raylib::Rectangle { x: 24.0, y: 24.0, width: 32.0, height: 16.0 };
let second = raylib::Rectangle { x: 30.0, y: 28.0, width: 32.0, height: 16.0 };
let collision = raylib::CheckCollisionRecs(first, second);
let overlap = رايليب::مستطيل_التداخل(first, second);
if not collision::ok or not overlap::ok { return 16; }
if not collision::value { return 17; }
var frame: i32 = 0;
while frame < 20 {
if not raylib::BeginDrawing()::ok or not raylib::ClearBackground(raylib::RAYWHITE)::ok { return 5; }
if not raylib::BeginMode2D(camera)::ok { return 6; }
if not raylib::DrawTexture(texture, 24, 24, raylib::WHITE)::ok { return 7; }
if not raylib::DrawTextureV(texture, raylib::Vector2 { x: 100.0, y: 24.0 }, raylib::SKYBLUE)::ok { return 8; }
if not raylib::DrawTextureEx(texture, raylib::Vector2 { x: 40.0, y: 110.0 }, -10.0, 4.0, raylib::WHITE)::ok { return 9; }
if not raylib::DrawTextureRec(texture, raylib::Rectangle { x: 16.0, y: 0.0, width: -16.0, height: 16.0 },
raylib::Vector2 { x: 250.0, y: 24.0 }, raylib::WHITE)::ok { return 10; }
if not raylib::DrawTexturePro(texture, raylib::Rectangle { x: 16.0, y: 0.0, width: 16.0, height: -16.0 },
raylib::Rectangle { x: 330.0, y: 160.0, width: -96.0, height: 96.0 },
raylib::Vector2 { x: 48.0, y: 48.0 }, 25.0, raylib::Color { r: 255, g: 255, b: 255, a: 210 })::ok { return 11; }
if not raylib::DrawRectangleLinesEx(overlap::value, 1.0, raylib::RED)::ok { return 18; }
if not raylib::EndMode2D()::ok { return 12; }
if frame matches 19 {
if not raylib::UnloadTexture(alias)::ok or raylib::IsTextureValid(texture) { return 13; }
}
if not raylib::EndDrawing()::ok { return 14; }
frame = frame + 1;
}
if not raylib::UnloadTexture(texture)::ok or not raylib::CloseWindow()::ok { return 15; }
print("texture sprites complete");
return 0;
}
Follow the Linux instructions to run this example. Download the source to keep a copy.
Download sprite-camera.mixed.asplExpected outcomes
{
"native": {
"check": 0,
"status": 0,
"output": "texture sprites complete",
"behavior": {
"en": "20 frames show tinted, rotated and flipped atlas sprites with a red rectangle intersection. The final frame unloads an alias before presentation and checks that the original is invalid. Success prints texture sprites complete without a trailing newline and returns 0.",
"ar": "تعرض 20 إطارا صور الأطلس الملونة والمدورة والمنعكسة مع تقاطع مستطيل أحمر. يحرر الإطار الأخير نسخة المالك قبل العرض ويتحقق من بطلان الأصل. يطبع النجاح texture sprites complete دون سطر جديد ويعيد 0."
}
}
}Commands and outcomes
Run from the directory containing the downloaded docs/ tree. Keep the generated .THIRD-PARTY-NOTICES companion when distributing the ELF program. Checking and building do not open a window. Running needs the stated graphics facilities.
ar:
aspl check docs/examples/raylib/صور-وكاميرا.لبات
aspl run docs/examples/raylib/صور-وكاميرا.لبات
aspl build -o raylib-sprite-camera-ar-program docs/examples/raylib/صور-وكاميرا.لبات
./raylib-sprite-camera-ar-programen:
aspl check docs/examples/raylib/sprite-camera.aspl
aspl run docs/examples/raylib/sprite-camera.aspl
aspl build -o raylib-sprite-camera-en-program docs/examples/raylib/sprite-camera.aspl
./raylib-sprite-camera-en-programmixed:
aspl check docs/examples/raylib/sprite-camera.mixed.aspl
aspl run docs/examples/raylib/sprite-camera.mixed.aspl
aspl build -o raylib-sprite-camera-mixed-program docs/examples/raylib/sprite-camera.mixed.aspl
./raylib-sprite-camera-mixed-program