Inkscape.org
Beyond the Basics I'm duplicating something with a clip path, but I'm not sure I'm doing it right
  1. #1
    Espyo Espyo @Espyo

    The idea

    So I'm making a spritesheet. For the sake of this example, it's a little guy with a simple circular head and a wobbly tail. I want the tail to flop around on each frame, so my idea is to grab the first sprite, duplicate it to make a new sprite, and shape the tail and its components accordingly. I've attached an example SVG with what I mean.

    The head is nothing special but the tail has some large markings around it and a complex blurry shine effect. Meaning that in order for this stuff to not leak out of the tail, I grouped it all and set a clip path with the shape of the tail.

    The problem

    There are two ways to do this that I can think of, but the problem is that both ways have problems when I try to duplicate the first sprite! The example SVG contains both of my approaches.

    • Top approach:
      • Method: The tail shape object proper and the marking+shine objects are grouped, and then a clone of the tail shape object is used as the clip path.
      • Problem: When I duplicate the sprite and try to edit the new sprite's tail shape object, the clip path remains the same. If I edit sprite 1's tail, sprite 2's clip path changes.
      • "Solution": Remove the clip path from the new sprite's tail, remove the stale clone, clone the shape tail object of the new sprite, move that clone out of the group, and finally re-clip the group with the new clone.
    • Bottom approach:
      • Method: The tail's color is one large rectangle object. It and the marking+shine objects are grouped. Finally, a tail shape object is used as the clip path.
      • Problem: When I duplicate the sprite and try to edit the clip path (the show clipping path option of the node tool must be on), both this sprite and the first sprite's clip path for the tail get changed.
      • "Solution": Remove the clip path from the new sprite's tail, then re-apply it.

    As you can see, both ways are problematic. Even the workaround "solutions" I found for each of them are a pain! The second method's solution is at least pretty simple, but if I forget to do it I'll be editing a previous sprite without my knowledge (something I learned the hard way...)

    Thoughts

    Now, it looks like I'm either not doing this properly, or the program is misbehaving in both cases...

    • In the top approach the clone within the duplicated sprite should be pointing to the new tail shape object, not the old one from the first sprite. I have confirmed that Preferences > Behavior > Clones > Duplicating original+clones/linked offset > Relink duplicated clones is on.
    • In the bottom approach the duplicated tail's clip path still internally points to the first sprite's, but since when I choose to remove the clip path a new tail shape object is created, it looks like Inkscape was meant to understand it's a different clip object but doesn't.

    What do you think? Is there an easier way to achieve what I want to do? Am I doing this right and Inkscape just has two glitches? Did I forget something else in the settings?

  2. #2
    David248 David248 @David248
    *

    Perhpas use a clipgroup instead of clipping a group (sounds the same... but different) : in a clip group the path(s) used to clip are put in a subgroup named Clip where they are easy to modifiy.

    So, I modified the svg : (I kept the version with a green background : more relevant to me, imho). You first need to open objects panel to clearly see what's going on.

    • released the clip on the tail : the clipping path (path 35) reappears just atop.
    • used the cliping path to set a clip group (right clic > set clip group). Inkscape created a clip group, I renamed Tail, and inkscape put in this group the clipping path in a subgroup named Clip.
    • I moved the parts of the tail in the Tail group (not in the Clip subgroup).
    • To modify the clip, you just have to select the path in the Clip subgroup.

    I group all (head and tail) and renamed the group Sprite#1 and duplicated it and rename this duplicate Sprite#2, so you can make experiments. Both sprites are stacked atop one another : hide Sprite#1 when working on Sprite#2. It might be smarter to use one Layer for each sprite.

    BUT : as far as I now, Clip Group is an inkscape-specific thing. My browser doesn't displays correctly the tail on the embeded-into-html svg below.

  3. #3
    Espyo Espyo @Espyo

    Ah, I see what you mean, thanks! I never tried Clip Group before, but I understood your explanation. I can also confirm that it doesn't work on my browser or file manager's preview, but works in Inkscape.

    However, it looks like this has the same problem... if you try duplicating the sprite and then editing the clip path (by selecting new sprite > Tail > Clip > pathXX in the objects list), it still won't get updated. And again, changing the first sprite's clip path will update both sprites.

    Your example also has this issue. If I edit Sprite #2's group clip path it updates both sprites. If I edit Sprite #1's group clip nothing happens.

    Is this maybe just an issue on my end? If it helps I'm duplicating by selecting a sprite and then hitting Ctrl+D. I forgot to add my specs to the OP but I'll do them now:

    • OS: Lubuntu 22.04.4
    • Inkscape version: 1.3.2
  4. #4
    David248 David248 @David248

    My mistake, you're right !

    I didn't expect it: I remodelled the svg to make it clearer (reversed the Sprite#1 and Sprite#2 names to match their order of creation, renamed Tail groups in Tail#1 and Tail#2 and cleaned up the defs to remove what wasn't being used). In an attempt to understand, by opening the xml editor, we see that sprite#1's Tail#1 ClipGroup refers in the defs to a ClipPath4, which is a clone of g3 (the Clip subgroup of Tail#1 ).
    But by duplicating Sprite#1, we keep for the duplicate (Sprite#2) the same reference to clipPath4, hence to g3, and not g35 (the ClipSubgroup of Tail#2, the ClipGroup of Sprite#2 : I didn't expect this.

    On second thought, the logic is if you duplicate one clone and its original, the duplicated clone refers to the original and not the duplicate of the original. Furthermore, if  one duplicates a clipped group, the clippath stays also the same (try and see in defs).

    So, ClipGroup isn't a solution, I'm sorry,  the way I would do for you is to draw a first sprite with a group for GreenBG, OrangeStripes and Shine, place atop the path that will be used to clip this group (the old good manner, that displays on browser), duplicate all, then work on the path and set a clip after for each sprite. Faster and simplier.

    Mre
  5. #5
    Espyo Espyo @Espyo

    I see. I think that if the user has the Preferences > Behavior > Clones > Duplicating original+clones/linked offset > Relink duplicated clones option enabled that this shouldn't happen, so is it a bug?

    In the meantime I'll just draw each clip path one by one. Thanks for the help!

  6. #6
    David248 David248 @David248

    The relink duplicates clones works.

    To me, theses issues have more to do with Duplicating and relinking to an own ClipPaths when Duplicating Clipped paths / groups and ClipGroups. I did'nt see such option in inkscapes preferences : it's not a bug, but perhaps a misbehavior. An option in preferences might be useful.

Inkscape Inkscape.org Inkscape Forum Beyond the Basics I'm duplicating something with a clip path, but I'm not sure I'm doing it right