Search Unity

Destructible 2D ☄️ Dynamic Sprite Destruction

Discussion in 'Assets and Asset Store' started by Darkcoder, May 29, 2014.

  1. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    What kind of scales are you setting it to? If you select the objects in question, do you notice anything strange in the scene view or inspector?

    For example, I notice that if you scale objects too small then Unity likes to randomly delete 2D collider vertices if they are deemed too close together, even if that results in the collider shape drastically changing. To limit this issue you can decrease the 'Detail' setting in the D2dPolygonCollider/D2dEdgeCollider, run 'Optimize Alpha' one or more times to increase the size of each destructible pixel, or increase the scale of your scene objects.
     
  2. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Hi I purchased this and it looks real cool and the demos are great nice job.

    I have question.

    The car demo has the "Player Car" object and a sprite inside it called "Car" along with tyres etc..
    In my own scene I want two objects to damage each other like the car does when they collide.

    I know this is simple.

    So I used the car object as a template and copied "Player Car" over to my scene with "Car" inside it.

    Then I duplicated the "Player Car" so I now have two cars in my scene. I removed the 2d Player Car script as I don't need to drive the cars and added a Gravity Scale of 1 to both cars.

    I then positioned one car on the ground and the other in the air above it and ran the scene.

    The upper car dropped and hit the car below creating damage. Awesome, this is cool and worked great.

    So I then created my own object "MyTest" and put a sprite inside it called "Car" and made that sprite destructible and made every setting and components the same as the car object that I had copied from your demo that now works in mine.

    I made sure my "MyTest" was exactly set up the same as "Player Car" with the properties and components and I made sure my "Car" sprite inside that had add its properties exactly the same as the one that works.

    When I run it my new one from scratch with exactly the same parameters it does not create damage when it hits the other.

    Now if I copy your "Player Car" Object and delete everything inside it, all the sprites. Then I add a new sprite and add 2D Destructible and 2D Polygon Collider and run it it all works great.

    My question is if I create my own "Player Car" type object from scratch with all the same components and settings and put a sprite inside that why doesn't work ?


    I must be missing something obvious as all the parameters and components are exactly the same. The only thing I can think of is is that there is a certain order this needs to be done in and I am not doing that.

    My version is Unity PRO 5.3.4f1

    I am looking forward to using this I am just testing it first in a test scene once I do that I am going to implement it in my game. So my test scene is just ground with a collider and objects with gravity added and creating damage when hitting each other falling from greater height.

    All I want is two objects with gravity that damage each other with "Car Damage" when they hit and if the object gets split in half become two objects like the tree.

    sorta like two trees like you have in the demo but with gravity.

    so I could stack em say like an angry birds structure and drop a wrecking ball on em and they would get damaged and split in half and apply damage to others they hit. I am also going to have the inner sprites like in the fish demo as well.
     
    Last edited: Apr 7, 2016
  3. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Hmm if you create a new scene and load up the car scene and right click on the "Player car" object and select copy and go back to your new scene and paste it twice so you have two cars. Remove the 2d player car script from both "Player car"' objects and give 1 some gravity and drop it on the other boom. It all works.

    Now remove the 2d spawner from both "Player car" objects and put the 2d spawner back on the "Player car" objects it won't work.

    Even if you create an object exactly the same as the "Player car" object from scratch with the car impact the 2d spawner won't work.

    If you delete the car sprite inside the copied "Player car" object from your demo and recreate that with your own it all works.

    What are the steps in simply creating a destructible sprite that has the 2d spawner with the car impact.

    I must be missing something here as far as I can see there is only a couple steps to follow and it should work.
     
    Last edited: Apr 8, 2016
  4. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    I just tried to set the damage textures on another test creating my own egg. I doesn't seem to let you select sprites in a sprite map.

    I tried dragging and dropping the sprite on the texture but it won't work either.
     
  5. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I'm out of town for a few more days so I can't test using the steps you described above. However, which component are you referring to when you say '2d spawner'?

    The car in the car damage scene is basically just a Rigidbody2D with a PolygonCollider2D attached (generated from the D2dPolygonCollider), so it should be able to collide with any other Rigidbody2D that has a 2D collider. Are you sure you didn't mix up the 2D and normal (3D) physics components?
     
  6. Eltayeb

    Eltayeb

    Joined:
    Jan 24, 2014
    Posts:
    20
    I reduce the scale by 0.1 every second.

    I noticed thou that if i changed the scale in the editor it works fine but when i do it through the script this happens
     
  7. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Hi Dark, yeah I am referring to the D2D Spawner component attached to the Player Car in the Car Demo. It is also in the menu Component/Destructible 2D/D2D Spawner.

    The other question is. When selecting textures, like the egg damage texture in the egg damage demo. All damage textures are not allowed to be in sprite sheets is that correct ?
     
  8. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    What if you pause the gameplay to check? D2D doesn't really check the object scale so it's out of my control.


    Oh right, well that spawner component doesn't do much on its own, it's just called by the D2dCollisionHandler when it detects a collision, and spawns an explosion there. If you have the right rigidbody and collider components then the collisions should all work.

    The egg textures can be in any Sprite sheet, you can see how it gets changed in the D2dRequirements component. To make damage textures look good they should be the same size as the original though, else it may appear to shift around.
     
  9. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    What I am saying is the 2D spawner does not work if you create an object from scratch with all the components like you have done in the Car Demo.

    I am also saying that if I load up the Breakable Egg Demo and go to change the textures in D2D Requirements you are not allowed to select sprites in a sprite sheet.
     
  10. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Did you link up the collision events from D2dCollisionHandler to the D2dSpawner? It won't do anything if you don't.

    It's possible I used to wrong Sprite selection dialogue so you can't select assets, but you should still be able to drag and drop them in from wherever. A Sprite is a Sprite after all, atlas or not.
     
  11. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Awesome, you were right, I never expanded the collision events when creating the object with the D2dSpawner. It works fantastic I thought I might be missing something simple there.

    Yeah I still can't drag and drop the sprite from my spritesheet into the Tex field still.

    I just loaded up the Egg demo to try and opened up the first D 2d Requirments where you can see Tex Egg_1 as I can't select sprites from a sprite sheet from the pop up dialog. I tried the drag and drop and it from the assets list and it doesn't drop. It's probably something simple to change, you would know more about that than me. I haven't made anything like that yet in the editor.

    I imagine most people would like the ability too though, my objects have spritesheets for all their damage and other graphics to do with them and I would need it I guess.

    Looking good though a great tool if I can get to use my spritesheets.
     
  12. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    OK I'm back at my PC now. I see the issue is that the egg example calls the D2dDestructible.SetMainTex method, which simply replaces the Texture2D used to render the destructible object. I'll have to write an alternative method that accepts a sprite so that can be used instead. I'll send you an updated build once it's ready.
     
  13. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Awesome thanks.
     
  14. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Do you have a time estimate for that as it is a showstopper for us at this end until we can reference the sprite sheet.
     
  15. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I'll try and get it done by tonight. It's not quite as simple as grabbing the texture from the sprite though, because each sprite can have drastically different dimensions based on trimming, even if they look the same in the editor when swapping between them. If you really can't wait then just split the textures up and call SetMainTex with those.
     
  16. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Thanks dark much appreciated, I'll wait all our sprites are in a sprite sheet.
     
  17. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
    Hi dark where is that outline effect located. I want to do a similar thing.
     
  18. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    It's in the Destructible 2D/Materials/Resources/Destructible 2D folder.
     
  19. CrystalDynamo

    CrystalDynamo

    Joined:
    May 22, 2014
    Posts:
    120
  20. alonsoGarrote

    alonsoGarrote

    Joined:
    Jun 23, 2012
    Posts:
    25
    Hi there, Im interested in this asset,
    Can this be usefull on implementing a multiplayer gunbound style game?,
    I need a destructible enviroment with diferent types of "slices" and collider updates accordingly, I think.
     
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    There is no multiplayer functionality built in, but synchronising the destruction for a gunbound style game should be fairly simple if you just pass the same destruction coordinates to each client. If you need more advanced functionality like fracturing/slicing/etc, then it will be much more complex though. In the worst case scenario you can just read/write the whole destruction state of an object using the D2dSnapshot class.
     
  22. Minneor

    Minneor

    Joined:
    Nov 5, 2012
    Posts:
    3
    Hi, I have a question. Is it possible to swap the Main Sprite in Runtime. When yes, how can I do this. I tried to use the "ReplaceWith(Sprite sprite)" method, but it doesn´t worked. i tried to use the .Maintex variable, but it need a Texture 2D. I tried to get the 2d Texture from a Sprite and to apply this, but I get an Error: UnityException: Texture 'Sprites' is not readable, the texture memory can not be accessed from scripts. So nothing worked.

    PS: I think, I got it working now. The Spritesheet has to be an Advanced Texture with Read/Write Permission on ( Multiple Sprite of course). Then I can swap the sprites with "ReplaceWith".
     
    Last edited: Apr 27, 2016
  23. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Ah yes, for runtime you will have to manually mark textures as readable. If you do this in the editor then they will automatically be marked as readable.
     
  24. xiDando

    xiDando

    Joined:
    Apr 6, 2016
    Posts:
    4
    Hey, i'm having a problem. In the inspector I have added a collision handler which works fine at runtime. However, if I make the object a prefab, when it comes to instantiating the 'damage destructible' is made blank and therefor won't damage on collision.
    Is there a way of setting the 'damage destructible' in script so I no long have this problem when instantiating prefabs?

    Cheers, JD
     
  25. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    What do you mean it's made blank? The inspector fails to render anything for that component? Or the OnImpact event handlers are removed? Also, do you see any errors in the console?
     
  26. xiDando

    xiDando

    Joined:
    Apr 6, 2016
    Posts:
    4
    Morning, thanks for the quick reply.

    If you look what i've circled, the prefab will not take the same argument. So when I instantiate the prefab it doesn't damage 'Box1'.

    I'm not sure if you have access to twitter, but this gif shows what the should happen. However if the shield is instantiated rather than just put in the hierarchy during editing, the box passes straight through the shield. -- https://twitter.com/JD_Pixels/status/727479933149306880 Untitled-1.png Untitled-2.png Thanks again, JD. EDIT: The On Impact Event also doesn't appear on the prefab.
     
    Last edited: May 4, 2016
  27. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I see, this is because prefabs cannot reference objects in the scene. If you try something similar with any other component you'll notice it also goes null/none. To get it to work you need to make these objects all part of the same prefab, or use multiple prefabs, but manually link these together in the scene.
     
  28. xiDando

    xiDando

    Joined:
    Apr 6, 2016
    Posts:
    4
    Okay thankyou I managed to get the shield and box prefabs working together, however, the shield does not damage the clones of the box(the keep spawning every second or so)

    box1 = GameObject.FindObjectOfType<box1Script>();
    boxDestructible = box1.GetComponent<Destructible2D.D2dDestructible>();
    collisionHandler.DamageDestructible = boxDestructible;

    That is in the update function but it doesn't work for clones, only the first one to be instantiated.

    Cheers, JD.
     
  29. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    This is because GameObject.FindObjectOfType<box1Script>(); will always return the first one in your scene.

    If you have to spawn two of these separate objects at a time then you should manually link them together upon spawning and not during Update.
     
  30. watkinza

    watkinza

    Joined:
    Oct 30, 2015
    Posts:
    1
    Hey Darkcoder, this is a really cool feature set and I am thinking about using it for my game which is already using procedural animation and 2d physics. I am concerned about performance (who isn't) because while the terrain won't be destructible, nearly all other objects will be while also using 2d physics.

    Edit: I read on page 7 the biggest performance bottleneck is the algorithm that fragments sprites. Are there other processes which currently have a significant impact on runtime performance? I am likely to use this plugin's script API if that makes a difference.

    Also, I am wondering if (with some coding on my part) I can make the destruction trigger based on collision events with a collider of a different shape than the game object's sprite? This would be helpful for isometric games I think, but may have issues with auto-generated colliders after fragmentation.
     
    Last edited: May 16, 2016
  31. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Yes, your destructible object can have a different collider and visual shape within reason, and you can also trigger collisions from code at any time.

    The biggest performance bottleneck is just using collider data that is too detailed, but this can easily be reduced using the built-in 'Optimize Alpha' setting, which halves the width & height of the destructible data and smooths the edges to make it look similar, making everything 4x faster.
     
    watkinza likes this.
  32. DigitalToy

    DigitalToy

    Joined:
    Oct 29, 2012
    Posts:
    11
    Hi, I love your plugin - it works pretty well. I do have some performance issues - at the moment of instantiation there is a noticeable "hiccup". I managed to reduce this by using the "Optimize Alpha" feature on the Destructible element. When I do this, however, I get an error when running - "Destroying assets is not permitted to avoid data loss." This is coming from the following calls:

    Destroying assets is not permitted to avoid data loss.
    If you really want to remove an asset use DestroyImmediate (theObject, true);
    UnityEngine.Object: Destroy(Object)
    Destructible2D.D2dHelper: Destroy(PolygonCollider2D) (at Assets/Destructible 2D/Scripts/D2dHelper.cs:35)
    Destructible2D.D2dPolygonCollider:Sweep() (at Assets/Destructible 2D/Scripts/D2dPolygonCollider.cs:133)
    Destructible2D.D2dPolygonCollider:OnStartSplit() (at Assets/Destructible 2D/Scripts/D2dPolygonCollider.cs:111)
    UnityEngine.Events.UnityEvent:Invoke()
    Destructible2D.D2dDestructible:Split(D2dSplitGroup, List`1, Int32) (at Assets/Destructible 2D/Scripts/D2dDestructible.cs:1312)
    Destructible2D.D2dQuadFracturer:Fracture(D2dDestructible, Int32, Single, Int32) (at Assets/Destructible 2D/Scripts/D2dQuadFracturer.cs:88)

    When I revert the object back to the way it was before using "Optimize Alpha", the error does not occur.

    Do you have an idea of how to avoid this?

    Also, a feature I could use is the ability to set the instantiated clones' layer to something different from the parent destructible (including the layer of the remaining fragment, which is not a clone - which was the parent object). I'd also like to be able to set the clones' mass. Could you add the ability to be able to modify these?

    Thank you
     
    Last edited: May 27, 2016
  33. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Are you trying to call Optimize Alpha on a prefab? If so, you need to drag it into your scene, modify it, then apply the changes back to the prefab. If not then I'd like some steps to reproduce the issue.

    The features you mention are possible to implement, but I don't think many people would find them useful, so it's best if you modify the D2D code to work how you want. You can see the layer setting code for splitting on line 1346 of D2dDestructible.cs, and you can look at the D2dRetainVelocity script to see how you can hook into the OnEndSplit event to modify split rigidbody information.
     
  34. DigitalToy

    DigitalToy

    Joined:
    Oct 29, 2012
    Posts:
    11
    Thank you - I think modifying the prefab was the problem.

    I have been able to modify the code to do what I want, so that's good too.
     
    Darkcoder likes this.
  35. DPhaze

    DPhaze

    Joined:
    Jun 10, 2016
    Posts:
    3
    Hey there, awesome plugin you've got here. I was just wondering if there is any way to optimize it further, other than the optimize alpha option? I'm running about 200(preferably more) objects that have a repeat stamp on them, with a custom script to iterate over the stamp running to distribute the load more.

    Also, the collider generation seems to not play too well with triangles.

    And while I'm here, there was a bug with an edge collider on a 1280pxX256px image, where it would cause lag if a certain collider was hit, even by a single object. Same thing was generated each time I tried to make a destructible from that image. I checked it over, didn't seem to be any extra colliders out of place, but one or two of them were causing some kind of issue.
     
  36. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    200 repeat stamping objects is pretty extreme. The best way I can think of to optimize that scenario is to only stamp if the stamp or some object in range has moved. Additionally you could stop or reduce stamp frequency on objects that aren't in the camera view. If it's still slow then you can try changing the stamp code to only mark edited pixels as modified, because right now it marks the whole stamp rectangle, which may not actually contain any changes. I didn't test if doing this would be faster in all scenarios though.

    I'm not really sure what I'm looking at in this picture. Is the generated collider twice the size it should be? If so, could you e-mail or message me a simple UnityPackage containing a scene with just that broken object so I can test?

    Assuming your edge collider wasn't being modified during this lag then it sounds like an issue with how detailed that particular collider was. Did you check the point count in the inspector to see if it's something crazy compared to the others? You can try decreasing the collider detail to see if it improves it. If the shape isn't the issue then I have no idea, as D2D doesn't do anything after the colliders have been generated.
     
  37. Ioann

    Ioann

    Joined:
    May 29, 2014
    Posts:
    1
  38. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Yes, SpriteRenderer is basically the same as MeshRenderer, so sprite shaders will work, and they can render together. However, D2D requires a few additional tweaks to the shader to show the destruction. There is a pdf that comes with D2D that details these modifications.
     
  39. Nerevarine

    Nerevarine

    Joined:
    Jul 26, 2014
    Posts:
    14
    Hi, please provide instructions on how to use this with meshes..
    I have a procedurally generated mesh at runtime that has vertices and triangles array.
    How to feed this information to Destructible 2D ?
     
  40. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    You can't, it's 2D image based destruction, and the mesh is an automatically generated quad.
     
  41. Nerevarine

    Nerevarine

    Joined:
    Jul 26, 2014
    Posts:
    14
    Hmm, thats a bummer :( I was hoping the mesh points could be fed into it :(
    Is there any way to convert a mesh into a sprite beforehand ?
     
  42. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    You can render your mesh using a Camera that has a RenderTarget, and copy the rendered pixels into a normal Texture2D, and then you can call yourD2dDestructible.ReplaceWith(yourTexture2D) to make it destructible.
     
  43. SweatyChair

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    140
    Bought the plugin and it works great in Android!

    Switched to iOS it said the texture not supported in Unity 5.4.0 as:

    Code (CSharp):
    1. Unsupported texture format - needs to be ARGB32, RGBA32, BGRA32, RGB24, Alpha8, RGBAFloat, RGBAHalf or one of supported compressed formats.
    2. UnityEngine.Texture2D:GetPixel(Int32, Int32)
    3. Destructible2D.D2dDestructible:SampleStamp(Texture2D, Vector2) (at Assets/Destructible 2D/Scripts/D2dDestructible.cs:744)
    4. Destructible2D.D2dDestructible:Stamp(Matrix4x4, Texture2D, Single) (at Assets/Destructible 2D/Scripts/D2dDestructible.cs:652)
    5. Destructible2D.D2dDestructible:StampAll(Matrix4x4, Texture2D, Single, Int32) (at Assets/Destructible 2D/Scripts/D2dDestructible.cs:552)
    6. Destructible2D.D2dDestructible:StampAll(Vector2, Vector2, Single, Texture2D, Single, Int32) (at Assets/Destructible 2D/Scripts/D2dDestructible.cs:535)
    7. Destructible2D.D2dExplosion:Start() (at Assets/Destructible 2D/Examples/Scripts/D2dExplosion.cs:99)

    It doesn't help even I change the Main Tex in D2dDestructible Format to Truecolor, it seems to be the problem of the Alpha Tex the script generated in run time. Any quick fix?

    Screen Shot 2016-08-23 at 7.29.41 PM.png
     
    Last edited: Aug 23, 2016
  44. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    This error indicates the StampTex is causing the error. Are you using a stamp that comes with the D2D example media, or are you using your own one?
     
  45. LunchLadiesMan

    LunchLadiesMan

    Joined:
    Mar 27, 2014
    Posts:
    1
    Does D2D support playmaker? Specifically can Playmaker create or modify a Sprite's D2D attributes?
     
  46. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I don't use Playmaker, but I believe it has the ability to modify normal component fields and call methods, so they should work fine together. The fields and methods have the same names as in the inspector, so if you figure out how to do something in the inspector then it should just be a case of doing the exact same things from your FSM.
     
  47. a-tauzzi

    a-tauzzi

    Joined:
    Dec 20, 2015
    Posts:
    33
    Does it work with a game object that has an animator and shows a couple of sprites taken from a spreadsheet?
    Is it able to destruct the whole game object or only applies to a single sprite?

    I saw a demo where the player can destroy a Bee that seems animated, unfortunately the Bee stops flying when hit. I don't understand if the damage can be inflicted to all sprites of the Bee or only one sprite.
     
    Last edited: Sep 4, 2016
  48. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    There are two ways you can animate things in D2D using the Animation/Animator features:

    1 - Create multiple destructible objects and combine them together into a compound destructible object. e.g. make an empty parent gameObject and attach a bunch of different body parts that move around.

    2 - Replace the base texture for the destructible object, e.g. the bee example.

    Keep in mind that 2 works best if your object shape doesn't change while animating. You'll notice the bee's wings move as it animates, so I had to combine all the animation frames to use as the collision shape, otherwise the wings would disappear as they go behind the original collision shape/mask.
     
  49. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    Hey Darkcoder,

    Two questions: is there a good approach to making sprites? I've more than once come across sprites that have an alpha count of 400k - when fracturing these my PC died :p When using 15k, the fractures look kinda rugged and not crisp. I've noticed that if I use 50k as alpha count it looks ok but fracturing is already quite laggy (0.5s delay or something).

    Secondly: can you destroy a sprite partially? For example, if I make a planet sprite, can I break off part of the planet by fracturing? I know stamping/slicing can do it but I kinda want to 'stamp' around the impact point of an asteroid and fracture the part of the planet that falls under the stamp (so to speak).
     
  50. a-tauzzi

    a-tauzzi

    Joined:
    Dec 20, 2015
    Posts:
    33

    Thank you for the answer.
    During the night I changed the "animation approach". I will resort to make the animation in the Update method simply swapping sprites. So I can apply the solution described in bullet 2, right?