Forums

OverviewV-Play 2 Support (Qt 5) › Possible to react to finishing of an AnimatedSpriteVPlay

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #9188

    Manuel

    Hello,

    I am trying to show an AnimatedSprite as an Explosion/Death Animation via the following Code, the Animation is now shown properly, because I don’t call enemyAnim.stop() directly after setting the explosion AnimatedSpriteVPlay… is there any possibility to react to finishing the Animation and finally destroy the entity?

     

    EntityBase {
        id: shipEntity
        entityType: "ship"
        variationType: "enemy"
    
        width: 32
        height: 32
    
        Rectangle {
            color:"transparent"
            anchors.fill: parent
    
            Image {
                id: shipImage
                smooth: false
                source: "../../assets/img/enemy.png"
                anchors.fill: parent
            }
            AnimatedSpriteVPlay {
              id: explosion
              width: 32
              height: 32
              loops: 1
              visible: false
              frameWidth: 16
              frameHeight: 16
              frameCount: 4
              startFrameColumn: 1
              frameRate: 20
              source: "../../assets/img/sprites/explosion.png"
            }
        }
    
        BoxCollider {
            categories: Box.Category2
            // the BoxCollider will not be affected by gravity or other applied physics forces
            collisionTestingOnlyMode: true
    
            collidesWith: Box.Category1
    
            // make the same size as the Image
            anchors.fill: shipEntity
    
            fixture.onBeginContact: {
                shipImage.visible=false
                explosion.visible=true
                explosion.restart()
            }
        }
    
        function startAnimation(to) {
            enemyAnim.to=to
            enemyAnim.start()
        }
    
        // moves the entity to y position 0 within 1 second
        NumberAnimation on y {
            id:enemyAnim
            duration: 4000
            running: false
            onStopped: {
                shipEntity.removeEntity()
            }
        }

    Thanks in Advance.

     

    • This topic was modified 3 years, 6 months ago.
    #9191

    Manuel

    I found a workaround, adding a transparent sprite to the png image and using the following code:

     fixture.onBeginContact: {
                shipImage.visible=false
                explosion.visible=true
                explosion.restart()
                shipEntity.collidersActive=false
            }

    This deactivates the entity (visibility and colliders) till it gets removed at the end of the scene.

    • This reply was modified 3 years, 6 months ago by  Deathdragon.
Viewing 2 posts - 1 through 2 (of 2 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