Forums

OverviewV-Play 2 Support (Qt 5) › animation not take framerate and frames name automatically

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #15019

    Nour

    hello

     

    i am using TexturePackerSpriteVPlay
    how i can make it fill frameNames, and frameRate automatically?

    #15020

    Günther
    V-Play Team

    Hi!

    These configuration values cannot be set automatically, as this depends on how you want to use TexuturePacker and how you configure your animations.
    With TexturePacker it is possible to for example pack images for multiple animations or even entities into one spritesheet. It is required to then specify which animations use which frames with the frameNames of the relevant frames. The frameRate then decides the speed of the sprite animation.

    Best,
    Günther

    #15023

    Nour

    then i i need to animate all frames, so i need to write all frames name in array?

    so if i have 30 frames, i need to fill array of 30 elements?

    #15025

    Günther
    V-Play Team

    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

Viewing 4 posts - 1 through 4 (of 4 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support