How can I mirror a sprite?

edited September 2014 in Library Questions

Hi there, So I'm just getting started with Processing and I'm using the Sprite library which is very handy. I'm missing a way to simply mirror my sprites, though. Is there an easy way to do it or do I have to make separate files/images for every mirrored version? Cheers, Matt

Tagged:

Answers

  • edited September 2014

    I have no idea how the sprite library you're talking about is doing the drawing, as you've not posted any example code. I'd assume there'd be a way to flip them built into the library. If you're drawing images, you can mirror one like so:

    pushMatrix();
    translate(x+sprite.width,y);
    scale(-1,1);
    image(sprite, 0, 0);
    popMatrix();
    
  • The Sprite library does not have an easy or even a hard way to mirror the sprites since it is usual for the developer to create a sprite sheet with all the possible frames for each sprite.

    It would be possible to create a separate sketch to load, mirror and save the images for you.

  • "since it is usual for the developer to create a sprite sheet with all the possible frames for each sprite"
    Still, mirroring a sprite is a cheap and accurate way to invert a movement (eg. a character running to left, then to right).
    Having 90° rotation is a good idea too (unlike other rotations that can lead to a blurred sprite).

  • @PhiLho

    Having 90° rotation is a good idea too ...

    The library already supports rotation of sprites (any angle not just 90º) and this does not involve rotating the image data, so no blurred sprite :)

    Still, mirroring a sprite is a cheap and accurate way to invert a movement

    Possibly but this library caches image data to prevent multiple copies being stored in RAM. It means that separate sprites may share image data and inverting the image data for one sprite would automatically do the same for the others.

    It might be possible to use the scale(-1,1); suggested by @TfGuy44 I will have to try this out when I get a chance.

  • yeah, unfortunately I didn't get the scale method to work, cause the sprite class only has a scale(x) function so I can only scale by 1 factor. Thanks anyways! maybe it's not the best thing to use the sprite library after all...

  • It would be easy enough to create a sketch that created mirror images of your graphics. The scale factor in the Sprites library works on the whole sprite so as to maintain the aspect ratio.

    As I said before it is usual for the developer to create sprite sheets that include ALL the frames of the sprite. The Sprite library provides many powerful features for working with sprites but if all you want to do is mirror some graphics then this is not the library for you.

Sign In or Register to comment.