kornicameister
26th August 2011, 11:08
In my arkanoid like game I have bar and the ball which interacts with that bar, or rather which should interacts with the bar, because I have no idea how to deliver this.
I create both ball and bar in the my js script and place them in specific location on the grid (which is an item defined in main.qml). But know I am facing the problem
1. how to implement moving the ball with the bar at the same time if ball lies on the bar ? Currently bar is moved with drag.** properties set in Bar.qml, and it works great, because I can click and press the bar and it moves :), but how to inform the ball object to move also but only if it knows it lies on the bar
import QtQuick 1.0
import "logic/barMechanics.js" as BAR_MECHANIC
Rectangle {
id: bar
smooth: true
radius: 30
opacity: 0.9
gradient: Gradient {
GradientStop { position: 0.0 ; color: "red"}
GradientStop { position: 0.5 ; color: "yellow" }
GradientStop { position: 1.0 ; color: "black"}
}
signal clicked;
property bool sticky: false //this property if true means that ball does not bounce from bar but gets atteched to it
MouseArea { //!!!! <--- CUSTOMIZE IT ---> !!!!//
id: mouseArea
anchors.fill: bar
drag.target: bar
drag.axis: Drag.XAxis
drag.minimumX: 0
drag.maximumX: bar.parent.width - bar.width + 10
onPressed: BAR_MECHANIC.barMoving(); //sets anchor to undefined
}
}
import QtQuick 1.0
///there will be three possible bal (red,green,blue)
Item {
id: bal
property int type: 0
property bool nitro: false //ball goes fast
property bool destroyer: false //ball do not bounce from obstacles it goes throught them crushig em
property bool onBar: false
//setting the bal colour
Image {
id: bal_colour
anchors.fill: bal
smooth: true
source: {
if(type == 0){
return "resources/redBall.png";
}else if (type == 1){
return "resources/yellowBall.png";
}else{
return "resources/greenBall.png"
}
}
}
MouseArea {
id: ballMouseArea
anchors.fill: parent
}
}
any suggestion ? if any other code part is required let me know...
I create both ball and bar in the my js script and place them in specific location on the grid (which is an item defined in main.qml). But know I am facing the problem
1. how to implement moving the ball with the bar at the same time if ball lies on the bar ? Currently bar is moved with drag.** properties set in Bar.qml, and it works great, because I can click and press the bar and it moves :), but how to inform the ball object to move also but only if it knows it lies on the bar
import QtQuick 1.0
import "logic/barMechanics.js" as BAR_MECHANIC
Rectangle {
id: bar
smooth: true
radius: 30
opacity: 0.9
gradient: Gradient {
GradientStop { position: 0.0 ; color: "red"}
GradientStop { position: 0.5 ; color: "yellow" }
GradientStop { position: 1.0 ; color: "black"}
}
signal clicked;
property bool sticky: false //this property if true means that ball does not bounce from bar but gets atteched to it
MouseArea { //!!!! <--- CUSTOMIZE IT ---> !!!!//
id: mouseArea
anchors.fill: bar
drag.target: bar
drag.axis: Drag.XAxis
drag.minimumX: 0
drag.maximumX: bar.parent.width - bar.width + 10
onPressed: BAR_MECHANIC.barMoving(); //sets anchor to undefined
}
}
import QtQuick 1.0
///there will be three possible bal (red,green,blue)
Item {
id: bal
property int type: 0
property bool nitro: false //ball goes fast
property bool destroyer: false //ball do not bounce from obstacles it goes throught them crushig em
property bool onBar: false
//setting the bal colour
Image {
id: bal_colour
anchors.fill: bal
smooth: true
source: {
if(type == 0){
return "resources/redBall.png";
}else if (type == 1){
return "resources/yellowBall.png";
}else{
return "resources/greenBall.png"
}
}
}
MouseArea {
id: ballMouseArea
anchors.fill: parent
}
}
any suggestion ? if any other code part is required let me know...