I'm a beginner at p5.js and coding in general. For my class project, I'm creating a customizable birthday card. Three sections of the card are customizable: the cake style, hat style, and facial expression on the cake. Ideally, users would click on each section of the card to cycle through the customization options to suit their taste.
What I have right now in the code pasted on this post is just the cake style options. Additionally I coded it so that users can click on a button to choose their cake style rather than clicking on a specific area on the card because that was a lot more simple for me to figure out.
My question is, how would I code it so that on the user's first click on the button, the first cake option would pop up, then on the second click, the second cake option would pop up, etc.? I need one cake option to pop up per click; all the other cake options need to stay hidden.
Another question I have is about cycling back to the first cake option after all cake options have been displayed. I have five cake options, so how would I code it so that not only will the first click bring up the first cake option, but also the sixth, eleventh, sixteenth, etc.?
Thanks in advance.
let clickCount = 0
let cakes
let cakeButton
function preload (){
card_bg = loadImage ("card_bg.png")
cake_chocolate = loadImage ("cake_chocolate.png")
cake_pink = loadImage ("cake_pink.png")
cake_pinkDrip = loadImage ("cake_pinkDrip.png")
cake_rainbow = loadImage ("cake_rainbow.png")
cake_white = loadImage ("cake_white.png")
hat_chevron = loadImage ("hat_chevron.png")
hat_dots = loadImage ("hat_dots.png")
hat_puff = loadImage ("hat_puff.png")
hat_stars = loadImage ("hat_stars.png")
hat_stripes = loadImage ("hat_stripes.png")
}
function setup() {
createCanvas(450, 600);
background(220);
image (card_bg, 0, 0)
cakeButton = createButton("click me", "blue")
cakeButton.position (125, 600)
cakeButton.size (200, 150)
cakeButton.mousePressed (cakePress)
}
function cakePress() {
clickCount++
imageMode (CENTER)
let cakes = [cake_chocolate, cake_pink, cake_pinkDrip, cake_white, cake_rainbow]
for (let i = 0; i<5; i++){
if (clickCount === i+1){
image (cakes[i], 225, 425)}
else if (clickCount === i+2 && cakes[i] === true){
cakes[i].hide()
}
}
}