0

I have an HTML game using the cocos 2D game engine and javascript. I have an image within the canvas, on clicking which I want the image to go full screen. Please don't confuse this question with doing this: http://jlongster.com/2011/11/21/canvas.html which I am able to reproduce just fine. The button is in the cocos canvas. Any help would be much appreciated.

user81371
  • 91
  • 1
  • 10

1 Answers1

1

So, I figured out the answer to my own question. The new Cocos-HTML5 has a nice API that makes your canvas full screen when you press a button:

if(coordinates are from the touch area)
{
    cc.Screen.getInstance().requestFullScreen(document.getElementById('<DIV ID in which your cocos canvas is embedded>'))
}

For more details check out: http://www.cocos2d-x.org/forums/19/topics/42564?r=42958#message-42958

user81371
  • 91
  • 1
  • 10
  • And how to toggle fullscreen? – Mohammad Kermani Mar 08 '17 at 14:23
  • 1
    Hi, I don't work on cocos anymore, but IIRC, we would exit fullscreen using the Javascript APIs `exitFullscreen()` - https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API. This was back when the games were displayed on the web canvas, and you needed a way to make the canvas fullscreen. Cocos also had a flag that can determine if the canvas is currently in fullscreen mode or not. Let me know if you need more help, and I can look. – user81371 Mar 10 '17 at 23:03
  • Thanks for your help, I got a Cocos game source, but it is oddly making the page fullscreen! But I don't know what and where that defined and I don't see any flag on the canvas tag. – Mohammad Kermani Mar 11 '17 at 06:43
  • Is your code available somewhere, so I can take a look? – user81371 Mar 13 '17 at 02:04
  • It was on GitHub for a while, but it's not there now. Thanks for your help :) – Mohammad Kermani Mar 13 '17 at 08:18