# PureBasic Forum

 It is currently Thu Aug 13, 2020 6:53 pm

 All times are UTC + 1 hour

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Drawing tilemap with zoomPosted: Sun Nov 11, 2018 4:47 pm
 Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 587
Hi,

To draw a tilemap, I calculate which tiles to draw like this:
Code:
x1 = scroll_pos\x / 32
y1 = scroll_pos\y / 32
x2 = ScreenHeight() / 32
y2 = ScreenWidth() / 32
If x1 > tiles_x
x1 = tiles_x
EndIf
If y1 > tiles_y
y1 = tiles_y
EndIf
For y = y1 To (y2 + y1)
For x = x1 To (x2 + x1)
; draw...
Next
Next

How can I incorporate zooming into this? I'm struggling to understand what I need to multiply by the zoom value.

Top

 Post subject: Re: Drawing tilemap with zoomPosted: Mon Nov 12, 2018 12:39 am

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3736
Location: Utah, USA
wombats wrote:
How can I incorporate zooming into this? I'm struggling to understand what I need to multiply by the zoom value.
Code:
tile_size = 32

zoom_amount = 1 ;za = 1 for normal size, za > 1 to zoom in, 0 > za > 1 to zoom out
screen_tile_size = tile_size * zoom_amount ;zoomed tile size on screen

x1 = scroll_pos\x / screen_tile_size
y1 = scroll_pos\y / screen_tile_size
x2 = ScreenHeight() / screen_tile_size
y2 = ScreenWidth() / screen_tile_size
If x1 > tiles_x
x1 = tiles_x
EndIf
If y1 > tiles_y
y1 = tiles_y
EndIf
For y = y1 To (y2 + y1)
For x = x1 To (x2 + x1)
; draw...
Next
Next

This should adjust for the tile size and can be considered 'simple zooming'. When zooming in things will 'grow' towards the bottom-right of the screen.

'Complex zooming' would require a bit more effort to calculate the position of the visible tiles and would allow zooming in/out of a particular point on the screen such as the center of the screen or the position of the mouse pointer and would cause things to 'grow' outward from or inward to the point of zoom.

_________________

Top

 Post subject: Re: Drawing tilemap with zoomPosted: Mon Nov 12, 2018 10:59 am
 Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 587

I think I need more 'complex' zooming. I already calculate the tiles that should display based on the scroll position, so it works at zoom level 1, but not at 0.5, 2.0, etc. Wherever I put the zoom value, it just causes problems like tiles being cut off.

Top

 Post subject: Re: Drawing tilemap with zoomPosted: Mon Nov 12, 2018 2:22 pm

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3736
Location: Utah, USA
Are you using sprites to display your tiles or drawing images?

_________________

Top

 Post subject: Re: Drawing tilemap with zoomPosted: Mon Nov 12, 2018 2:29 pm
 Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 587
I am drawing images. I subtract the current scroll position from their grid position.

Top

 Post subject: Re: Drawing tilemap with zoomPosted: Mon Nov 12, 2018 3:42 pm

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1246
Location: right here
You need to scale the position as well as the size of tiles, i guess that's what you are already doing. If you have gaps, it might be because you are using integer division when applying the scaling. Make sure you have some floating point variables in your division or in the relevant context like variables that are being assigned to.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 6 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 10 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - IDE    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite