Hello,
I am trying to make a simple Space-Shooter and can’t get the Bullets animated properly:
This is my Bullet QML File, with the animation.
bullet.qml
import QtQuick 2.0
import Felgo 3.0
EntityBase {
id: bulletEntity
entityType: "bullet"
poolingEnabled: true
Rectangle {
color:"transparent"
anchors.fill: parent
//debug info
//border.color: 'green'
Image {
id: bulletImage
smooth: false
source: "../../assets/img/bullet.png"
// set the size of the image to the one of the collider and not vice versa, because the physics properties depend on the collider size
anchors.fill: parent
}
// moves the entity to y position 0 within 2 seconds
NumberAnimation on y {
to: 0
duration: 2000
}
}
}
I am creating the bullets in my “Main.qml”, like that:
Scene {
id: scene
width: 480
height: 320
Rectangle {
color: "black"
anchors.fill: parent
//move the Ship according to the mouse position
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,
x: ship1.x + (ship1.width/2) - 7.5,
y: ship1.y - 12,
}
entityManager.createEntityFromUrlWithProperties(
Qt.resolvedUrl("entities/Bullet.qml"),
newEntityProperties);
}
}
}
It seems I am stuck here, I can’t really get a hold of the problem, I only could get Animations to work when using them directly in the scene via “manually created” entities:
Bullet {
x: 100
y: 100
width: 15
height: 20
numberAnimation on y {
to: 0
duration: 4000
}
}
Any idea what could be the problem in the above code sample?
Thanks in Advance.
-
This topic was modified 8 years ago by
Deathdragon.