所以我試圖在 haxeflixel 中添加一個影片,但我無法讓它作業。所以我想使用它附帶的 .xml 檔案,這樣我就可以獲得影片的寬度、高度和名稱。
這是我的作業表和 xml 檔案:
<?xml version="1.0" encoding="utf-8"?>
<TextureAtlas imagePath="bob.png">
<!-- Created with Adobe Animate version 21.0.1.37179 -->
<!-- http://www.adobe.com/products/animate.html -->
<SubTexture name="Idle0000" x="0" y="0" width="228" height="588"/>
<SubTexture name="Idle0001" x="228" y="0" width="228" height="588"/>
<SubTexture name="Idle0002" x="456" y="0" width="228" height="588"/>
<SubTexture name="Idle0003" x="684" y="0" width="228" height="588"/>
<SubTexture name="Idle0004" x="912" y="0" width="228" height="588"/>
<SubTexture name="Idle0005" x="1140" y="0" width="228" height="588"/>
<SubTexture name="Idle0006" x="1368" y="0" width="228" height="588"/>
<SubTexture name="Idle0007" x="1596" y="0" width="228" height="588"/>
<SubTexture name="Idle0008" x="1824" y="0" width="228" height="588"/>
<SubTexture name="Idle0009" x="2052" y="0" width="228" height="588"/>
<SubTexture name="Idle0010" x="2280" y="0" width="228" height="588"/>
<SubTexture name="Idle0011" x="2508" y="0" width="228" height="588"/>
<SubTexture name="Idle0012" x="2736" y="0" width="228" height="588"/>
<SubTexture name="Idle0013" x="2964" y="0" width="228" height="588"/>
<SubTexture name="Idle0014" x="3192" y="0" width="228" height="588"/>
<SubTexture name="Idle0015" x="3420" y="0" width="228" height="588"/>
<SubTexture name="Idle0016" x="3648" y="0" width="228" height="588"/>
<SubTexture name="Idle0017" x="0" y="588" width="228" height="588"/>
<SubTexture name="Idle0018" x="228" y="588" width="228" height="588"/>
<SubTexture name="Idle0019" x="0" y="0" width="228" height="588"/>
<SubTexture name="Walk0000" x="456" y="588" width="250" height="600"/>
<SubTexture name="Walk0001" x="706" y="588" width="250" height="600"/>
<SubTexture name="Walk0002" x="956" y="588" width="250" height="600"/>
<SubTexture name="Walk0003" x="1206" y="588" width="250" height="600"/>
<SubTexture name="Walk0004" x="1456" y="588" width="250" height="600"/>
<SubTexture name="Walk0005" x="1706" y="588" width="250" height="600"/>
<SubTexture name="Walk0006" x="1956" y="588" width="250" height="600"/>
<SubTexture name="Walk0007" x="2206" y="588" width="250" height="600"/>
<SubTexture name="Walk0008" x="456" y="588" width="250" height="600"/>
</TextureAtlas>
和我的代碼:
loadGraphic(sprite.graphic, true, 228, 588); // i dont know if the last 2 values are a frame or the entire image
addAnimation("idle", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], true);
addAnimation("walk", [0, 1, 2, 3, 4, 5, 6, 7], true);
animation.play("idle");
uj5u.com熱心網友回復:
該 XML 實際上是 XML 格式的 Adob??e Animate 紋理圖集。該圖集帶有 .png 和 .xml。
問題是您根本不會訪問 XML 內容。您只是在使用自定義值。要在 HF 中加載圖集,請執行以下步驟:
/* mySprite is the sprite we're loading the animations into. You don't specify the
frame size because it'll grab it from the XML anyway.*/
mySprite.loadGraphic("path/to/graphic.png", true);
/* this line actually loads the animation from the XML. Replace the paths to the
paths where your atlas png and xml files are located. */
mySprite.frames = FlxAtlasFrames.fromSparrow("path/to/graphic.png", "path/to/xmlfile.xml");
/* here, you add the animations. The first parameter is the name of the animation as
you wish it to be in **your code**. The second parameter is the name of the
animation **inside the xml**, which will be used to locate its size, frames, and
position. Last argument is the framerate at which the animation plays. */
mySprite.animation.addByIndices("idleAnimation", "idle", frameRate);
//here, you play the animation you just added.
mySprite.animation.play("idleAnimation");
祝你好運!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/515437.html
