Estoy haciendo un sitio web virtual abierto cuando con la biblioteca P5. Tengo que hacerlo compatible con los teléfonos. Agregué la función de invisibilidad para probarlo. Sé cómo agregar un toque, pero ¿cómo hago múltiples toques ya que esto requiere múltiples toques? Aquí está mi código
var laugh, laughI, sadI, sad, titleI, title, annoyI, annoy, motiI, moti var stressI, stress, angryI, angry; function preload(){ laughI = loadImage("images/laugh.png"); sadI = loadImage("images/sad.png"); titleI = loadImage("images/title.png"); annoyI = loadImage("images/annoy.png"); motiI = loadImage("images/motivation.png"); stressI = loadImage("images/stress.png"); angryI = loadImage("images/angry.png"); } function setup() { createCanvas(windowWidth, 1800); title = createSprite(windowWidth/2, 80) title.addImage(titleI) title.scale = 0.9; laugh = createSprite(windowWidth/2, 270); laugh.addImage(laughI); laugh.scale = 0.2; sad = createSprite(windowWidth/2, 550); sad.addImage(sadI); sad.scale = 0.2; annoy = createSprite(windowWidth/2, 830); annoy.addImage(annoyI); annoy.scale = 0.2; moti = createSprite(windowWidth/2, 1110); moti.addImage(motiI); moti.scale = 0.2; stress = createSprite(windowWidth/2, 1390); stress.addImage(stressI); stress.scale = 0.2; angry = createSprite(windowWidth/2, 1670); angry.addImage(angryI); angry.scale = 0.2; } function draw() { background(0); if(mouseIsPressed){ laugh.visible = false; } drawSprites(); }En un teléfono, creo que obtendrá el evento mousePressed() si un usuario toca, y mouseIsPressed debe establecerse en verdadero cuando ocurre un toque (al menos hasta que disminuya la cantidad de toques). Sin embargo, también puede verificar explícitamente los toques con la matriz de touches .
function setup() { createCanvas(windowWidth, windowHeight); // Prevent top level gesture scrolling/zooming // This if iOS Safari specific document.addEventListener("gesturestart", function (e) { e.preventDefault(); return false; }); } let pressedAt; let clickedAt; function mousePressed(e) { pressedAt = frameCount; } function mouseClicked(e) { clickedAt = frameCount; } function draw() { background(220); if (frameCount - clickedAt < 30) { background("orange"); } else if (frameCount - pressedAt < 30) { background("blue"); } else { if (touches.length) { background("green"); text(`${mouseIsPressed ? 'mouse pressed' : 'mouse not pressed'} (touches: ${touches.length})`, 10, height / 2); } else if (mouseIsPressed) { background("red"); } } } <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>Dado que los fragmentos no funcionan en dispositivos móviles, puede ejecutar el ejemplo aquí: https://editor.p5js.org/Kumu-Paul/full/LpkV7Gio2