Although this is what I was looking for, how do I go about changing the
__init__ and animate methods to manipulate a sprite animation?
I have tried to call another function so that the sprite updates (see
below) but it fails to switch between GIFs.
import pyglet
from cocos import scene
from cocos.layer import Layer
from cocos.director import director
from cocos.sprite import Sprite
class TestLayer(Layer):
is_event_handler = True
def __init__(self):
super(TestLayer, self).__init__()
x, y = director.get_window_size()
self.sprite = Sprite(pyglet.image.load_animation('example1.gif'))
self.sprite.position = x//2, y//2
self.add(self.sprite)
def run_movement(self, flag=True):
if flag:
self.sprite = Sprite(pyglet.image.load_animation('example2.gif'))
else:
self.sprite = Sprite(pyglet.image.load_animation('example1.gif'))
def on_key_press(self, key):
if key == pyglet.window.key.SPACE:
self.run_movement(True)
def on_key_release(self, key):
if key == pyglet.window.key.SPACE:
self.run_movement(False)
director.init()
director.run(scene.Scene(TestLayer()))
Thank you.
On Tuesday, November 21, 2017 at 3:43:45 AM UTC, Claudio Canepa wrote:
>
> Oh, sorry, I misread as "want to manually set which picture in the gif
> will be shown when pressing a key" while you want multiple gifs, and jump
> to one to the other.
> One possibility it is to join all the gifs in only one gif and proceed as
> before.
>
> Else, for sepparate gifs you should look at the pyglet.sprite.Sprite code,
> in particular to the __init__ and _animate methods and see how to
> manipulate the sprite animation state to switch between gifs.
>
>
> On Tue, Nov 21, 2017 at 12:22 AM, claudio canepa <[email protected]
> <javascript:>> wrote:
>
>> Yes. The sprite.image attribute controls which image will be shown.
>>
>> So the issue would be how to access each picture into the .GIF
>>
>> I modified the cocos' s example test/test_animation.py first to explore
>> the GIF and then to change the picture at each SPACE key release.
>>
>> Attached as test_animation_2.py, put in the test/ directory so the gif
>> can be found.
>>
>>
>>
>>
>>
>> On Mon, Nov 20, 2017 at 6:52 PM, FreshManGaming <[email protected]
>> <javascript:>> wrote:
>>
>>> Hi all,
>>>
>>> I'm trying to change an animated GIF in real time to another animated
>>> GIF, e.g. from an idle state to a running state depending on a key-press.
>>>
>>> So far I have managed to load in the idle animated GIF but I am
>>> struggling to replace the idle GIF to the running GIF,
>>>
>>> I have looked into using Pyglet's Animation class however whenever I use
>>> from_image_sequence
>>> the program just crashes.
>>>
>>> Are there any ways to change a sprite represented by a GIF in real time
>>> with another GIF temporarily depending on a key-press?
>>>
>>> Thank you.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "cocos2d discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected] <javascript:>.
>>> To post to this group, send email to [email protected]
>>> <javascript:>.
>>> Visit this group at https://groups.google.com/group/cocos-discuss.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/d/optout.