Bacon2D

ScriptBehavior QML Type

ScriptBehavior is a Behavior including a script to evaluate on each update. More...

Import Statement: import Bacon2D 1.0
Inherits:

Behavior

Properties

Detailed Description

The ScriptBehavior's script gets called each time the Scene update its entities. Can be used to build custom behavior, like movement logic and AI.

Game {
    width: 800
    height: 600
    Scene {
        width: parent.width
        height: parent.height
        Entity {
            width: parent.width
            height: parent.height
            updateInterval: 50
            behavior: ScriptBehavior {
                script: {
                    var newPos = entity.x + 5
                    entity.x = newPos > parent.width ? 0 : newPos
                    console.log("update: x -> ", entity.x)
                }
            }
        }
    }
}

Property Documentation

script : string

This property contains the javascript to evaluate on each update