scar
  • The scar game library
  • Application Structure
    • App
    • Scenes
    • Spaces
    • Entities
    • Components
    • Systems
    • Objects
    • Drawing
    • Events
  • Builtin Features
    • Actions
    • Assets
    • Config
    • Input
    • Logger
    • Music
    • Tweens
    • Util
    • Vectors & Rects
  • Builtin Components
    • Text
    • Sprite
    • Animated Sprite
  • Builtin Systems
    • Animate Sprites
Powered by GitBook
On this page

Was this helpful?

  1. Application Structure

App

PreviousThe scar game libraryNextScenes

Last updated 5 years ago

Was this helpful?

Each scar application should define a main class which inherits from Scar::App. This abstract class contains the basic structure of a scar app and takes care of running all the features of the library such as , , and so on.

You have to define three methods: init, update(dt) and render(dt). In init all the applications' initialization should take place (like loading assets). update and render are intended for game logic updates and drawing. The class is then created with a SFML window and an Input manager instance (why will be explained in )

require "scar"
# crsfml, json and yaml are required automatically

class MyCoolGame < Scar::App
    # this simplifies the use of scar features as
    # it removes the need for always typing Scar::
    include Scar
    
    def init
        # setup input
        # load assets
        # build scene
    end
    
    def update
        # update game
    end
    
    def render
        @window.clear(SF::Color::Black)
        # render stuff
    end
end

window = SF::RenderWindow.new(
            SF::VideoMode.new(1600, 900),
            "My cool game",
            SF::Style::Close)
app = MyCoolGame.new(window, Scar::Input.new)
app.run

At the bottom of the example you can see how a scar app is executed. You just have to create a window and an input manager and pass them to his app class. To start the app, simply call the App#run method.

More stuff

It also provides the App#exit instance method which can be used to exit the program. It unloads all assets and disposes the window before exiting with the given status code.

The init and update functions should not update or draw any entities. They are supposed to be an easy way to update global game status or to debug. is explained in a later section.

The Scar::App class defines getters for the sfml window window, the input handler input, the scene stack scene_stack and the current actions actions. Refer to the for more info.

How , , and are handled is be explained in the respective sections of this book.

events
tweens
actions
Input Handling
Drawing
reference
events
scenes
tweens
actions