added touchscreen support
This commit is contained in:
		
							parent
							
								
									1df62ff1fe
								
							
						
					
					
						commit
						6b7ff7e86d
					
				
					 1 changed files with 12 additions and 0 deletions
				
			
		| 
						 | 
					@ -108,4 +108,16 @@
 | 
				
			||||||
		else if(e.key=='ArrowRight') inputs.right=true;
 | 
							else if(e.key=='ArrowRight') inputs.right=true;
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						window.addEventListener('touchstart', e => {
 | 
				
			||||||
 | 
							let x=e.touches[0].clientX/window.innerWidth-.5;
 | 
				
			||||||
 | 
							let y=e.touches[0].clientY/window.innerHeight-.5;
 | 
				
			||||||
 | 
							const angle=((Math.atan2(x, y)+2*Math.PI)%(2*Math.PI))/Math.PI;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							let inputs=currentInputs;
 | 
				
			||||||
 | 
							if(angle>.25 && angle <.75) inputs.right=true;
 | 
				
			||||||
 | 
							else if(angle>.75 && angle<1.25) inputs.up=true;
 | 
				
			||||||
 | 
							else if(angle>1.25 && angle<1.75) inputs.left=true;
 | 
				
			||||||
 | 
							else inputs.down=true;
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
})();
 | 
					})();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue