I am new to both Qt and V-play and this is my test about collision and animation (with property). Here is the code I used:
import Felgo 3.0
import QtQuick 2.0
GameWindow {
screenWidth: 960
screenHeight: 640
EntityManager {
id: entityManager
entityContainer: scene
}
PhysicsWorld{
debugDrawVisible: true
}
Scene {
id: scene
// the "logical size" - the scene content is auto-scaled to match the GameWindow size
width: 480
height: 320
PhysicsWorld {debugDrawVisible: true} // put it anywhere in the Scene, so the collision detection between monsters and projectiles can be done
BackgroundImage {
id:levelBackground
source: "../assets/sky.jpg"
height:240
width:480
MouseArea {
anchors.fill: levelBackground
onClicked: {
console.debug(mouseX, mouseY)
entityManager.createEntityFromComponentWithProperties(projectile, {"startY": mouseY});
}
}
}
BackgroundImage{
id:hudBackground
source: "../assets/hud.jpg"
y:240
height:80
width:480
}
Component {
id: airBalloon
EntityBase {
entityType: "balloon"
Image {
id: balloonImage
source: "../assets/balloon.jpg"
scale:0.1
}
x:100
y:100
BoxCollider {
anchors.bottom: balloonImage.bottom // make the collider as big as the image
collisionTestingOnlyMode: true // use Box2D only for collision detection, move the entity with the NumberAnimation above
width:30
height:30
}
}// BoxCollider
}// EntityBase
}// Component
Component {
id: projectile
EntityBase {
entityType: "projectile"
width: 29
height: 11
x:970
y: 100
Image {
id: arrowImage
source: "../assets/arrow.png"
width: parent.width
height: parent.height
x: -width / 2
y: -height / 2
}
property double startX: scene.gameWindowAnchorItem.width
property double startY
property double goalX: -70
property double goalY: startY
property double speed: 3000
BoxCollider {
anchors.centerIn: parent
width: 30
height: 15
collisionTestingOnlyMode: true // use Box2D only for collision detection, move the entity with the NumberAnimation above
fixture.onBeginContact: {
// if the collided type was a projectile, both can be destroyed and the player gets a point
var collidedEntity = other.getBody().target
console.debug("collided with entity", collidedEntity.entityType)
// monsters could also collide with other monsters because they have a random speed - alternatively, collider categories could be used
if(collidedEntity.entityType === "tower") {
// remove the projectile entity
collidedEntity.removeEntity()
// remove the tower
removeEntity()
}
}
}// BoxCollider
ParallelAnimation {
running: true // all animations are started
NumberAnimation {
target: projectile
property: "x"
from: startX
to: goalX
duration: speed
easing.type: Easing.InCubic
}
NumberAnimation {
target: projectile
property: "y"
from: startY
to: goalY
duration: speed
easing.type: Easing.InCubic
}
NumberAnimation {
target: projectile
property: "scale"
to: 1.0
duration: speed
easing.type: Easing.InCubic
}
}
}
}
}
The app return errors
NumberAnimation: Cannot animate non-existent property “x”
NumberAnimation: Cannot animate non-existent property “y”
NumberAnimation: Cannot animate non-existent property “scale”
Moreover when it show the game screen, the AirBalloon was not showed and the CollisionBox is not right at the visual representation of balloon and arrow. What have I done wrongly?