Author Topic: Switching zoom in-game  (Read 1744 times)

Raf

  • Contributor
  • ****
  • Posts: 268
  • Karma: +0/-0
    • View Profile
Switching zoom in-game
« on: Mon, Feb 4, 2013 »
I'm wondering if others here have had the same problem, and how you guys have solved it.

My game is at zoom level 2 (when starting out, I followed a tutorial where it was set that way. Drew all my in-game graphics accordingly, and don't feel like redrawing them all to fit a zoom level 1). The menu's and everything else is at zoom level 1, since, when I was drawing the menu items, I noticed it looked like crap and noticed the zoom level thing. Had the chance to take care of it there, as it wasn't too late yet.

Now I'm trying to add an in-game pause screen. I can switch between zoom level 1 and 2 just fine, except... the entire game camera gets reset.

I've tried a crapload of things, but none have worked so far. I also can't keep the zoom level at 2 for the pause screen, since the buttons don't work then (their "hotspot" is god knows where then).

So has anybody been in the same situation? How did you solve it?

Edit: Just for the records, these are what I've used so far:
1. Leave it as is.
Result: buttons don't work (hotspot is way off)

2. Switch camera the same way I always do (create a new camera, create a new cameras array, add the new camera to the new array).
Result: It works just fine, except that the old camera is reset, and thus empty. It doesn't get refilled completely upon a new update (maybe that's a path to go, redrawing background colour and everything on each update...)

3. Switch camera the same way as in 2. but add a backup of the current camera to my registry during the game (so not during pause), and assigning that to the new cameras array.
Result: Everything works, except you got to press "P" twice: Once to remove the pause screen, once to get the game to work again.

4. Same as 3. but taking the backup is done with an additional check (to make sure the player isn't pressing P at that moment).
Result: Everything works, and the game works when you unpause. When you want to pause again, the game pauses without the pause screen. Unpausing and repausing shows the screen again.

5. Zoom gets switched by changing the FlxG.cameras[0].zoom without changing anything else.
Result: Works like a charm, except that the game itself gets zoomed out behind the overlay as well. The buttons also don't work here, for god knows what reason
« Last Edit: Mon, Feb 4, 2013 by Raf »

tbonius

  • Member
  • **
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Switching zoom in-game
« Reply #1 on: Wed, Feb 6, 2013 »
not sure if this helps but Ive been using this excellent class found here for adjusting zooms on the fly..

http://bullettimeninja.blogspot.com.au/2011/09/zoom-camera.html

Raf

  • Contributor
  • ****
  • Posts: 268
  • Karma: +0/-0
    • View Profile
Re: Switching zoom in-game
« Reply #2 on: Wed, Feb 6, 2013 »
"Whoa! That's an intense amount of code! What does it mean???"
That's damn right ;D

I don't need the alignment, but some of the screenshots of the problems he's having, are the same as mine. I'll give that class a try this evening and see if it'll help.

Esti

  • Active Member
  • ***
  • Posts: 104
  • Karma: +0/-0
    • View Profile
Re: Switching zoom in-game
« Reply #3 on: Wed, Feb 6, 2013 »
awesome stuff

Check it out on Mochi!

Raf

  • Contributor
  • ****
  • Posts: 268
  • Karma: +0/-0
    • View Profile
Re: Switching zoom in-game
« Reply #4 on: Wed, Feb 6, 2013 »
Doesn't work. To give you an idea of the problem, this is as far as I've gotten it so far:

http://freehare.com/raf/index.html

Go to "Campaign", then select a level (you probably have only lvl. 1 available, so that one), then press P. That's the pause screen. Pressing P again works properly. Pressing the "resume" button once, works properly as well. Pressing P and then "resume" again and... things are screwed up.

The code for pressing P is this:
In my play state:
Code: [Select]
        override public function update():void {
            if (!FlxG.paused) {
                //super.update();
                if (FlxG.keys.justPressed("P")) {   
                    pauseMenu = new LostFocusScreen(this);
                    add(pauseMenu);
                    //pauseMenu.activate();
                }
                else {           
                   // Active game stuff
                }
            }
            else {       
                if (FlxG.keys.justPressed("P")) {
                    pauseMenu.unpause();
                }
                else {
                    pauseMenu.update();
                }
            }                   
        }

The pauseMenu class:
Code: [Select]
package 
{
    import flash.display.Graphics;
    import flash.media.Camera;
    import org.flixel.*;
    import form_objects.*;
   
    public class LostFocusScreen extends FlxGroup
    {
        private var state:StoryState;
       
        public var resume_btns:ButtonSpriteGenerator;
        public var quit_btns:ButtonSpriteGenerator;
        public var resume_btn:MainButton;
        public var quit_btn:MainButton;
        private var camera:FlxCamera;
       
        (...)       
       
        public function LostFocusScreen(_state:StoryState) {
            camera = new FlxCamera(0, 0, 640, 480, 1);
            activate();
            state = _state;
            (...)           
            resume_btns = new ButtonSpriteGenerator(btn_resume_off, btn_resume_on, btn_menu_off, btn_menu_on,  100, 25);   
            resume_btn = new MainButton(105, 100, unpause, resume_btns.button_off, resume_btns.button_on, 100, 25, 1);
            resume_btn.pauseProof = true;
            add(resume_btn);

            quit_btns = new ButtonSpriteGenerator(btn_quit_off, btn_quit_on, btn_menu_off, btn_menu_on,  100, 25);   
            quit_btn = new MainButton(105, 140, quit, quit_btns.button_off, quit_btns.button_on, 100, 25, 1);
            quit_btn.pauseProof = true;
            add(quit_btn);
        }

        public function activate():void {
            FlxG.addCamera(camera);
            FlxG.mouse.show();   
            Settings.activateLayer(1);
            FlxG.paused = true;
        }
       
        public function deactivate():void {
            FlxG.removeCamera(camera, false);
            Settings.activateLayer(0);
            FlxG.mouse.hide();
            FlxG.paused = false;
        }
       
        public function removeFromParent():void {
            state.remove(state.pauseMenu);           
        }
       
        public function unpause():void {
            deactivate();
            removeFromParent();
        }
       
        public function quit():void {
            FlxG.removeCamera(camera, false);
            FlxG.paused = false;
            FlxG.switchState(new MenuState);
        }       
    }

}

I don't see a difference in the code that gets executed when pressing "P" to unpause, and when clicking the "resume" button, as both call the same function.
« Last Edit: Wed, Feb 6, 2013 by Raf »

Raf

  • Contributor
  • ****
  • Posts: 268
  • Karma: +0/-0
    • View Profile
Re: Switching zoom in-game
« Reply #5 on: Tue, Feb 12, 2013 »
Nobody got any ideas?

Raf

  • Contributor
  • ****
  • Posts: 268
  • Karma: +0/-0
    • View Profile
Re: Switching zoom in-game
« Reply #6 on: Tue, Feb 19, 2013 »
Ok, screw this. I can't figure this out, and nobody else seems to either want to or able to figure this out. I'll just kick the pause screen out then. **** it!