[SOLVED] Variable Value to Adjust Picture Based on Screen Size

Discussion in 'Javascript/Plugin Support' started by RyanBram, Jul 6, 2019.

Thread Status:
Not open for further replies.
  1. RyanBram

    RyanBram Veteran Veteran

    Messages:
    184
    Likes Received:
    138
    First Language:
    Indonesian
    Primarily Uses:
    RMMV
    [​IMG] [​IMG]

    In event commands of RPG Maker MV, we can insert picture by entering its absolute value for its position.
    Although it work as it, but it doesn't respond with change on screen size. If I change screen size with plugin, I should re-enter the position value or my picture will appear in wrong position. There are option to assign this position using Javascript variable.

    Can anybody show me, how to create variable that makes my picture relative to current screen resolution. I need variable value for "Left", "Center", "Right" for X-value and also "Bottom" for Y-value.

    I need something like (it's assumed the picture is anchored at "Upper Left":
    Right = [Current screen size] - [Picture Width]
    Center = [Current screen size] / 2 - [Picture Width] / 2

    If above example is also wrong, please correct me to find ideal value.

    Thanks.
     
    #1
  2. MushroomCake28

    MushroomCake28 KAMO Studio Veteran

    Messages:
    1,614
    Likes Received:
    2,861
    Location:
    Montreal, Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    Well first of all it depends if your plugin really changes the Graphics width/height, or if it simply scales the canvas to your new window size. If it's the second scenario, then everything should work as it is. Changing the resolution by not zooming in/out mid game is not something common, and I only know about one plugin that does that (one of my plugin, check my Screen Resolution plugin for that). Even as the coder of that plugin, I don't recommend doing it unless you're a coder and can manually correct stuff in the game's code.

    If it's the first scenario, then your position can be updated to:
    Code:
    var x = posX * Graphics.width / originalScreenWidth;
    var y = posY * Graphics.height / originalScreenHeight;
    So for example, if your original resolution is 1280x720 and you want your window to be placed at x = 200 and y = 100, the code would look like this:
    Code:
    var x = 200 * Graphics.width / 1280;
    var y = 100 * Graphics.height / 720;
    If the new resolution is 1920x1080 (assuming it's not just the canvas zooming), would x = 309 and y = 150.

    So basically you don't touch Graphics.width and Graphics.height since it will return the current screen resolution, you replace posX and posY by your x and y position, and replace the originalScreenWidth/Height variable by your original screen resolution.

    But like I said, will is be a true resolution change, or simply a canvas zooming?
     
    #2
    RyanBram likes this.
  3. RyanBram

    RyanBram Veteran Veteran

    Messages:
    184
    Likes Received:
    138
    First Language:
    Indonesian
    Primarily Uses:
    RMMV
    Hi, @MushroomCake28 .
    Thank you so much for he information. It works. :kaojoy:

    I don't have intention to change resolution mid game, what I want to do is to create different build for my game for different resolution, eg: 1024:768 and 1366:768, so I don't need to readjust the picture position when toggling the screen resolution.

    One more problem is my pictures have different width. (Bust picture). So the formula that you told me will have different result depending on picture width. I made lot's of conversation scene, so I hope I can adjust the position automatically.

    Will you tell me how to make a formula that will also count picture width dynamically? I assume Graphics.width is for screen resolution,are there the equivalent for that, e.g Picture.width ?

    Thanks.
     
    #3
  4. MushroomCake28

    MushroomCake28 KAMO Studio Veteran

    Messages:
    1,614
    Likes Received:
    2,861
    Location:
    Montreal, Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    It's a bit trickier for sprites. You can technically check with sprite.width and sprite.height, but it will only work after the sprite is loaded into ram (depending on computers, I'd say between 5 to 20 frames).

    Also, I need to understand more about your resolution issue. So I understand you won't be switching resolution mid, and instead you'll deploy at different resolution. What I don't know is either different resolution means canvas zooming or a real resolution change. So if you increase the resolution, does the player see more things on the screen (sees more tiles on screen), or does he have the same view distance (but objects are bigger)?
     
    #4
    RyanBram likes this.
  5. RyanBram

    RyanBram Veteran Veteran

    Messages:
    184
    Likes Received:
    138
    First Language:
    Indonesian
    Primarily Uses:
    RMMV
    I am using Yanfly Core engine to change the resolution. So I think it is the true resolution changer, not scaling the screen. Because everything looks smaller which mean I need to scale my picture manually using picture editor, so it doesn't look smaller in larger resolution. And yes, I see more tiles on screen when scaling the resolution (From 1024x768 to 1366x768).

    Thanks.
     
    #5
  6. MushroomCake28

    MushroomCake28 KAMO Studio Veteran

    Messages:
    1,614
    Likes Received:
    2,861
    Location:
    Montreal, Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    Well in that case I suggest using values like Graphics.width / 2, or other similar values (with Graphics.width or Graphics.height in it) instead of flat numbers. Ideally a 2D game is designed for a single resolution, so having multiple resolutions is a challenge, especially if you don't know how to code (that would make it so much easier).
     
    #6
    RyanBram likes this.
  7. RyanBram

    RyanBram Veteran Veteran

    Messages:
    184
    Likes Received:
    138
    First Language:
    Indonesian
    Primarily Uses:
    RMMV
    Thank you very much for your help and suggestion.
    It solves my problem. :thumbsup-left::):thumbsup-right:
     
    #7
    MushroomCake28 likes this.
  8. slimmmeiske2

    slimmmeiske2 Little Red Riding Hood Moderator

    Messages:
    5,309
    Likes Received:
    3,957
    Location:
    Belgium
    First Language:
    Dutch
    Primarily Uses:
    RMXP

    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.

     
    #8
Thread Status:
Not open for further replies.

Share This Page