Hi all guys!
I'm making a game in phyton and have done all the hard part of the game. For test i've used canvas.rectangle instead of real image. Now i'm switching these rectangles to images with canvas.blit(image,target=(x,y),mask=testmask).
I have to draw 5 5x5 pixel image and 1 10x10 image. This is into a while loop with a sleep timer at the end. I've inserted the drawing code just after the canvas.clear(), but when i'm running the game it seems that the draw function is too slow and the screen is cleared before it finish to draw my images. i post some part of code:
automask code for images (called once at the beggining of program just after the image loading)
drawing code (executed every cycle)Code:def automask(im): width, height = im.size mask = Image.new(im.size, '1') # black and white tran = im.getpixel((0,0))[0] # transparent top-left for y in range(height): line = im.getpixel([(x, y) for x in range(width)]) for x in range(width): if line[x] == tran: mask.point((x,y), 0) # mask on the point return mask
Am i doing something wrong? is there a way for speed up things? timer is already at the lowest sleep possibile and if i delete it i only obtain a faster game but with the same problem.Code:canvas.clear(0x000000) canvas.rectangle((ostacolox, ostacolo, (ostacolox + 10), (ostacolo + 30)), fill=color) canvas.rectangle((ostacolo2x, ostacolo2, (ostacolo2x + 10), (ostacolo2 + 30)), fill=color) spunti= unicode(int(punti)) slivello= unicode(livello) canvas.text((290,18), spunti ,fill=0xffff00) canvas.text((2,18), "Livello " + slivello, fill=0xffff00) canvas.blit(corpo, target=(x1,y1)) canvas.blit(corpo, target=(x3,y3)) canvas.blit(corpo, target=(x5,y5)) canvas.blit(corpo, target=(x7,y7)) canvas.blit(corpo, target=(x9,y9)) canvas.blit(testa, target=(x11,y11),mask=masktesta)
If you want you can watch my game working with canvas.rectagle here -> http://www.youtube.com/watch?v=OTqyHoNIlOw
Sorry for my bad english! I hope in some reply!!
Thank you
Michele

Reply With Quote



