Skip to content

Add Update Animation Usage Example#751

Open
ralphweng2023 wants to merge 2 commits into
thoth-tech:mainfrom
ralphweng2023:update-animation-usage-example
Open

Add Update Animation Usage Example#751
ralphweng2023 wants to merge 2 commits into
thoth-tech:mainfrom
ralphweng2023:update-animation-usage-example

Conversation

@ralphweng2023
Copy link
Copy Markdown

Overview

This usage example demonstrates update_animation by showing how an animation progresses through its frames inside a game loop, cycling through different colors.

SplashKit Function: update_animation

Files Included

  • Title and explanation (.txt)
  • C++ code (SplashKit)
  • C# code (Top-Level statements)
  • C# code (Object-Oriented Programming)
  • Python code
  • Screenshot (.png)
  • Resources (.zip — animation script file)

What the Example Does

  1. Creates a 4-frame sprite sheet programmatically (red, green, blue, yellow squares)
  2. Sets cell details on the bitmap (64x64 per cell, 4 columns, 1 row)
  3. Loads an animation script that defines a looping color cycle
  4. Creates an animation from the script
  5. In the game loop:
    • Draws the bitmap using option_with_animation to select the correct frame
    • Calls update_animation to advance to the next frame
  6. Releases animation and script resources on exit

Design Decisions

  • Programmatic sprite sheet: The bitmap is built at runtime using create_bitmap and fill_rectangle_on_bitmap, avoiding the need for an external image file. This keeps the resource bundle minimal (only the animation script).
  • Minimal code: Focused on demonstrating update_animation with the fewest lines possible while remaining clear and beginner-friendly.

Usage Example Checks

  • Simple, clear demonstration of the function
  • Code uses SplashKit functions
  • npm run build passes (no new link validation errors)
  • Cross-references auto-generated via usage-example-scraping
  • Consistent comments across all language versions

- C++, C# (top-level + OOP), and Python implementations
- Demonstrates color cycling animation using update_animation()
- Sprite sheet created programmatically (no external bitmap needed)
- Includes animation script resource file (color_cycle.txt)
- Screenshot of window output
@netlify
Copy link
Copy Markdown

netlify Bot commented May 3, 2026

Deploy Preview for splashkit failed.

Name Link
🔨 Latest commit aeda4cb
🔍 Latest deploy log https://app.netlify.com/projects/splashkit/deploys/6a05690e74e1d60008568cfc

Copy link
Copy Markdown

@222448082Ashen 222448082Ashen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peer Review

I've reviewed the update_animation usage example (PR #751).

Checks

  • All required files are present.
    • Example Title (.txt): update_animation-1-example.txt
    • C++ code: update_animation-1-example.cpp
    • C# code (top-level statements): update_animation-1-example-top-level.cs
    • C# code (Object-Oriented Programming): update_animation-1-example-oop.cs
    • Python code: update_animation-1-example.py
    • Screenshot: update_animation-1-example.png (shows 4-color cycling animation)
    • Resources: update_animation-1-example-resources.zip (contains animation script)
  • Code correctly uses SplashKit functions.
  • Code clearly demonstrates the function.
  • All versions maintain the same structure and comments.

Code Tests Done

  • C++ code ran correctly creates sprite sheet programmatically, loads animation script, cycles through colors using update_animation().
  • C# top-level code ran correctly mirrors C++ logic with correct SplashKit API naming.
  • C# OOP code ran correctly object-oriented approach with proper method chaining (e.g., sheet.FillRectangle(), anim.Update()).
  • Python code ran correctly follows SplashKit Python conventions (e.g., clear_screen_to_white(), refresh_screen_with_target_fps()).

Website Tests Done

  • npm run build Passed successfully; all setup scripts completed without errors.
  • npm run preview Usage example displays correctly under Animations category; JSON metadata correctly links to /api/animations/#update-animation; resource file accessible.

Copy link
Copy Markdown

@Osaid2993 Osaid2993 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overview and example itself look clear to me and the explanation matches the function well.

My only remaining concern is that the PR should stay limited to this example only. Please remove the unrelated changes from scripts/json-files/usage-example-references.json, then I’m happy to review again.

Scope this PR to update_animation only. Drop unrelated additions for
saturation_of, rectangle_around, bitmap_center, draw_circle,
get_font_style, close_window from usage-example-references.json.
@ralphweng2023
Copy link
Copy Markdown
Author

@Osaid2993 thanks for the review! I've removed the unrelated entries from scripts/json-files/usage-example-references.json in aeda4cb. The PR diff now contains only the animations.update_animation entry. Could you take another look when you have a moment? 🙏

Copy link
Copy Markdown

@rachelpatrao rachelpatrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage example is well-structured and clearly demonstrates how update_animation works within a game loop. The implementation is beginner-friendly, keeps the code minimal and focused, and the inclusion of consistent cross-language versions, resources, and documentation makes the example easy to follow. Approved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants