Thank you very much for the help, I really appreciate it!

On Thursday, 19 July 2018 07:27:01 UTC+2, Toke Ivø wrote:
>
> So, a couple of things:
> You're on the right track, but there's a bit of work to be done.
>
> I think you want to change your loop into:
>
> f or i in range(len(self.brick_images)):
>             brick_type = randint(0, len(self.brick_images) - 1)
>             image = self.brick_images[brick_type]            
>             ...
>
> No reason to save the loop variables.
>
> Secondly, your problem is this:
>             self.bricks.append(pyglet.sprite.Sprite(self.image, x=x, y=y, 
> batch=self.batch))
> should've been:
>             self.bricks.append(pyglet.sprite.Sprite(pyglet.image.load(self
> .image), x=x, y=y, batch=self.batch))
>
> Now, obviously it's a smart idea to move the "pyglet.image.load" so that 
> you're only loading the images once. (Pyglet actually takes care of that, 
> but no need to make it any harder to read)
>
>
>
>
> On Thu, Jul 19, 2018 at 7:12 AM, Gregory Strydom <gregory.s...@gmail.com 
> <javascript:>> wrote:
>
>> Hello.
>>
>> I am fairly new to the world of pyglet but find it very interesting. 
>> Although, I have now come across a problem which I cannot understand why it 
>> does not work.
>>
>> Some example code:
>>
>>
>> import pyglet
>>
>>
>> from random import randint
>>
>>
>> class GameWindow(pyglet.window.Window):
>>     def __init__(self, *args, **kwargs):
>>         super(GameWindow, self).__init__(*args, **kwargs)
>>
>>
>>         self.batch = pyglet.graphics.Batch()
>>         self.brick_images = ['brick1.png', 'brick2.png']
>>         self.bricks = []
>>
>>
>>         for i in range(len(self.brick_images)):
>>             self.brick_type = randint(0, len(self.brick_images) - 1)
>>             self.image = self.brick_images[self.brick_type]
>>             x = i * 200 + 50
>>             y = i * 100 + 70
>>             self.bricks.append(pyglet.sprite.Sprite(self.image, x=x, y=y, 
>> batch=self.batch))
>>
>>
>>     def on_draw(self):
>>         self.clear()
>>         self.batch.draw()
>>
>>
>>     def update(self, dt):
>>         pass
>>
>>
>>
>>
>> if __name__ == '__main__':
>>     window = GameWindow(800, 600, 'test', resizable=False)
>>     pyglet.clock.schedule_interval(window.update, 1.0 / 60.0)
>>     pyglet.app.run()
>>
>> The traceback error is:
>>
>> Traceback (most recent call last):
>>   File "C:/Users/jyscal/PycharmProjects/simplesim1/testing.py", line 30, 
>> in <module>
>>     window = GameWindow(800, 600, 'test', resizable=False)
>>   File "C:/Users/jyscal/PycharmProjects/simplesim1/testing.py", line 19, 
>> in __init__
>>     self.bricks.append(pyglet.sprite.Sprite(self.image, x=x, y=y, 
>> batch=self.batch))
>>   File "C:\Python27\lib\site-packages\pyglet\sprite.py", line 243, in 
>> __init__
>>     self._texture = img.get_texture()
>> AttributeError: 'str' object has no attribute 'get_texture'
>>
>> I copied most of the code from pyglets documentation example using 1.3
>>
>> Any help would be appreciated and I can provide further info if required.
>>
>> Thank you!! 
>>
>> -- 
>> 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 pyglet-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to pyglet...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/pyglet-users.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to