Skip to content

Instantly share code, notes, and snippets.

@zicklag zicklag/UiScript.hx
Created Mar 8, 2019

Embed
What would you like to do?
UiScript exampel for Armory3D
package arm;
import iron.Scene;
import iron.App;
import iron.system.Time;
import armory.system.Event;
import armory.trait.internal.CanvasScript;
class UiScript extends iron.Trait {
var canvas:CanvasScript;
public function new() {
super();
notifyOnInit(function() {
// Get canvas attached to scene
canvas = Scene.active.getTrait(CanvasScript);
// Once the canvas is ready, tell it to start running the update function
canvas.notifyOnReady(function() {
notifyOnUpdate(update);
});
});
}
// This runs every frame because of the `notifyOnUPdate(update)` code above
function update() {
// Canvas may be still being loaded
if (!canvas.ready) return;
// Get image
var img = canvas.getElement("selection");
// Set image's x based on the "qb_selected" property of the object
// that this trait is applied to.
if (this.object.properties["qb_selected"] == 0) {
img.x = 510;
} else {
img.x = 610;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.