Hi,
yes it’s always required to set the frameNames.
However, of course you can use QML to build this array automatically on-the-fly. For example, you can set your frame names to only include an increased counter (like frame_0.png, frame_1.png, …) and create this array dynamically. Another option would be to load and parse the exported TexturePacker JSON manually. However, I’m not sure if the sorting of the frames will be in the correct order then.
Here are a few examples:
// manual
TexturePackerAnimatedSpriteVPlay {
source: "../assets/img/sprite.json"
frameNames: ["frame_0.png", "frame_1.png", "frame_2.png"]
}
// automatic
TexturePackerAnimatedSpriteVPlay {
source: "../assets/img/sprite.json"
property int frameCount: 3
frameNames: {
var names = []
for(var i = 0; i < frameCount; i++)
names.push("frame_"+i+".png")
return names
}
}
// parse texturepacker json
TexturePackerAnimatedSpriteVPlay {
source: "../assets/img/sprite.json"
frameNames: {
var spriteData = loadFile(source)
var names = []
for(var name in spriteData.frames)
names.push(name)
return names
}
}
function loadFile(file) {
var xmlHttpReq = new XMLHttpRequest()
xmlHttpReq.open("GET", Qt.resolvedUrl(file), false)
xmlHttpReq.send()
return JSON.parse(xmlHttpReq.responseText)
}
Hope this helps!
Best,
Günther