Sign in

    selene-canvas

    Default backend for Selene game engine.

    Game Engine
    Download zip
    Author
    Version
    0.19.1
    License
    Apache-2.0
    Last updated
    10 months ago
    Downloads
    102

    #A Selene Backend with Canvas2D/JavaScript

    #Installation

    Import this backend with

    moon add Milky2018/selene-canvas

    Choose this implementation wherever the Milky2018/selene/backend is used. Add this in your moon.pkg.json:

    { "overrides": [ "Milky2018/selene-canvas" ] }

    #Instruction

    Copy the provided index.html to the root path of your project.

    Replace the source file path with your actual file path.

    Build your project with

    moon build --target js

    Run the server with any Web Server such as

    python3 -m http.server 8000

    Finally, you can play your game by accessing localhost:8000 in your browser.

    Audio

    type Audio

    Audio::new

    fn Audio::new(path : String) -> Audio

    Audio::pause

    fn Audio::pause(self : Audio) -> Unit

    Audio::play

    fn Audio::play(self : Audio) -> Unit

    Audio::set_loop

    fn Audio::set_loop(self : Audio, loop_ : Bool) -> Unit

    Audio::set_volume

    fn Audio::set_volume(self : Audio, volume : Double) -> Unit

    CanvasBackend

    type CanvasBackend

    CanvasBackend::new

    draw_color_circle

    fn draw_color_circle(x~ : Double, y~ : Double, radius~ : Double, color~ : String, stroke_color~ : String) -> Unit

    draw_color_rect

    fn draw_color_rect(x~ : Double, y~ : Double, width~ : Double, height~ : Double, color~ : String, stroke_color~ : String) -> Unit

    draw_gradient_rect

    fn draw_gradient_rect(x~ : Double, y~ : Double, width~ : Double, height~ : Double, color_start~ : String, color_end~ : String) -> Unit

    draw_picture

    fn draw_picture(png~ : String, x~ : Double, y~ : Double, width~ : Double, height~ : Double, transform~ :
    Transform
    , repeat~ :
    RepeatMode
    ) -> Unit

    draw_sprite

    fn draw_sprite(sprite_path~ : String, x~ : Double, y~ : Double, offset_x~ : Double, offset_y~ : Double, width~ : Double, height~ : Double, transform~ :
    Transform
    ) -> Unit

    draw_text

    fn draw_text(text~ : String, x~ : Double, y~ : Double, font~ : String, color~ : String, align~ :
    HAlign
    , baseline~ :
    VAlign
    ) -> Unit

    get_canvas_size

    fn get_canvas_size() ->
    Vec2D

    get_realtime_delta

    fn get_realtime_delta() -> Double

    get_time_scale

    fn get_time_scale() -> Double

    get_zoom

    fn get_zoom() -> Double

    initialize

    fn initialize(startup~ : () -> Unit, render_loop~ : (Double) -> Unit, game_loop~ : (Double) -> Unit, canvas_width~ : Double, canvas_height~ : Double, fps~ : UInt, image_smooth~ : Bool, zoom~ : Double) -> (() -> Unit)

    load_font

    fn load_font(font : String, path : String) -> Unit

    lock_mouse

    fn lock_mouse(locked : Ref[Bool]) -> Unit

    play_audio

    fn play_audio(audio_path~ : String, volume~ : Double, loop_~ : Bool) -> Unit

    preload_audio

    fn preload_audio(audio_path : String) -> Unit

    preload_img

    fn preload_img(path : String) -> Unit

    register_key_events

    fn register_key_events(pressed_keys :
    Set
    [
    Code
    ]) -> Unit

    register_mouse_events

    fn register_mouse_events(mouse :
    Mouse
    , mouse_movement :
    MouseMovement
    ) -> Unit

    set_time_scale

    fn set_time_scale(time_scale : Double) -> Unit

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io