Documentation ¶
Index ¶
- func DefaultLayoutFunc(w, h int) (int, int)
- type Clock
- type Component
- type ComponentContainer
- type Drawer
- type EmitNotifyFunc
- type Emitter
- type Engine
- type Entity
- type EntityManager
- type EventListener
- type EventManager
- type EventType
- type LayoutFunc
- type PostUpdateFunc
- type ProcessArgs
- type ProcessTrigger
- type Scene
- type SceneChangedArgs
- type SceneManager
- type System
- type SystemManager
- type Updater
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultLayoutFunc ¶
DefaultLayoutFunc uses 1:1 scaling.
Types ¶
type Clock ¶
type Clock struct { // The time in real world seconds. Time float64 // The game time. This is the time that Update() was last called. This should be // used for game logic instead of Time. GameTime float64 // The amount of time spent on the previous tick. DeltaTime float64 }
Clock represents the game clock.
type Component ¶
type Component interface{}
Component is an empty interface for any component type. A component can be anything, though typically it is used by a system and thus implements that system's interface.
type ComponentContainer ¶
type ComponentContainer interface { // Components returns a list of components for the object. Components() []Component }
ComponentContainer is an interface for an object which has a list of components.
type Drawer ¶
Drawer is an interface for the draw system. When a component implements this interface it will have its Draw() method called every frame.
type EmitNotifyFunc ¶
type EmitNotifyFunc func(t EventType, data interface{})
EmitNotifyFunc is a function type which is called when an event is emitted.
type Emitter ¶
type Emitter interface { // Emit broadcasts an event to all listeners. The event type must be a single event and // cannot be EventAll. Panics if the event type is invalid. Emit(t EventType, data interface{}) }
Emitter is an interface for the Emit method which is used for emitting an event type and payload.
type Engine ¶
type Engine interface { ebiten.Game Draw(screen *ebiten.Image) Entities() EntityManager Events() EventManager Scenes() SceneManager Systems() SystemManager SetInitialScene(scene Scene) SetLayout(fn LayoutFunc) }
Engine is the primary interface used both by ebiten and accessing various managers.
type Entity ¶
type Entity interface { ComponentContainer // AddComponent adds a component to the entity. AddComponent(c ...Component) // ID returns the entity's ID ID() int64 }
Entity is an interface for an entity in the game (i.e. game object). Every entity has a unique ID and a list of components. The components contain all of the logic and graphics for the entity.
type EntityManager ¶
type EntityManager interface { // Add adds an entity to the manager. Add(e Entity) // Create creates a new entity using the components from the given container, adds // the entity to the manager, then returns it. Create(container ComponentContainer) Entity // Get returns an entity with the given ID, or nil if it doesn't exist. Get(id int64) Entity // NextID returns the next available entity ID. NextID() int64 // Pop removes and returns an entity that was previously added. If no entity with the // given ID exists, returns nil. Pop(id int64) Entity // Reset removes all entities from the manager and resets the entity ID counter. Reset() }
EntityManager stores a collection of entities and keeps track of an incrementing ID which is used for creating new entities.
func NewEntityManager ¶
func NewEntityManager(events Emitter) EntityManager
NewEntityManager creates a new EntityManager. This function accepts an optional Emitter argument which when provided will create an EntityManager which emits entity added/removed events.
type EventListener ¶
type EventListener struct {
// contains filtered or unexported fields
}
EventListener describes an observer which has subscribed to the event emitter.
type EventManager ¶
type EventManager interface { Emitter // AddListener takes a notifier function and a list of event types. When an event is emitted // that matches any of the provided types the notifier will be called. To listen for all events, // use EventAll. Returns the event listener ID which can be passed to RemoveListener(). AddListener(fn EmitNotifyFunc, types ...EventType) int // RemoveListener takes a listener previously created by AddListener() and removes it. Panics // if the listener is nil. RemoveListener(id int) }
EventManager is an interface for an event emitter that notifies listeners when events are emitted.
func NewEventManager ¶
func NewEventManager() EventManager
NewEventManager creates a new blank EventManager.
type EventType ¶
type EventType int
EventType describes what kind of event is being emitted.
const ( EventAll EventType = iota // EventEntityAdded is fired when a new entity is added to the entity manager. // The event data is the entity that was added. EventEntityAdded // EventEntityAdded is fired when an entity is removed from the entity manager. // The event data is the entity that was removed. EventEntityRemoved // EventSceneChanged is fired when switching to a new scene. // The event data is a SceneChangedArgs object. EventSceneChanged )
Various types of events accepted by an Emitter.
type LayoutFunc ¶
LayoutFunc is used by ebiten to determine how the rendering should be scaled. See ebiten.Game.Layout for more info.
func FixedLayout ¶
func FixedLayout(fixedWidth, fixedHeight int) LayoutFunc
FixedLayout returns a new LayoutFunc which always returns the given width and height.
type PostUpdateFunc ¶
type PostUpdateFunc func()
PostUpdateFunc is an optional function that is returned by a component's Update() method. If a component returns a non-nil value, the function is deferred until all other components have completed updating.
The purpose of this is to defer all state changes until after update processing has finished. This avoids the problem of components behaving differently when they are processed in different orders.
Thus, if a component needs to perform a state change, it should do so only in the PostUpdateFunc return.
type ProcessArgs ¶
type ProcessArgs struct {
Clock Clock
}
ProcessArgs is used to give information to systems during processing.
type ProcessTrigger ¶
type ProcessTrigger int
ProcessTrigger represents when a system should run processing.
const ( // OnUpdate triggers systems to run during the update phase. OnUpdate ProcessTrigger = iota // OnDraw triggers systems to run during the draw phase. OnDraw )
type Scene ¶
type Scene interface { // Setup is called immediately after switching to a new scene. Setup(engine Engine) // Teardown is called immediately after switching from one scene to another. Teardown(engine Engine) }
Scene is an interface for displaying a scene.
type SceneChangedArgs ¶
type SceneManager ¶
func NewSceneManager ¶
func NewSceneManager(engine Engine) SceneManager
type System ¶
type System interface { // CanProcess returns true if the system supports this component. CanProcess(c Component) bool // Process runs the system logic for the component. Process(c Component, args ProcessArgs) // PreProcess is called before any processing begins. PreProcess() // PostProcess is called after all processing has finished. PostProcess() }
System is an interface for handling components that have logic or behavior.
func NewDrawSystem ¶
NewDrawSystem returns a new draw system.
type SystemManager ¶
type SystemManager interface { // AddComponent adds a component to the SystemManager. AddComponent(c Component) // AddSystem adds a new system to the SystemManager. AddSystem(s System, on ProcessTrigger) // ProcessAll iterates through each system that matches the given trigger and processes // all of its components. ProcessAll(args ProcessArgs, on ProcessTrigger) // RemoveComponent removes the given component from all systems. RemoveComponent(c Component) // Reset clears all components from all systems. Reset() }
SystemManager is an interface for managing systems and their components.
func NewSystemManager ¶
func NewSystemManager() SystemManager
NewSystemManager creates a new SystemManager.
type Updater ¶
type Updater interface {
Update(clock Clock) PostUpdateFunc
}
Updater is an interface for the update system. When a component implements this interface it will have its Update() method called every tick.