Interface Sketch
public interface Sketch
Base interface for all framework sketches.
setup(Graphics) is called once, before the first frame.
render(Graphics, Frame, Params, Input) is called every frame.
Subinterfaces may add lifecycle hooks for other kinds of content.
Usage:
public class MySketch implements Sketch {
public void render(Graphics g, Frame f, Params p, Input in) {
g.background(30);
g.fill(255);
g.circle(g.cx(), g.cy(), 40 + 20 * Math.sin(f.time()));
}
public static void main(String[] args) {
SketchApp.run(new MySketch());
}
}
-
Method Summary
-
Method Details
-
render
Renders one frame of the sketch.Usually called about 60 times per second, but the actual frame rate can vary. Use
f.dt()for movement rather than assuming a fixed time between frames.- Parameters:
g- the graphics context for drawingf- timing and frame-count information for this tickp- interactive parameters (sliders, toggles, etc.); may beParams.NO_OPwhen the GUI is disabledin- mouse and keyboard state for this frame
-
setup
Initializes sketch resources before rendering begins.Called once, after the graphics context is ready. Load images and create reusable resources here rather than in
render().- Parameters:
g- graphics context
-