Notice: Welcome to TinyChan, an account has automatically been created and assigned to you, you don't have to register or log in to use the board, but don't clear your cookies unless you have set a memorable name and password. Alternatively, you can restore your ID. The use of this site requires cookies to be enabled; please cease browsing this site if you don't consent.

TinyChan

New reply in topic: Random discussions thread

You are not recognized as the original poster of this topic.

:

You are required to fill in a captcha for your first 5 posts. Sorry, but this is required to stop people from posting while drunk. Please be responsible and don't drink and post!
If you receive this often, consider not clearing your cookies.

Please familiarise yourself with the rules and markup syntax before posting.


Replying to Phoneposter…

I never really cared about p5.js on mobile (I hate mobile-friendly multi-touch programming) but I noticed that mouse events don't properly work on mobile:
function appendStyle(CSS){
  let existingStyles=document.querySelectorAll("style");
  for(let style of existingStyles)
    if(style.innerHTML===CSS)return; //Already exists…
  let style=document.createElement("style");
  style.type="text/css";
  document.head.appendChild(style);
  style.appendChild(document.createTextNode(CSS));
  /*if(!document.querySelector(`style:contains("${CSS}")`)){ //Error: not a valid selector…
    let style=document.createElement("style");
    style.type="text/css";style.innerHTML=CSS;
    document.head.appendChild(style);
  }*/
}
function handleTouch(event){ //Converts touches to mouse events…
  let touch=event.touches[0],
      type=event.type;
  //window[event.type.replace(/touch(.)/i,(match,p1)=>"mouse"+p1.toUpperCase())](touch.clientX,touch.clientY); //Doesn't work because: “start” → “Pressed”, “move” → “Dragged”, “end” → “Released”…
  //mouseX=touch.clientX;mouseY=touch.clientY;
  switch(type){
    case"touchstart":
      mousePressed(touch.clientX,touch.clientY);
      //mouseIsPressed=true;
      break;
    case"touchmove":
      mouseDragged(touch.clientX,touch.clientY);
      break;
    case"touchend":
      mouseReleased(touch.clientX,touch.clientY);
      //mouseIsPressed=false;
      break;
  }
}
function setup(){
  let metaContent="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"; //Prevent zooming…
  if(!document.querySelector(`meta[name="viewport"][content="${metaContent}"]`)){
    let meta=document.createElement("meta");
    meta.name="viewport";
    meta.content=metaContent;
    document.head.appendChild(meta);
  }
  createCanvas(windowWidth,windowHeight);
  appendStyle(`html,body{overscroll-behavior-y:contain;}`); //Prevent pull-down-to-refresh…
  /* Optional…
  document.addEventListener("touchstart",handleTouch);
  document.addEventListener("touchmove",handleTouch);
  document.addEventListener("touchend",handleTouch);
  */
}
function draw(){
  background(200);
  for(let touch of touches){
    stroke(0);strokeWeight(30);
    point(touch.x,touch.y);
    noStroke();fill(0);
    textAlign(CENTER,BOTTOM);
    text(`(${+touch.x.toFixed(2)},${+touch.y.toFixed(2)})\nID: ${touch.id}`,touch.x,touch.y-32)
  }
}
//Prevent default (e.g. panning/zooming)…
function touchStarted(){return false;}
function touchEnded(){return false;}
function touchMoved(){return false;}