Log In  

Here's a proof-of-concept for a zoomable camera:

Features

  • Multiple cameras
  • Set target coordinates, drawn at the camera center
  • Set zoom factor, for drawing scaled map and sprites

Functionality

  • camera.get_center()
  • camera.set_target(x, y)
  • camera.get_target()
  • camera.start_draw()
  • camera.draw_map(tx, ty, tw, th, x, y)
  • camera.draw_spr(s, x, y)
  • camera.draw_sspr(sx, sy, sw, sh, x, y)
  • camera.end_draw()

Relies on this smap function. Code is below or via GitHub.

Cart #zoomable_camera-1 | 2024-04-09 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
8

P#145973 2024-04-07 12:26 ( Edited 2024-04-09 16:12)

cool, i have been looking for something like this for a whie. But i have a few questions.

  • does it work with sprites
  • does it work with the map
  • the demo you showed if you
    zoon out too much the circle
    inverts and it starts getting
    bigger. could you fix it with
    radius=max(0,radius)

i like it :)

P#145985 2024-04-07 16:30 ( Edited 2024-04-07 16:31)
1

Hey, glad you like the code. In answer to your questions:

  • It works with custom 'sprite' objects, which are just containers for the data needed to call 'sspr'. You could always add separate camera.draw_spr and camera.draw_sspr functions that use different data.
  • Yes, it works with the map. You just need to edit the width and height of the map in the map function.
  • You're right, I didn't add any error checking. Your suggested code is a great idea, thanks.
P#146034 2024-04-08 08:33

Thanks :)

P#146051 2024-04-08 13:25
1

@cheesemug i've updated the camera code to cope with drawing sprites using spr and sspr functionality (see list in my original post). I've also removed my own sprite object code, as I like the idea of the camera integrating with existing functions as much as possible.

Thanks!

P#146173 2024-04-09 16:15

[Please log in to post a comment]