Skip to content

Instantly share code, notes, and snippets.

@zicklag
Created March 8, 2019 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zicklag/d2e7713b02c43ef58e0f0c9952da29df to your computer and use it in GitHub Desktop.
Save zicklag/d2e7713b02c43ef58e0f0c9952da29df to your computer and use it in GitHub Desktop.
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