2
0
Эх сурвалжийг харах

Fixed typo in SceneSprite constructor, added Sprite code example to Lua examples

Ivan Safrin 10 жил өмнө
parent
commit
6ececfb837

+ 1 - 1
Core/Contents/Include/PolySceneSprite.h

@@ -119,7 +119,7 @@ namespace Polycode {
     
     
     class SpriteSet : public ResourcePool {
     class SpriteSet : public ResourcePool {
     public:
     public:
-        SpriteSet(String imageFileName, ResourcePool *parentPool = CoreServices::getInstance()->getResourceManager()->getGlobalPool());
+        SpriteSet(const String &fileName, ResourcePool *parentPool = CoreServices::getInstance()->getResourceManager()->getGlobalPool());
         ~SpriteSet();
         ~SpriteSet();
         
         
         void setTexture(Texture *texture);
         void setTexture(Texture *texture);

+ 1 - 2
Core/Contents/Source/PolySceneSprite.cpp

@@ -524,10 +524,9 @@ void Sprite::setName(String name) {
 }
 }
 
 
 
 
-SpriteSet::SpriteSet(String fileName, ResourcePool *parentPool) : ResourcePool(fileName, parentPool) {
+SpriteSet::SpriteSet(const String &fileName, ResourcePool *parentPool) : ResourcePool(fileName, parentPool) {
     nextFrameIDIndex = 0;
     nextFrameIDIndex = 0;
     loadSpriteSet(fileName);
     loadSpriteSet(fileName);
-    
 }
 }
 
 
 void SpriteSet::loadSpriteSet(String fileName) {
 void SpriteSet::loadSpriteSet(String fileName) {

BIN
Examples/Lua/Graphics/Sprites/Resources/explosion.png


+ 31 - 0
Examples/Lua/Graphics/Sprites/Resources/sprite_set.sprites

@@ -0,0 +1,31 @@
+<?xml version="1.0" ?>
+<sprite_set>
+    <sprite_sheet fileName="Resources/explosion.png">
+        <frames>
+            <frame id="0" x="0" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="1" x="0.0555556" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="2" x="0.111111" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="3" x="0.166667" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="4" x="0.222222" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="5" x="0.277778" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="6" x="0.333333" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="7" x="0.388889" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="8" x="0.444444" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="9" x="0.5" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="10" x="0.555556" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="11" x="0.611111" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="12" x="0.666667" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="13" x="0.722222" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="14" x="0.777778" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="15" x="0.833333" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+            <frame id="16" x="0.888889" y="0" w="0.0555556" h="1" ax="0" ay="0" />
+        </frames>
+    </sprite_sheet>
+    <sprites>
+        <sprite name="Explosion">
+            <states>
+                <state name="default" fps="20" scale="1" width="32" height="32" offset_x="0" offset_y="0" frame_ids="0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16" />
+            </states>
+        </sprite>
+    </sprites>
+</sprite_set>

+ 10 - 0
Examples/Lua/Graphics/Sprites/Scripts/Main.lua

@@ -0,0 +1,10 @@
+scene = Scene(Scene.SCENE_2D)
+scene:getActiveCamera():setOrthoSize(640, 480)
+    
+spriteSet = SpriteSet("Resources/sprite_set.sprites", Services.ResourceManager:getGlobalPool())
+sceneSprite = SceneSprite(spriteSet)
+sceneSprite:setScale(4, 4)
+scene:addEntity(sceneSprite)
+    
+sceneSprite:setSpriteByName("Explosion")
+sceneSprite:setSpriteStateByName("default", 0, false)

+ 8 - 0
Examples/Lua/Graphics/Sprites/Sprites.polyproject

@@ -0,0 +1,8 @@
+<?xml version="1.0" ?>
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0" entryPoint="Scripts/Main.lua" textureFiltering="linear" vSync="false" anisotropyLevel="0" frameRate="60">
+    <backgroundColor red="0.25" green="0.25" blue="0.25" />
+    <polyarray:packedItems>
+        <item type="folder" path="Resources" />
+        <item type="folder" path="Scripts" />
+    </polyarray:packedItems>
+</PolycodeProject>