ChickenOutbreak2 Demo
import Felgo 4.0
import QtQuick 2.0
Item {
id: bgi
objectName: "parallaxScrollingBackgroundItem"
property string sourceImage: ""
property url filenameImage: ""
property string sourceImage2: ""
property url filenameImage2: ""
property alias image:mt1
property bool mirrorSecondImage: sourceImage2==""
property int __totalWidth: (mt1.width + mt2.width)*2*__inversRatio.x
property int __totalHeight: (mt1.height + mt2.height)*2*__inversRatio.y
property variant movementVelocity: Qt.point(0,0)
property variant ratio: Qt.point(1.0,1.0)
property variant __inversRatio: Qt.point(1/ratio.x,1/ratio.y)
property bool running: externalMovementAnimation ? externalMovementAnimation.target ? false : true : true
function resetBackgrounds() {
movingItem.x = 0
movingItem.y = 0
parallaxItem1.x = 0
parallaxItem1.y = 0
parallaxItem1.limiterX = mt1.width*1.5*__inversRatio.x
parallaxItem1.limiterY = mt1.height*1.5*__inversRatio.y
parallaxItem2.x = movementVelocity.x ? (movementVelocity.x>0 ? -mt1.width*__inversRatio.x : mt1.width*__inversRatio.x) : 0
parallaxItem2.y = movementVelocity.y ? (movementVelocity.y>0 ? -mt1.height*__inversRatio.y : mt1.height*__inversRatio.y) : 0
parallaxItem2.limiterX = (mt1.width+mt2.width*1.5)*__inversRatio.x
parallaxItem2.limiterY = (mt1.height+mt2.height*1.5)*__inversRatio.y
parallaxItem3.x = movementVelocity.x ? (movementVelocity.x>0 ? -(mt1.width+mt2.width)*__inversRatio.x : (mt1.width+mt2.width)*__inversRatio.x ) : 0
parallaxItem3.y = movementVelocity.y ? (movementVelocity.y>0 ? -(mt1.height+mt2.height)*__inversRatio.y : (mt1.height+mt2.height)*__inversRatio.y ) : 0
parallaxItem3.limiterX = (mt1.width*2.5+mt2.width)*__inversRatio.x
parallaxItem3.limiterY = (mt1.height*2.5+mt2.height)*__inversRatio.y
parallaxItem4.x = movementVelocity.x ? (movementVelocity.x>0 ? -(mt1.width*2+mt2.width)*__inversRatio.x : (mt1.width*2+mt2.width)*__inversRatio.x ) : 0
parallaxItem4.y = movementVelocity.y ? (movementVelocity.y>0 ? -(mt1.height*2+mt2.height)*__inversRatio.y : (mt1.height*2+mt2.height)*__inversRatio.y ) : 0
parallaxItem4.limiterX = (mt1.width*2.5+mt2.width*2)*__inversRatio.x
parallaxItem4.limiterY = (mt1.height*2.5+mt2.height*2)*__inversRatio.y
}
MovementAnimation {
target: movingItem
property: "x"
velocity: movementVelocity.x
running: bgi.running
}
MovementAnimation {
target: movingItem
property: "y"
velocity: movementVelocity.y
running: bgi.running
}
property variant externalMovementAnimation
Connections {
target: externalMovementAnimation ? externalMovementAnimation.target ? externalMovementAnimation.target : null : null
function onXChanged() {
movingItem.x = externalMovementAnimation.target.x
}
function onYChanged() {
movingItem.y = externalMovementAnimation.target.y
}
}
Item {
id: movingItem
onXChanged: {
if(typeof movementVelocity != "undefined" ) {
if(movementVelocity.x>0) {
if(x > parallaxItem1.limiterX) {
parallaxItem1.x -= __totalWidth
parallaxItem1.limiterX += __totalWidth
}
if(x > parallaxItem2.limiterX) {
parallaxItem2.x -= __totalWidth
parallaxItem2.limiterX += __totalWidth
}
if(x > parallaxItem3.limiterX) {
parallaxItem3.x -= __totalWidth
parallaxItem3.limiterX += __totalWidth
}
if(x > parallaxItem4.limiterX) {
parallaxItem4.x -= __totalWidth
parallaxItem4.limiterX += __totalWidth
}
} else {
if(x < parallaxItem1.limiterX*(-1)) {
parallaxItem1.x += __totalWidth
parallaxItem1.limiterX += __totalWidth
}
if(x < parallaxItem2.limiterX*(-1)) {
parallaxItem2.x += __totalWidth
parallaxItem2.limiterX += __totalWidth
}
if(x < parallaxItem3.limiterX*(-1)) {
parallaxItem3.x += __totalWidth
parallaxItem3.limiterX += __totalWidth
}
if(x < parallaxItem4.limiterX*(-1)) {
parallaxItem4.x += __totalWidth
parallaxItem4.limiterX += __totalWidth
}
}
}
}
onYChanged: {
if(typeof movementVelocity != "undefined" ) {
if(movementVelocity.y >0) {
if(y > parallaxItem1.limiterY) {
parallaxItem1.y -= __totalHeight
parallaxItem1.limiterY += __totalHeight
}
if(y > parallaxItem2.limiterY) {
parallaxItem2.y -= __totalHeight
parallaxItem2.limiterY += __totalHeight
}
if(y > parallaxItem3.limiterY) {
parallaxItem3.y -= __totalHeight
parallaxItem3.limiterY += __totalHeight
}
if(y > parallaxItem4.limiterY) {
parallaxItem4.y -= __totalHeight
parallaxItem4.limiterY += __totalHeight
}
} else {
if(y < parallaxItem1.limiterY*(-1)) {
parallaxItem1.y += __totalHeight
parallaxItem1.limiterY += __totalHeight
}
if(y < parallaxItem2.limiterY*(-1)) {
parallaxItem2.y += __totalHeight
parallaxItem2.limiterY += __totalHeight
}
if(y < parallaxItem3.limiterY*(-1)) {
parallaxItem3.y += __totalHeight
parallaxItem3.limiterY += __totalHeight
}
if(y < parallaxItem4.limiterY*(-1)) {
parallaxItem4.y += __totalHeight
parallaxItem4.limiterY += __totalHeight
}
}
}
}
ParallaxItem {
id: parallaxItem1
objectName: "parallaxItem"
ratio: bgi.ratio
property real limiterX: mt1.width*1.5*__inversRatio.x
property real limiterY: mt1.height*1.5*__inversRatio.y
SingleSpriteFromFile {
id: mt1
source: sourceImage
filename: filenameImage
translateToCenterAnchor: false
}
}
ParallaxItem {
id: parallaxItem2
objectName: "parallaxItem2"
ratio: bgi.ratio
x: movementVelocity.x ? (movementVelocity.x>0 ? -mt1.width*__inversRatio.x : mt1.width*__inversRatio.x) : 0
y: movementVelocity.y ? (movementVelocity.y>0 ? -mt1.height*__inversRatio.y : mt1.height*__inversRatio.y) : 0
property real limiterX: (mt1.width+mt2.width*1.5)*__inversRatio.x
property real limiterY: (mt1.height+mt2.height*1.5)*__inversRatio.y
SingleSpriteFromFile {
id: mt2
mirrorX: movementVelocity.x ? mirrorSecondImage : false
mirrorY: movementVelocity.y ? mirrorSecondImage : false
source: bgi.sourceImage2=="" ? bgi.sourceImage : bgi.sourceImage2
filename: bgi.filenameImage2=="" ? bgi.filenameImage : bgi.filenameImage2
translateToCenterAnchor: false
}
}
ParallaxItem {
id: parallaxItem3
objectName: "parallaxItem3"
ratio: bgi.ratio
x: movementVelocity.x ? (movementVelocity.x>0 ? -(mt1.width+mt2.width)*__inversRatio.x : (mt1.width+mt2.width)*__inversRatio.x ) : 0
y: movementVelocity.y ? (movementVelocity.y>0 ? -(mt1.height+mt2.height)*__inversRatio.y : (mt1.height+mt2.height)*__inversRatio.y ) : 0
property real limiterX: (mt1.width*2.5+mt2.width)*__inversRatio.x
property real limiterY: (mt1.height*2.5+mt2.height)*__inversRatio.y
SingleSpriteFromFile {
id: mt3
mirrorX: movementVelocity.x ? mirrorSecondImage : false
mirrorY: movementVelocity.y ? mirrorSecondImage : false
source: sourceImage
filename: filenameImage
translateToCenterAnchor: false
}
}
ParallaxItem {
id: parallaxItem4
objectName: "parallaxItem4"
ratio: bgi.ratio
x: movementVelocity.x ? (movementVelocity.x>0 ? -(mt1.width*2+mt2.width)*__inversRatio.x : (mt1.width*2+mt2.width)*__inversRatio.x ) : 0
y: movementVelocity.y ? (movementVelocity.y>0 ? -(mt1.height*2+mt2.height)*__inversRatio.y : (mt1.height*2+mt2.height)*__inversRatio.y ) : 0
property real limiterX: (mt1.width*2.5+mt2.width*2)*__inversRatio.x
property real limiterY: (mt1.height*2.5+mt2.height*2)*__inversRatio.y
SingleSpriteFromFile {
id: mt4
mirrorX: movementVelocity.x ? mirrorSecondImage : false
mirrorY: movementVelocity.y ? mirrorSecondImage : false
source: bgi.sourceImage2=="" ? bgi.sourceImage : bgi.sourceImage2
filename: bgi.filenameImage2=="" ? bgi.filenameImage : bgi.filenameImage2
translateToCenterAnchor: false
}