In order to keep highest SVG-standard upon my buttons, I want to use the “HTML+CSS/UI”-example frame (https://developer.playcanvas.com/en/tutorials/htmlcss-ui/), and not the 2DScreen-published-export touch-button setup (https://developer.playcanvas.com/en/tutorials/basic-touch-input/)
Project:
https://playcanvas.com/editor/scene/1167085 … and as published: https://playcanv.as/b/OYMaPP5d/
As one can see I cannot do by ‘click’ alone if mobile-screen resolution is <1800 combined px:
The following reacts to mouse/workstation above 1800 px, but not below with ‘touch’.
Ui.prototype.bindEvents = function() {
var self = this;
// example
//
// get button element by class
var button = this.div.querySelector('.button');
var counter = this.div.querySelector('.counter');
// if found
self.scrResToMobOrNotDeterm = window.innerHeight + window.innerWidth;
if(self.scrResToMobOrNotDeterm>1800){
if (button) {
// add event listener on `click`
button.addEventListener('click', function() {
++self.counter;
if (counter)
counter.textContent = self.counter;
console.log('button clicked'); self.app.root.findByName("Text").element.text = "Mouse";
// try to find object and change its material diffuse color
// just for fun purposes
var obj = pc.app.root.findByName('chamferbox');
if (obj && obj.model && obj.model.model) {
var material = obj.model.model.meshInstances[0].material;
if (material) {
material.diffuse.set(Math.random(), Math.random(), Math.random());
material.update();
}
}
}, false);
}else{
if (button) {
/// trying by standard js-DOM event list (https://www.w3schools.com/jsref/dom_obj_event.asp):
button.addEventListener('ontouchStart', function(){
self.app.root.findByName("Text").element.text = "TchSt"; }, false);
button.addEventListener('ontouchend', function(){ self.app.root.findByName("Text").element.text = "TchEd"; }, false);
/// trying by pc.EVENT:
if(self.app.touch) { self.app.touch.on(pc.EVENT_TOUCHSTART, self.onTouchStart, self);
self.app.touch.on(pc.EVENT_TOUCHEND,self.onTouchEnd, self); }
}
}
}
if (counter)
counter.textContent = self.counter;
};
Ui.prototype.onTouchStart= function (){ this.app.root.findByName("Text").element.text = "OTS"; };
Ui.prototype.onTouchEnd= function (){ this.app.root.findByName("Text").element.text = "OTE"; };
What to do in order to merge the two example-approaches? (so yes, they both work independently, but the cross-platform event-compromise of ‘click’ seems insufficient when it comes to holding/keeping the finger down on a mobile screen)