Find the Best Demos and Examples

Check out this quick tour to find the best demos and examples for you, and to see how the Felgo SDK can help you to develop your next app or game!

Forums

OverviewFelgo 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 5 years, 5 months ago by  Deathdragon.
    #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 5 years, 5 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.