Forums

OverviewV-Play 1 Support › Particles z-ordering

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

    Christian
    V-Play Team

    Hi,

    I just added a cool new particle effect to my game, and I would like it to be drawn below the player, but above everything else. Everything is drawn via sprites (SingleSpriteFromFile elements) and without use of the vertexZ property.

    Is this possible?

    My setup is this:

    I have a collectible item, and I want it to have a cool particle effect when the player collects it. The collectible item has the particle as a child of itself. When it gets collected, the particle effect is started. The collectible item is drawn below the player, but the particles appear above everything.

     

    Cheers, Chrisu

    #4332

    Christian
    V-Play Team

    Hi Chrisu,

    good hear from you again – always challenging to answer your questions :)

    This is a tricky question, because of the following:

    The SingleSpriteFromFile uses batched rendering for maximum performance, which means all sprites within the sprite sheet are drawn in one draw call. This SpriteBatchContainer is usually put at the root element of your GameWindow. This means when drawing the items based after their z order, the sprites of the spritesheet are drawn first, and afterwards the particles are drawn. To avoid the Particle being drawn on top of the sprites but below them, you would need to put the Particle element before the SpriteBatchContainer and modify its property there. You could also play with the vertexZ property and try to get it right.

    Please let me know if this approach works for you.

    Cheers, Chris

    #4387

    Christian
    V-Play Team

    Hey Chris,

     

    thanks for your answer. It doesn’t seem to be working when putting the particles on the same file as the SpriteBatchContainer above it and modifying the z-property. Here is how i tried it in my BaseLevel.qml:

    property variant particleItem
    
    GemParticles {
      id: gemParticles
      z: particleItem ? particleItem.z : 0
      type: particleItem ? particleItem.type : 1
      pos.x: particleItem ? particleItem.x + particleItem.width / 2 : 0
      pos.y: particleItem ? particleItem.y + particleItem.width * 2 / 5 : 0
    }
    
    SpriteBatchContainer {}
    
    function startGemParticles(item) {
      if(window.isParticlesEnabled()) {
        gemParticles.stop()
        gemParticles.stopLivingParticles()
        particleItem = item
        gemParticles.start()
      }
    }
    

    But all particles are still drawn above everything.

    When I use vertexZ, i thought it was not possible to change this property at runtime?

    #4430

    David

    Hi Chrisu,

    could you please try to align your particles z-value along the SpriteBatchContainer z-value and test if this works propertly?

    GemParticles {
      id: gemParticles
      z: spriteBatchContainer.z-1
    }
    
    SpriteBatchContainer {
      id: spriteBatchContainer  
    }
    

    Following example displays different objects in order to test the particles z-ordering.

    import QtQuick 1.1
    import VPlay 1.0
    
    //  This example test the particle Z ordering.
    GameWindow {
      id: screen
    
      Scene {
        id: scene
        objectName: "scene"
    
        Rectangle {
          id: base
          z: particle.z-1
          x: scene.width/2
          y: scene.height/2-25
          width: 50
          height: 50
          color: "darkgrey"
        }
    
        Particle {
          id: particle
          z: container.z-1
          fileName: "FireParticle.json"
          x: scene.width/2
          y: scene.height/2
    
          autoStart: true
        }
    
        SpriteBatchContainer {
          id: container
        }
    
        Rectangle {
          id: overlapper
          x: scene.width/2
          y: scene.height/2
          width: 50
          height: 50
          color: "grey"
        }
    
        SingleSpriteFromSpriteSheet {
          id: sprite
          frameWidth: 256
          frameHeight: 256
          startFrameColumn: 0
          spriteSheetSource: "img/weaponbox.png"
          translateToCenterAnchor: false
        }
      }
    }

    Cheers,

    David

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