setup()
setup() runs once when the sketch starts. Use it to initialize your canvas, create objects, and set up the starting state of your game.
function setup() {
createCanvas(windowWidth, windowHeight);
player = { x: width / 2, y: height - 50, w: 80, h: 20 };
}
Line-by-line explanation (2 lines)
🔧 Subcomponents:
createCanvas(windowWidth, windowHeight);
Creates a canvas that fills the entire browser window at any size
player = { x: width / 2, y: height - 50, w: 80, h: 20 };
Defines the paddle as an object with position, width, and height so it can be moved and drawn
createCanvas(windowWidth, windowHeight);- Creates a canvas that matches the full browser window size using windowWidth and windowHeight variables
player = { x: width / 2, y: height - 50, w: 80, h: 20 };- Creates a player object with x and y position (centered horizontally, 50 pixels from bottom), width w of 80 pixels, and height h of 20 pixels