Hello, I've also tried your code in Win 7 with the following install: cocos2d==0.6.5 - pyglet [required: >=1.2, installed: 1.2.4] - six [required: >=1.4, installed: 1.11.0]
It works correctly. Personally I would put the data in a class dedicated for this Sprite. The Action would only manipulate the data from the class to change the facing. Here is my take on it. # # cocos2d # http://python.cocos2d.org # # a simple cocos2d app for changing a sprite's image on keyboard input # by pressing tye "c" key import cocos import pyglet from pyglet.window import key class Man(cocos.sprite.Sprite): def __init__(self, *args, **kwargs): self.images = {"left": pyglet.resource.image("hombreiz.png"), "right": pyglet.resource.image("hombreder.png") } self.side = "left" super().__init__(self.images[self.side], *args, **kwargs) class SwapFacing(cocos.actions.InstantAction): def start(self): target = self.target target.side = "left" if target.side == "right" else "right" target.image = target.images[target.side] class HelloWorld(cocos.layer.ColorLayer): is_event_handler = True def __init__(self): super(HelloWorld, self).__init__(255, 255, 250, 255) sprite = Man() sprite.position = 320, 240 sprite.scale = 1 self.add(sprite, name="man", z=1) def on_key_release(self, symbol, modifiers): if symbol == key.C: man = self.get("man") man.do(SwapFacing()) else: print("Press 'C' to change side") if __name__ == "__main__": cocos.director.director.init() hello_layer = HelloWorld() main_scene = cocos.scene.Scene(hello_layer) cocos.director.director.run(main_scene) On Thu, Oct 19, 2017 at 4:25 AM, claudio canepa <[email protected]> wrote: > addendum: using pyglet dev from their repo, branch default > > > On Wed, Oct 18, 2017 at 11:23 PM, claudio canepa <[email protected]> > wrote: > >> The script 'as is' seems to work ok here, with win7 and ati radeon video >> hardware, meaning pressing 'C' switches the sprite image between two poses, >> both displaying normal. >> >> I'm missing something ? >> >> >> >> On Wed, Oct 18, 2017 at 7:44 PM, Alan Etkin <[email protected]> wrote: >> >>> Hi >>> >>> Loading media with pyglet.resource... at the main scope of my cocos >>> script (simple hello world example with keyboard event) does weird stuff in >>> Windows: if you call the command twice for different media, just the first >>> is "visible" on screen, no error thrown. The media object looks ok (same >>> values as the one that is actually working), but it does not show on >>> screen. I don't get it :P. I've solved the issue by calling the resource >>> commands on node init method. Then everything is fine. Just wondering what >>> would be the cause of the odd behavior. I attach a code example (the one >>> that failed). >>> >>> Regards >>> >>> -- >>> 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. >>> >> >> > -- > 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. > -- 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.
