PDA

View Full Version : x and y setting in qml



vinayaka
19th October 2011, 09:35
//.js code



var component = Qt.createComponent("ball.qml")
var board = new Array(42)
var ply=0;
var currentItem = null
var score=0
var score1=0
var preferleft=0
var preferDia=0
var preferDia1=0
var preferUp=0
var preferleft1=0
var preferleftnew=0

function index(x, y) {
return 7*y+x
}
function column(x) {
return Math.floor((x+2) /77)
}

function handleClick(x,y) {

var col = column(x)

var row = -1;
for(var i = 0; i<=5;++i) {
if(board[index(col,i)] != null)
continue;
row = i;
break;
}
if(row==-1)
return;
clickHandler.enabled = false
var Itemzz = component.createObject(playGround)
Itemzz.x = col*(playGroundID.width/8.966)+playGroundID.width/31.117+col*(playGroundID.width/37.78)
Itemzz.y = (5-row)*(playGroundID.height/6.164)+playGroundID.height/23.684
Itemzz.c = col
Itemzz.r = row
Itemzz.type = ply
board[index(col,row)] = Itemzz
currentItem = Itemzz
if(ply!=0)
{
arrowBlack.opacity=0
arrowRed.opacity=1
playerImage.opacity=1
playerImage2.opacity=0
}
if(ply==0)
{
playerImage.opacity=0
playerImage2.opacity=1
arrowRed.opacity=0
arrowBlack.opacity=1
}

}

function deleteBlock() {
for (var i = 0; i <= 100; i++) {
if (board[i] != null)
board[i].destroy();
}
board=new Array(42);
}
function startNewGame() {
for (var i = 0; i <= 42; i++) {
if (board[i] != null)
{
board[i].y=1500;
deleteArray.push(board[i]);
}
}
delete deleteArray;
board=new Array(42);
}
function checkWin(col, row)
{
var type = board[index(col,row)].type
// playGround.tick()
ply = ply == 0 ? 1 : 0
var connected = 1
var connected1 = 1
var curCol = col
var connArr = new Array()
connArr.push(board[index(col,row)])
var connArrleft1 = new Array()
connArrleft1.push(board[index(col,row)])
var connArrDIA1 = new Array()
connArrDIA1.push(board[index(col,row)])
var connArrDIA = new Array()
connArrDIA.push(board[index(col,row)])
var connArrleftnew = new Array()
connArrleftnew.push(board[index(col,row)])
var ind;
// go left
for(var i = col-1; i>=0; i--) {
// playGround.tick()
ind = index(i,row)
if(board[ind]==null) break;
if(board[ind].type != type)
break;
connArrleft1.push(board[ind])
if(connArrleft1.length==4)
{
preferleft++;
if(ply!=0)
{
myParent.score++
}
else if(ply==0)
{
myParent.score1++
}
}
connected++;
}





//ball.qml



import Qt 4.7
import "core.js" as Logic

Item {
width:55
height: width
// width:gameCanvas.width/19
// height: width
property int type: 0
property int c
property int r
property int i:0
id:indu
Image {
id: img

source: if(type==0) {
"Normal/pics/M_CCblackChess.png"
} else if(type!=0)
{
"Normal/pics/M_CCredChess.png"
}

anchors.fill: parent
}

Behavior on y {

SequentialAnimation {
SmoothedAnimation{ velocity: 800 ;easing.type:Easing.InOutQuad }
ScriptAction {
script: playGround.check()
}
}
}
states: [
State {
name: "black"
PropertyChanges {
target: img
source:"Normal/pics/M_CCblackChessWin.png"
}
},
State {
name: "red"
PropertyChanges {
target: img
source:"Normal/pics/M_CCredChessWin.png"
}
}
]

property int transType: 1

transitions: [
Transition {
from: transType == 1 ? "*" : "none"
to: transType == 1 ? "*" : "none"
SequentialAnimation {
loops: Animation.Infinite
NumberAnimation { target:indu; properties: "width,height";from: indu.width+5;to:indu.width; duration: 400 }
NumberAnimation { target:indu;properties: "width,height";from:indu.width;to:indu.width+5; duration: 400 }
}
}
]


}



handleClick is a js function used to fall a ball on mouse click.playGround is a rectangle where the ball falls
its x and y position is set in js. So when I resized the window ball's x and y position donot get changed . How can I change that

is there any way to apply x and y position of the ball in qml instead of it in js

vinayaka
20th October 2011, 07:10
Can anyone help me in this problem.

When i resize the application both board and ball get resized:). but the x an y position is same ,donot get changed :confused: and the complete game looks UGLY. So please tell me to change the x and y position of the ball