13

Is there a way to make a temporary "image" with Pyglet? (Something akin to LÖVE's Canvas).

Basically, I want to have an object that I could blit stuff like sprites and text to, and then blit this temporary image to the window.

I tried creating an image with pyglet.image.create(), but apparently it procures an ImageData which you can't blit to.

Thank you very much for your attention.

art-solopov
  • 4,289
  • 3
  • 25
  • 44

1 Answers1

1

Checkout AbstractImage. It has all the methods I think you want - creating an image offline, blitting stuff to it:

myimage.blit_into('sprite1',x,y,z)
myimage.blit_into('sprite2',x+20,y,z)

and then blitting it to the active frame:

myimage.blit(x,y[,z])

etc.

kabanus
  • 24,623
  • 6
  • 41
  • 74
  • `pyglet.image.ImageException: Cannot blit images onto .` – art-solopov Aug 31 '17 at 09:21
  • I'll need more info. Also, did you read the docs? are you constructing the proper abstract image? it has a few sub-classes (Texture etc) – kabanus Aug 31 '17 at 20:36
  • I have. I've linked to the documentation in my question. I've also skimmed the source code. The `AbstractImage` thing is complicated. It has the `blit_into` method but by default it throws an error. – art-solopov Aug 31 '17 at 21:55
  • I've tried using `Texture` before, and you can blit `ImageData` into it, but I can't find how to blit the text. – art-solopov Aug 31 '17 at 21:56
  • I checked the source code, the base class doesn't have the method implemented (thus the exception). I'll give it another go later today -but the answer maybe you need an outside library. – kabanus Sep 01 '17 at 08:06
  • @art-solopov How are you blitting the text? Are you using `text.Label`? – kabanus Sep 01 '17 at 11:26
  • Yeah, with `text.Label`. – art-solopov Sep 01 '17 at 13:47
  • @art-solopov Sorry it took a while - the `pyglet` code is still a bit incomplete. I don't see any easy way to get text working yet with pylget except creating an image with the text yourself and blitting that (you can post on github if you want the author's to work on it), though I didn't check the latest code. Otherwise you can try switching frameworks if you don't want to deal with this (pygame, which are the guys working on pyglet maybe?). – kabanus Sep 11 '17 at 07:04
  • TBH I probably will switch frameworks. Either go with PyGame or try to look into an HTML5/ES6+ framework. Thank you for your answer regardless!.. – art-solopov Sep 11 '17 at 08:21
  • Yup, glad to help (as much as I could anyway) – kabanus Sep 11 '17 at 09:49