Hey there,

I've spent way too much time trying to fix this issue, but I'm getting
nowhere.

I am flipping my sprites on the X axis using get_transform
(flip_x=True). This works fine, even when I flip animations, BUT it's
not working properly when I use it for multiple sprites that use the
same set of images. If I flip one sprite, all the other sprites also
flip even though I didn't tell them. If I understand Python's builtin
id() function correctly, it's using the same copies of the images for
both sprites, which would make sense. However, using copy.copy() to
make new copies of each image doesn't help, and copy.deepcopy() throws
an exception.

I figure this is a pretty elementary thing for someone making a
platformer or any other sort of game that requires sprite-independent
texture flipping.

Here's the code that initially creates the image frames and animations
(facing = -1 means 'facing left', facing = 1 means 'facing right'. The
images are drawn facing right):

    def generate_anims(_):
        if _.facing == 1:
            flip = False
        elif _.facing == -1:
            flip = True

        for stance in ('hi','mid','lo'):
            pattern = '%s_Idle_%s.png'
            _.frames[pattern % (stance, '1')] = pyglet.resource.image
(pattern % (stance, '1'), flip_x=flip)
            _.frames[pattern % (stance, '2')] = pyglet.resource.image
(pattern % (stance, '2'), flip_x=flip)
            pattern = '%s_BlockIdle_%s.png'
            _.frames[pattern % (stance, '1')] = pyglet.resource.image
(pattern % (stance, '1'), flip_x=flip)

etc....
            pattern = '%s_Attack_%s.png'
            attack_images = [pyglet.resource.image(pattern % (stance,
i), flip_x=flip) for i in ('1','2','3')]
            attack_images.append(pyglet.resource.image
('%s_Inter_1.png' % stance, flip_x=flip))
            _.animations['%s_Attack_light' % stance] =
pyglet.image.Animation.from_image_sequence(attack_images,
                    _.attacks['light']['duration']/(len(attack_images)
+2),
                    loop=False)

etc....


and here's the code that flips them when I want to change the facing
of the sprite:
    def setFacing(_, newfacing):
        if newfacing != _.facing:
            _.facing = newfacing

            if _.facing == 1:
                flip = True
            elif _.facing == -1:
                flip = False

            #_.generate_anims()
            for key, img in _.frames.items():
                _.frames[key] = img.get_texture().get_transform
(flip_x=flip)

            for key, anim in _.animations.items():
                _.animations[key] = anim.get_transform(flip_x=flip)

            # start off with a correctly-transformed version of the
normal idle stance
            _.sprite.image = _.frames['%s_Idle_%s.png' % (_.stance,
_.breath_stage)]


Sorry if the code is hard to read, any help is appreciated!

--~--~---------~--~----~------------~-------~--~----~
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