Hey guys,
I thought I'd share this snippet here:
https://bitbucket.org/snippets/treehousegames/g6Xdg
Most of the code is from the fixed resolution viewport that is in the
pyglet example code, but I've tweaked it a bit such as turning it into a
context manager, and implementing a simple 2D camera. The camera in
particular seems to be a challenge for beginners, so maybe this could help
someone.
It's used like this:
# make an instance of the viewport:
viewport = FixedResolutionViewport(target_window, resolution)
# to use it without involving a camera, simply do:
with viewport:
window.clear()
batch.draw()
# If you want to use the camera, it must be specifically set before drawing:
with viewport:
window.clear()
viewport.set_camera(300, 0)
batch.draw()
# If you want to display a static HUD on top of your scrolling scene, you
can reset the view and draw a second batch:
with viewport:
window.clear()
viewport.set_camera(300, 0)
main_batch.draw()
viewport.reset_camera()
hud_batch.draw()
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.