Change the View Offset

About Monkey 2 Forums Monkey 2 Programming Help Change the View Offset

This topic contains 12 replies, has 4 voices, and was last updated by  c0d3r9 8 months, 3 weeks ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #15142

    c0d3r9
    Participant

    Is it possible to set the offset from the view?
    I.e. if i have a a map with a width 1000px and the virtual resolution 500px and with the offset i can scroll left and right.

    I know how i can draw a tilemap only the tiles who needed but for little tilemaps that would be useful for scrolling.

    btw. In this case is it possible to fix the position of a sprite on screen.(so it doesn´t scroll)
    Alternative i can calculate the new position every time of course.

    #15156

    Abe _King_
    Participant

    Not exactly sure what you’re looking for but I’m assuming you’re looking for working with applying transformations to the canvas??

    The basic ones I can recommend to start out with would be translating the canvas and scaling the canvas. Utilizing both could allow you to create something of a camera that can pan and zoom.

     

    These both have different effects on the way things are drawn if you do them in a certain order. I recommend applying these transformations prior to any drawing.

    #15157

    c0d3r9
    Participant

    Imagine i have a tilemap.
    Each tile 64x64px and the map is i.e. 500×500 tiles.

    The view offset change the area that shows the tiles depend from the resolution.
    Note: i would draw all tiles in this case.

    Like camera movent in 3d.u know?
    In 3d i can sprites positioning on screen coordinates and then there are worldcoordinates for the 3d world.

    Imagine a 3d plane for the tilemap and with the camera movement i can scroll around the tilemap.

    Or i have to calculate the tileposition for each tile every onrender.(and so i need to draw only the visible tiles)

    Here an explantation from sfml.better to understand: https://www.sfml-dev.org/tutorials/2.5/graphics-view.php

    Edit: i found

    Maybe thats what i need.
    Test it if i have time

    #15187

    cocon
    Participant

    I had some need about this a while ago.

    Trying to pan and zoom

    #15188

    Abe _King_
    Participant

    @c0d3r9

    I’m not sure what you’re trying to do anymore, you may need to clarify more specifically the goal and what you are presently using to achieve the goal.

    #15190

    c0d3r9
    Participant

    Haven´t time to code the last days.and its to hot 😉

    In short, imagine you have a tilemap wich is drawn complete and then have a size much bigger like the screen resolution.
    With the “view offset” you can change the position of the rectangular view was shown on screen.
    I.e. a map width 5000px and height 2000px.
    The start view offset is 0, 0 then the view represents  from 0 to screenwidth, 0 to screenheight.
    If you now change this offset i.e. 100px on the x position now you see 100 to screenwidth+100.
    Its like a 2d camera.
    You have a big tilemap(or one big image) and you can move the “cameraview” across this map.

    I hope I could explain it well.
    My link from sfml explain it as best i think.

    #15194

    Gwenel
    Participant

    Think I know what you mean I dont know much but this I know. Heres an example for you I made because I know this is abit tricky in the beginining buts its really easy when you see it in action.

    The codebox is strange but I made the codefor my friend as tutorial. Here it is with proper formatting.

    https://ufile.io/nwy8j

     

    #15195

    Gwenel
    Participant

    You can do extremely big worlds using this no problem. It is about 90 LOC and easy to understand.

    #15198

    c0d3r9
    Participant

    Your upload is 0kb.The file is empty 😉

    I take a look at the codebox later and delete the comments.
    To hot here to read this atm.
    Thanks

    #15202

    Gwenel
    Participant

    Here it is in proper print because you cant read that mess.

    Attachments:
    1. scroll.zip
    #15204

    c0d3r9
    Participant

    Take a short look into it.
    You draw the visible area of the tilemap.Thats the way i know.
    I thought there is a way to draw all and then to scroll with the camera across the complete area.

    #15206

    Gwenel
    Participant

    Clipping via hardware is effective but you are still limited to some kind of size probably 4k or so and you might need to stitch several ones to get the size you want.

    It becomes the same tiling technique but at a ridiculues scale and you still need to handle world coordinates the same way.

    #15207

    c0d3r9
    Participant

    Okay i would use the “draw-only-the-visible-tiles” way that i have.
    It´s not bad and the speed is every time the same because its even the same tilescount wich are visible.

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.