On 14 July 2011 21:40, Zombie Mariachis <[email protected]> wrote:

> The code below is giving me the following error.  It's just a static
> sprite that I scroll an image across. It works fine when drawn by
> itself, but when I include it in a batch the 'wrong type' error pops
> up.  Any ideas?
>
> File "C:\Python26\lib\site-packages\pyglet\sprite.py", line 143, in
> set_state
>    glBlendFunc(self.blend_src, self.blend_dest)
> ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: wrong
> type
>
>
> #####My code:######
>
> asteroid_belt_batch = pyglet.graphics.Batch()
>
> class Level_1(pyglet.sprite.Sprite):
>    def __init__(self, img, x, y, batch):
>        super(Level_1, self).__init__(img, x, y, batch)
>        self.x = 0
>        self.y = Window_Height / 2
>        self.img = img
>        self.gx = x
>        self.gy = y
>        self.batch = batch
>
>    def update(self, dt):
>        self.dx = 40 / (space_quotient * 5)
>        self.x -= self.dx * dt
>
>    def draw(self):
>        glMatrixMode(GL_TEXTURE)
>        glPushMatrix()
>        glTranslatef(self.x, self.y, -100.0)
>        self.img.blit(self.gx, self.gy, 0)
>        glPopMatrix()
>        glMatrixMode(GL_MODELVIEW)
>
> asteroid_level_1_texture =
> pyglet.resource.image('small_asteroids.png')
> asteroid_level_1 = Level_1(asteroid_level_1_texture, batch =
> asteroid_belt_batch, x = 0, y = (Window_Height / 2) - 256)
>
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.
>
>
It's getting a wrong type for argument 1. From what I can tell, this means
that when you're initialising the base Sprite, it's getting something else
for the blend function. Looking at the code, I suggest changing the super
call to this:

  super(Level_1, self).__init__(img, x=x, y=y, batch=batch)

I'm not sure if that will error and I can't test now (it shouldn't). If it
does, do this:

  super(Level_1, self).__init__(img, x, y, GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA, batch)

after importing * or the two GL_ things from pyglet.gl.

The reason is that YOUR sprite class has the order of __init__ variables
(img, x, y, batch), but if you look at a normal sprite, it goes (img, x, y,
blend_src, blend_dest, batch, ...). So you have to always remember to
compensate for that in your code.

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to