algorithmic Zoom calculation help rmmv?

● ARCHIVED · READ-ONLY
Started by Jonforum 5 posts View original ↗
  1. Would anyone have the right math formula to calculate the zoom in rpg maker mv?
    I need one based on the mouse position.


    PHP:
    const SM_S = SceneManager._scene;
    const mapZoom = SM_S._spriteset._tilemap.scale;
    PHP:
        function wheel_(event) {//TODO: zoom system
            if(event.wheelDeltaY>0){
                mapZoom.x+=0.05;
                mapZoom.y+=0.05;
                $gameMap._displayX+=0.05
                dX+=0.05;
            }else{
                mapZoom.x-=0.05;
                mapZoom.y-=0.05;
                $gameMap._displayX-=0.05
                dX-=0.05;
            }
        };

    thank
  2. I have tried to deal with zoom, but always failed in the end :( However, maybe it'd be more appropriate to use $gameMap._displayX+= Math.floor (0.05 * Graphics.boxWidth) multiplied by 1 or -1 depending on which half of the screen your mouse is.
    Same for the Y direction.
  3. Someone explain to me a trick that seems logical to me, it remains for me more than to apply it.
    Ideally I would like something a little more mathematical.
    The idea is to remember coordinates of certain point on screen, and then restore them.

    PHP:
    class myCamera extends PIXI.Container {
           constructor {
                  super();
                  memCoord = new PIXI.Point();
               memCoord2 = new PIXI.Point();
           }
    
       public pushPivot(pos) {
           this.toLocal(pos, null, this.memCoord);
       }
    
       public popPivot(pos) {
           this.toLocal(pos, null, this.memCoord2);
           this.pivotTarget.x -= this.memCoord2.x - this.memCoord.x;
           this.pivotTarget.y -= this.memCoord2.y - this.memCoord.y;
       }
    }
    //declare scale somewhere. you can do it in camera too.
    var scale = 1.0;
    ...
    //zoom in
    const mousePos = renderer.interaction.mouse.global;
    stage.camera.pushPivot(mousePos);
    
    scale *= 1.1;
    camera.scale.set(scale);
    
    stage.camera.popPivot(mousePos);
  4. ho yess, finaly, no need to touch the $gameMap._displayX

    PHP:
        memCoord = new PIXI.Point();
        memCoord2 = new PIXI.Point();
        function pushPivot(pos) {
            SM_S._spriteset._tilemap.toLocal(pos, null, memCoord);
        }
        function popPivot(pos) {
            SM_S._spriteset._tilemap.toLocal(pos, null, memCoord2);
            SM_S._spriteset._tilemap.pivot.x -= memCoord2.x - memCoord.x;
            SM_S._spriteset._tilemap.pivot.y -= memCoord2.y - memCoord.y;
        }
        function wheel_(event) {//TODO: zoom system
            setMouseXY();
            const mousePos = new PIXI.Point(mX,mY);
            pushPivot(mousePos);
            if(event.wheelDeltaY>0){
                mapZoom.x+=0.1
                mapZoom.y+=0.1
            }else{
               mapZoom.x-=0.1;
               mapZoom.y-=0.1;
            }
            popPivot(mousePos);
        };
  5. This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.