Browse Source

Update 24_Urho2DSprite sample with spriter animation.

aster2013 11 years ago
parent
commit
a99145a80c

+ 4 - 6
Bin/Data/LuaScripts/24_Urho2DSprite.lua

@@ -92,19 +92,17 @@ function CreateScene()
         end
     end
 
-    local animation = cache:GetResource("Animation2D", "Urho2D/GoldIcon.anm")
-    if animation == nil then
+    local animationSet = cache:GetResource("XAnimationSet2D", "Urho2D/GoldIcon.scml")
+    if animationSet == nil then
         return
     end
 
     local spriteNode = scene_:CreateChild("AnimatedSprite2D")
     spriteNode.position = Vector3(0.0, 0.0, -1.0)
 
-    local animatedSprite = spriteNode:CreateComponent("AnimatedSprite2D")
+    local animatedSprite = spriteNode:CreateComponent("XAnimatedSprite2D")
     -- Set animation
-    animatedSprite.animation = animation
-    -- Set blend mode
-    animatedSprite.blendMode = BLEND_ALPHA
+    animatedSprite:SetAnimation(animationSet, "idle")
 end
 
 function CreateInstructions()

+ 4 - 6
Bin/Data/Scripts/24_Urho2DSprite.as

@@ -78,17 +78,15 @@ void CreateScene()
         spriteNodes.Push(spriteNode);
     }
 
-    Animation2D@ animation = cache.GetResource("Animation2D", "Urho2D/GoldIcon.anm");
-    if (animation is null)
+    XAnimationSet2D@ animationSet = cache.GetResource("XAnimationSet2D", "Urho2D/GoldIcon.scml");
+    if (animationSet is null)
         return;
     Node@ spriteNode = scene_.CreateChild("AnimatedSprite2D");
     spriteNode.position = Vector3(0.0f, 0.0f, -1.0f);
 
-    AnimatedSprite2D@ animatedSprite = spriteNode.CreateComponent("AnimatedSprite2D");
+    XAnimatedSprite2D@ animatedSprite = spriteNode.CreateComponent("XAnimatedSprite2D");
     // Set animation
-    animatedSprite.animation = animation;
-    // Set blend mode
-    animatedSprite.blendMode = BLEND_ALPHA;
+    animatedSprite.SetAnimation(animationSet, "idle");
 }
 
 void CreateInstructions()

+ 57 - 0
Bin/Data/Urho2D/GoldIcon.scml

@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<spriter_data scml_version="1.0" generator="BrashMonkey Spriter" generator_version="b8_1">
+    <folder id="0" name="GoldIcon">
+        <file id="0" name="GoldIcon/2.png" width="64" height="64" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="1" name="GoldIcon/1.png" width="64" height="64" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="2" name="GoldIcon/3.png" width="17" height="60" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="3" name="GoldIcon/4.png" width="64" height="64" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="4" name="GoldIcon/5.png" width="64" height="64" pivot_x="0.5" pivot_y="0.5"/>
+    </folder>
+    <entity id="0" name="entity_000">
+        <animation id="0" name="idle" length="500">
+            <mainline>
+                <key id="0">
+                    <object_ref id="0" timeline="0" key="0" z_index="0"/>
+                </key>
+                <key id="1" time="99">
+                    <object_ref id="0" timeline="1" key="0" z_index="0"/>
+                </key>
+                <key id="2" time="199">
+                    <object_ref id="0" timeline="2" key="0" z_index="0"/>
+                </key>
+                <key id="3" time="300">
+                    <object_ref id="0" timeline="3" key="0" z_index="0"/>
+                </key>
+                <key id="4" time="400">
+                    <object_ref id="0" timeline="4" key="0" z_index="0"/>
+                </key>
+                <key id="5" time="500"/>
+            </mainline>
+            <timeline id="0" name="1">
+                <key id="0" spin="0">
+                    <object folder="0" file="1" angle="0"/>
+                </key>
+            </timeline>
+            <timeline id="1" name="2">
+                <key id="0" time="99" spin="0">
+                    <object folder="0" file="0" angle="0"/>
+                </key>
+            </timeline>
+            <timeline id="2" name="3">
+                <key id="0" time="199" spin="0">
+                    <object folder="0" file="2" angle="0"/>
+                </key>
+            </timeline>
+            <timeline id="3" name="4">
+                <key id="0" time="300" spin="0">
+                    <object folder="0" file="3" angle="0"/>
+                </key>
+            </timeline>
+            <timeline id="4" name="5">
+                <key id="0" time="400" spin="0">
+                    <object folder="0" file="4" angle="0"/>
+                </key>
+            </timeline>
+        </animation>
+    </entity>
+</spriter_data>

BIN
Bin/Data/Urho2D/GoldIcon/1.png


BIN
Bin/Data/Urho2D/GoldIcon/2.png


BIN
Bin/Data/Urho2D/GoldIcon/3.png


BIN
Bin/Data/Urho2D/GoldIcon/4.png


BIN
Bin/Data/Urho2D/GoldIcon/5.png


+ 7 - 9
Source/Samples/24_Urho2DSprite/Urho2DSprite.cpp

@@ -20,8 +20,6 @@
 // THE SOFTWARE.
 //
 
-#include "AnimatedSprite2D.h"
-#include "Animation2D.h"
 #include "Camera.h"
 #include "CoreEvents.h"
 #include "Engine.h"
@@ -37,6 +35,8 @@
 #include "Text.h"
 #include "Urho2DSprite.h"
 #include "Zone.h"
+#include "XAnimationSet2D.h"
+#include "XAnimatedSprite2D.h"
 
 #include "DebugNew.h"
 
@@ -117,19 +117,17 @@ void Urho2DSprite::CreateScene()
         spriteNodes_.Push(spriteNode);
     }
 
-    // Get animation
-    Animation2D* animation = cache->GetResource<Animation2D>("Urho2D/GoldIcon.anm");
-    if (!animation)
+    // Get animation set
+    XAnimationSet2D* animationSet = cache->GetResource<XAnimationSet2D>("Urho2D/GoldIcon.scml");
+    if (!animationSet)
         return;
 
     SharedPtr<Node> spriteNode(scene_->CreateChild("AnimatedSprite2D"));
     spriteNode->SetPosition(Vector3(0.0f, 0.0f, -1.0f));
 
-    AnimatedSprite2D* animatedSprite = spriteNode->CreateComponent<AnimatedSprite2D>();
+    XAnimatedSprite2D* animatedSprite = spriteNode->CreateComponent<XAnimatedSprite2D>();
     // Set animation
-    animatedSprite->SetAnimation(animation);
-    // Set blend mode
-    animatedSprite->SetBlendMode(BLEND_ALPHA);
+    animatedSprite->SetAnimation(animationSet, "idle");
 }
 
 void Urho2DSprite::CreateInstructions()