Forums

OverviewV-Play 2 Support (Qt 5)NumberAnimation in a entity QML file › Reply To: NumberAnimation in a entity QML file

OverviewV-Play 2 Support (Qt 5)NumberAnimation in a entity QML file › Reply To: NumberAnimation in a entity QML file
#9186

Manuel

It seems the problem with all of the above suggestions (except the onYchanged one) is that I use Entity Pooling, which means that the animation will not be started, when the entities are reused…I would need to restart it manually by using the entityManager.

When using onYChanged it will be called always as Y is changing even when reusing the entities.

 

Possible Solution with entity Pooling and not using onYChanged:

function startAnimation() {
        bulletAnim.start()
    }

    // moves the entity to y position 0 within 1 second
    NumberAnimation on y {
        id:bulletAnim
        to: 0
        duration: 1000
        running: true
        onStopped: {
            bulletEntity.removeEntity()
        }
    }

and

MouseArea {
                id:shipInputController
                //enable updating of mouse position without clicking
                hoverEnabled: true
                anchors.fill: parent
                onMouseXChanged: {
                    //positioning the ship in the middle of the mouse position (all items have a top-left origin)
                    ship1.x = mouseX - (ship1.width/2) ;
                }
                onClicked: {
                    clickSound.play()

                    var newEntityProperties = {
                        width: 15,
                        height: 20,
                        // vary x between [ safetyZoneHoriztonal ... width-safetyZoneHoriztonal]
                        x: ship1.x + (ship1.width/2) - 7.5,
                        y: ship1.y - 12, // position on top of the scene, at least below the top wall
                    }

                    entityManager.createEntityFromUrlWithProperties(
                                Qt.resolvedUrl("entities/Bullet.qml"),
                                newEntityProperties);
                    entityManager.getLastAddedEntity()["startAnimation"].call()
                }
            }

Thanks again.

  • This reply was modified 3 years, 2 months ago by  Deathdragon.

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