#!/usr/bin/python
import pi3d
DISPLAY = pi3d.Display.create(background=(1.0, 1.0, 1.0, 1.0),
w=800, h=480,
frames_per_second=30, tk=False)
shader = pi3d.Shader("uv_flat")
CAMERA = pi3d.Camera(is_3d=False)
mykeys = pi3d.Keyboard()
img = pi3d.Texture("textures/zero.png", mipmap=False, i_format=pi3d.GL_RGBA, filter=pi3d.GL_NEAREST)
ww = 32
hh = 32
verts = ((-ww, hh, 0.0), (ww, hh, 0.0), (ww, -hh, 0.0), (-ww, -hh, 0.0),
(-ww, hh+64, 0.0), (ww, hh+64, 0.0), (ww, -hh+64, 0.0), (-ww, -hh+64, 0.0))
norms = ((0, 0, -1), (0, 0, -1), (0, 0, -1), (0, 0, -1),
(0, 0, -1), (0, 0, -1), (0, 0, -1), (0, 0, -1))
texcoords = ((0.0, 0.0), (0.5, 0.0), (0.5, 1.0), (0.0 , 1.0),
(0.0, 0.0), (0.5, 0.0), (0.5, 1.0), (0.0 , 1.0))
inds = ((3, 0, 1), (1, 2, 3),
(3, 0, 1), (1, 2, 3))
sprites = pi3d.Shape(CAMERA, None, "points", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
1.0, 1.0, 1.0, 0.0, 0.0, 0.0)
sprites.buf = [pi3d.Buffer(sprites, verts, texcoords, inds, norms)]
sprites.set_draw_details(shader, [img])
while DISPLAY.loop_running():
sprites.draw()
if mykeys.read() == 27:
mykeys.close()
DISPLAY.destroy()
break
texcoords = ((0.0, 0.5), (1.0, 0.5), (01.0, 1.0), (0.0, 1.0), (0.0, 0.0), (1.0, 0.0), (1.0, 0.5), (0.0 , 0.5))#texcoords = ((0.0, 0.0), (1.0, 0.0), (1.0, 0.5), (0.0 , 0.5),# (0.0, 0.5), (1.0, 0.5), (01.0, 1.0), (0.0, 1.0))#texcoords = ((1.0, 0.0), (1.0, 0.5), (0.0 , 0.5),(0.0, 0.0), # (0.0, 1.0), (0.0, 0.5), (1.0, 0.5), (01.0, 1.0))#mess around with different orientations and relfections.
inds = ((3, 0, 1), (1, 2, 3), (7, 4, 5), (5, 6, 7)) # you need to define the 2nd and 3rd triangles to use the top 8 verts
uv_light seems to do the job. But I'm sure to be stuck somewhere sometimes, it was so hard the last time… :)
Yes json is a little bit simpler, but pytmx seems to be rather good (nevertheless requires another dependency…). Here is my first step :
#!/usr/bin/python
import pi3d
import raspigame
import pygame
from pygame import *
DISPLAY = pi3d.Display.create(background=(1.0, 1.0, 1.0, 1.0),
w=800, h=480,
frames_per_second=60, tk=False, use_pygame=True)
shader = pi3d.Shader("uv_flat")
CAMERA = pi3d.Camera(is_3d=False)
img = pi3d.Texture("textures/sheet.png", mipmap=False, i_format=pi3d.GL_RGBA, filter=pi3d.GL_NEAREST)
sheet = raspigame.Spritesheet('textures/sheet.json')
sbuffer = raspigame.SpriteBuffer()
for x,sprite in enumerate(sheet.sprites):
offset = 32 * x
sbuffer.add_sprite(-16+offset,16, sheet.sprites[sprite])
sprites = pi3d.Shape(CAMERA, None, "points", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
1.0, 1.0, 1.0, 0.0, 0.0, 0.0)
sprites.buf = [pi3d.Buffer(sprites, sbuffer.verts, sbuffer.texcoords, sbuffer.inds, sbuffer.norms)]
sprites.set_draw_details(shader, [img])
x = 0
y = 0
move_x = 0
move_y = 0
move = 4
LEFT = RIGHT = UP = DOWN = False
while DISPLAY.loop_running():
for e in pygame.event.get():
if e.type == QUIT: raise SystemExit, "QUIT"
if e.type == KEYDOWN and e.key == K_ESCAPE:
DISPLAY.destroy()
raise SystemExit, "QUIT"
if e.type == KEYDOWN and e.key == K_LEFT:
LEFT = True
if e.type == KEYDOWN and e.key == K_RIGHT:
RIGHT = True
if e.type == KEYDOWN and e.key == K_UP:
UP = True
if e.type == KEYDOWN and e.key == K_DOWN:
DOWN = True
if e.type == KEYUP and e.key == K_LEFT:
LEFT = False
if e.type == KEYUP and e.key == K_RIGHT:
RIGHT = False
if e.type == KEYUP and e.key == K_UP:
UP = False
if e.type == KEYUP and e.key == K_DOWN:
DOWN = False
if LEFT and not RIGHT: move_x = -move
if RIGHT and not LEFT: move_x = move
if not LEFT and not RIGHT: move_x = 0
if UP and not DOWN: move_y = 4
if DOWN and not UP: move_y = -4
if not UP and not DOWN: move_y = 0
x += move_x
y += move_y
sprites.position(x, y, 0.0)
sprites.draw()
verts[offset:offset+4,0:2] = verts_initial_xy[offset:offset+4,:] + [x, y]
#setting a flag in sprites True so that in sprites
..
def draw(self):
if self.redraw_flag:
self.buf[0].re_init()
self.draw()self.buf[0].array_buffer[offset:offset+4,0:2] = verts_initial_xy[offset:offset+4,:] + [x, y] if PLATFORM == PLATFORM_ANDROID:
self.surface = openegl.eglGetCurrentSu
...
elif PLATFORM == PLATFORM_PI:
self.dispman_display = bcm.vc_dispmanx_display_open(0) #LCD setting
...
elif pi3d.USE_PYGAME: # does't get here on the Raspberry Pi
import pygame
flags = pygame.OPENGLimport pygame
pygame.init()No it's Tiled, THE opensource map editor. My goal is to re-use the most useful software for each part of the job.
Strangely, moving sprites is really smooth on the Pi but really laggy on a i7 under Linux.
Really looking forward to seeing it. What app is running in the screen shot; is that your engine?
--
You received this message because you are subscribed to a topic in the Google Groups "pi3d" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pi3d/zHdPO_VYj7k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pi3d+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.