aduros / flambe

Rapidly cook up games for HTML5, Flash, Android, and iOS.
https://github.com/aduros/flambe/wiki
MIT License
743 stars 118 forks source link

Resize event after enter the fullscreen mode on iPhone 4 #166

Closed pspmiracle closed 10 years ago

pspmiracle commented 11 years ago

Hi!

Please help me. I didn't receive resize event when change the fullscreen mode on my iPhone 4.

1) I have loaded the HTML5 game page. Resize event is fired and viewport fits all screen space. It works great. img_3649

2) Then I go to the fullscreen mode but resize event isn't fired. Why? img_3650

My code:

public var BASE_WIDTH = 480;
public var BASE_HEIGHT = 320;
public var ScaleFactor:Float;
public var ScaleFactorX:Float;
public var ScaleFactorY:Float;
public var viewport:Entity;
public function new () {   
        viewport = new Entity().add(new Sprite());
        System.root.addChild(viewport);
        System.stage.resize.connect(updateViewportScale);
        updateViewportScale();
}
private function updateViewportScale() {
            var w = System.stage.width;
            var h = System.stage.height;

            ScaleFactorX = w / BASE_WIDTH;
            ScaleFactorY = h / BASE_HEIGHT;
            ScaleFactor = Math.min(ScaleFactorX, ScaleFactorY);

            var viewportSprite = viewport.get(Sprite);
            viewportSprite.x._ = Math.floor(0.5*w - 0.5*ScaleFactor*BASE_WIDTH);
            viewportSprite.y._ = Math.floor(0.5*h - 0.5*ScaleFactor*BASE_HEIGHT);
            viewportSprite.setScale(ScaleFactor);
}

PS: Sorry for my English.

Thanks!

aduros commented 11 years ago

Is the stage width/height not changing after a fullscreen, or is it not even firing resize events at all?

Thanks for the report!

pspmiracle commented 11 years ago

Yes, resize event isn't fired at all.

volkipp commented 10 years ago

We've also run into this. At first glance, the code in HTMLStage hideMobileBrowser() corrects the problem when called in resizeCanvas(). It's a little tough to debug because Mobile Safari debugger breaks connection with Safari desktop when you go fullscreen. Fun times.

aduros commented 10 years ago

Thanks for the patch Kipp! This doesn't actually fix it for me though, running iOS 6. When I hit the fullscreen button, it appears that no resize event is ever fired at all. No events for window.resize, document.resize, document.body.resize...

On the other hand, none of this applies to iOS 7, where the address bar can't be hidden at all as far as I can tell :(

volkipp commented 10 years ago

Weird, I tested the patch against 6.1.3 on a 4S and it worked okay for me. I wasn't getting resize events from flambe, but the native events were firing for me. What device were you testing against? (Although it probably shouldn't matter)

On Sep 24, 2013, at 3:19 AM, Bruno Garcia notifications@github.com wrote:

Thanks for the patch Kipp! This doesn't actually fix it for me though, running iOS 6. When I hit the fullscreen button, it appears that no resize event is ever fired at all. No events for window.resize, document.resize, document.body.resize...

On the other hand, none of this applies to iOS 7, where the address bar can't be hidden at all as far as I can tell :(

— Reply to this email directly or view it on GitHub.

aduros commented 10 years ago

On 09/24/2013 12:47 PM, Kipp Ashford wrote:

What device were you testing against? (Although it probably shouldn't matter)

iPod Touch (latest generation) running 6.1.3.

After futzing with this some more, I'm finding that I only get native window resize events if "height=device-height" is removed from the viewport meta tag...

pspmiracle commented 10 years ago

aduros, it works, thanks!