Jump to content

Invalid button press detection while scaling canvas


Recommended Posts

Greetings, developers! 


I have the following situation here: 

I'm not using any of Phaser tools to manage game stretch logics and I have a problem with Phaser buttons right now.

Guess that Phaser don't know that touch coordinates are related to old canvas style while it was stretched.


The resizing logic is following:

function ResizeGame(){    var Ratio = 960 / 640;    var NewWidth = window.innerWidth;    var NewHeight = window.innerHeight;    if (NewWidth > NewHeight) // LANDSCAPE    {        GameInstance.canvas.style.height = NewHeight + "px";        GameWrapperContainer.style.height = NewHeight + "px";        NewWidth = NewHeight * Ratio;        GameInstance.canvas.style.width = NewWidth + "px";        GameWrapperContainer.style.width = NewWidth + "px";        //GameInstance.scale.width = (960 / (NewHeight * Ratio));        //GameInstance.scale.height = (960 / (NewHeight * Ratio));    } else //PORTRAIT    {        NewHeight = NewWidth / Ratio;        GameInstance.canvas.style.height = NewHeight + "px";        GameWrapperContainer.style.height = NewHeight + "px";        GameInstance.canvas.style.width = NewWidth + "px";        GameWrapperContainer.style.width = NewWidth + "px";        //layer.scale = 960 / NewWidth;    }    GameWrapperContainer.style.left = window.innerWidth * 0.5 - NewWidth * 0.5 + "px";    GameWrapperContainer.style.top = window.innerHeight * 0.5 - NewHeight * 0.5 + "px";}

The button boundaries are offset. I don't know what to do.

Changing camera view boundaries not works.

Changing world boundaries also has no effect.

Tried using Phaser to do that stuff but not found the way how to do it.


The next question is about locking mobile swipes and touches to prevent scrolling of the page while playing. The stretched game has some parts of document body visible. And when player's finger touches that region the browser scrolls content so url bar appears.. Its awful.

Tried doing that:

/* Locking mobile browser non-gaming manipulations */document.body.addEventListener("touchmove", function(e){    e.preventDefault();    return false;});document.body.addEventListener("touchstart", function(e){    e.preventDefault();    return false;});document.body.addEventListener("selectstart", function(e){    e.preventDefault();    return false;});document.body.addEventListener("dragstart", function(e){    e.preventDefault();    return false;});document.body.addEventListener("contextmenu", function(e){    e.preventDefault();    return false;});

But it doesn't work. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...