Squaby Demo
import QtQuick 2.0
import Felgo 4.0
import "../gameScene/hud"
EntityBase {
id: waypoint
entityType: "waypoint"
property variant prev
property variant next
poolingEnabled: true
onUsedFromPool: {
calculateRotationAndMirroring()
}
SingleSquabySprite {
id: sprite
translateToCenterAnchor: true
source: Qt.resolvedUrl("../../assets/img/steps/steps-4-corner-from-left-to-top.png")
}
Component.onCompleted: {
calculateRotationAndMirroring()
}
function calculateRotationAndMirroring() {
var fromLeft;
var fromRight;
var fromTop;
var fromBottom;
sprite.mirrorX = false;
if(prev.x < x) {
fromLeft = true;
} else if(prev.x > x) {
fromRight = true;
} else if(prev.y < y) {
fromTop = true;
} else if(prev.y > y) {
fromBottom = true;
}
var toLeft;
var toRight;
var toTop;
var toBottom;
if(next.x > x) {
toRight = true;
} else if(next.x < x) {
toLeft = true;
} else if(next.y > y) {
toBottom = true;
} else if(next.y < y) {
toTop = true;
}
if(fromLeft && toTop) {
waypoint.rotation = 0;
} else if(fromTop && toRight) {
waypoint.rotation = 90;
} else if(fromRight && toBottom) {
waypoint.rotation = 180;
} else if(fromBottom && toLeft) {
waypoint.rotation = 270;
} else {
sprite.mirrorX = true;
}
if(fromRight && toTop) {
waypoint.rotation = 0;
} else if(fromBottom && toRight) {
waypoint.rotation = 90;
} else if(fromLeft && toBottom) {
waypoint.rotation = 180;
} else if(fromTop && toLeft) {
waypoint.rotation = 270;
}