Hello, I'm creating an amazing RPG with pyglet. It's a top-down, tile-
based ordeal. I'm only really just starting it, but what I have so far
is located at https://code.launchpad.net/~james-gangur/+junk/jagolyrpg
I'm completely new to both pyglet and OpenGL, so that code is probably
pretty bad, so if there are any simple things that I've done wrong,
please do tell me.
But anyway, what I'm wondering is what would be the easiest way to
create a "HUD"? What I mean is how do I position a second viewport
over the top of my primary one? I'm using a viewport to scroll over
the map which is much bigger than the window. At the moment, my
relevent code looks like this:
#!/usr/bin/python
import pyglet
from pyglet.gl import *
from miscclasses import *
from fileloads import *
from playerclass import PlayerObject
VIEWPORT_WIDTH = 512
VIEWPORT_HEIGHT = 512
key = pyglet.window.key
keyboard = key.KeyStateHandler()
def updatetick(dt):
if player.animation[0] == True:
player.animate("move")
if keyboard[key.UP] and window.keypriority[0] == key.UP:
player._move(0, keyboard[key.SPACE])
elif keyboard[key.DOWN] and window.keypriority[0] == key.DOWN:
player._move(1, keyboard[key.SPACE])
elif keyboard[key.LEFT] and window.keypriority[0] == key.LEFT:
player._move(2, keyboard[key.SPACE])
elif keyboard[key.RIGHT] and window.keypriority[0] == key.RIGHT:
player._move(3, keyboard[key.SPACE])
player = PlayerObject(pyglet.sprite.Sprite(playerup_image), 32, 0, 0)
class MyWindow(pyglet.window.Window):
def __init__(self):
pyglet.window.Window.__init__(self, width=512, height=512)
self.push_handlers(keyboard)
self.viewportx = 0
self.viewporty = 0
self.keypriority = [key.UP, key.DOWN, key.LEFT, key.RIGHT]
def scroll(self):
glViewport(0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT)
glMatrixMode(gl.GL_PROJECTION)
glLoadIdentity();
glOrtho(self.viewportx, self.viewportx+VIEWPORT_WIDTH,
self.viewporty, self.viewporty+VIEWPORT_HEIGHT, -1, 1)
glMatrixMode(gl.GL_MODELVIEW)
def keypriorityupdate(self, pressed, symbol):
if pressed == True:
self.keypriority.remove(symbol)
self.keypriority.insert(0, symbol)
else:
self.keypriority.remove(symbol)
self.keypriority.append(symbol)
window = MyWindow()
window.set_vsync(True)
window.push_handlers(keyboard)
@window.event
def on_key_press(symbol, modifiers):
if symbol == key.UP or symbol == key.DOWN or symbol == key.LEFT or
symbol == key.RIGHT:
window.keypriorityupdate(True, symbol)
@window.event
def on_key_release(symbol, modifiers):
if symbol == key.UP or symbol == key.DOWN or symbol == key.LEFT or
symbol == key.RIGHT:
window.keypriorityupdate(False, symbol)
@window.event
def on_draw():
window.clear()
#print "player:", 'x:', player.sprite.x, 'y:', player.sprite.y
#print "viewport:", 'x:', window.viewportx, 'y:', window.viewporty
window.viewportx = player.sprite.x - (VIEWPORT_WIDTH / 2 -
(player.size/2))
window.viewporty = player.sprite.y - (VIEWPORT_HEIGHT / 2 -
(player.size/2))
window.scroll()
background_sprite.draw()
player.sprite.draw()
batch_tile_objects.draw()
pyglet.clock.schedule_interval(updatetick, 1/60.0)
pyglet.app.run()
The GL stuff is in MyWindow.scroll()
How would I go about creating a second area that I can put stuff that
does not scroll with everything else?
- Jagoly
--
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 http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.