Repository navigation
Menu Rendering
inventivetalent edited this page May 17, 2016
·
2 revisions
In order to render your menu, you need to call the renderer functions from your script. As the tick() function is called regularly, it's a good place to call the functions.
renderer.refresh(): Refreshes the ItemFrames the menu was placed on. It's not necessary to call this very often, but it's generally a good idea to call it every few seconds for a continuous display.
Why you need to call it:
- The menu initially doesn't know which ItemFrames it is placed in, so you first have to let it know where it is.
- When chunks unload (or if you change the world, leave the server, etc.) the ItemFrames get unloaded and the menu once again doesn't know where it is.
renderer.render(): This is the actual render function. It tells the renderer to reset the previous image and call your script's render function.
It should be sufficient to use it without parameters, but you can also use renderer.render(player) to render it for specific players only.
function init() {
options.tickSpeed = 1; // Our tick speed is 1 - 20 times a second
}
// Variable to keep track of the current tick
var ticks = 0;
function tick() {
if (ticks == 10) { // This will call the render function twice every second
renderer.render();
}
if (tick >= 20) { // One second is over
renderer.refresh(); // Refresh the renderer
ticks = 0; // Reset our counter
}
// Increase the ticks, so we know how much time passed
ticks++;
}
function render(graphics, player) {
// Do rendering stuff
}