Results 1 to 2 of 2

Thread: x and y setting in qml

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default x and y setting in qml

    //.js code

    Qt Code:
    1. var component = Qt.createComponent("ball.qml")
    2. var board = new Array(42)
    3. var ply=0;
    4. var currentItem = null
    5. var score=0
    6. var score1=0
    7. var preferleft=0
    8. var preferDia=0
    9. var preferDia1=0
    10. var preferUp=0
    11. var preferleft1=0
    12. var preferleftnew=0
    13.  
    14. function index(x, y) {
    15. return 7*y+x
    16. }
    17. function column(x) {
    18. return Math.floor((x+2) /77)
    19. }
    20.  
    21. function handleClick(x,y) {
    22.  
    23. var col = column(x)
    24.  
    25. var row = -1;
    26. for(var i = 0; i<=5;++i) {
    27. if(board[index(col,i)] != null)
    28. continue;
    29. row = i;
    30. break;
    31. }
    32. if(row==-1)
    33. return;
    34. clickHandler.enabled = false
    35. var Itemzz = component.createObject(playGround)
    36. Itemzz.x = col*(playGroundID.width/8.966)+playGroundID.width/31.117+col*(playGroundID.width/37.78)
    37. Itemzz.y = (5-row)*(playGroundID.height/6.164)+playGroundID.height/23.684
    38. Itemzz.c = col
    39. Itemzz.r = row
    40. Itemzz.type = ply
    41. board[index(col,row)] = Itemzz
    42. currentItem = Itemzz
    43. if(ply!=0)
    44. {
    45. arrowBlack.opacity=0
    46. arrowRed.opacity=1
    47. playerImage.opacity=1
    48. playerImage2.opacity=0
    49. }
    50. if(ply==0)
    51. {
    52. playerImage.opacity=0
    53. playerImage2.opacity=1
    54. arrowRed.opacity=0
    55. arrowBlack.opacity=1
    56. }
    57.  
    58. }
    59.  
    60. function deleteBlock() {
    61. for (var i = 0; i <= 100; i++) {
    62. if (board[i] != null)
    63. board[i].destroy();
    64. }
    65. board=new Array(42);
    66. }
    67. function startNewGame() {
    68. for (var i = 0; i <= 42; i++) {
    69. if (board[i] != null)
    70. {
    71. board[i].y=1500;
    72. deleteArray.push(board[i]);
    73. }
    74. }
    75. delete deleteArray;
    76. board=new Array(42);
    77. }
    78. function checkWin(col, row)
    79. {
    80. var type = board[index(col,row)].type
    81. // playGround.tick()
    82. ply = ply == 0 ? 1 : 0
    83. var connected = 1
    84. var connected1 = 1
    85. var curCol = col
    86. var connArr = new Array()
    87. connArr.push(board[index(col,row)])
    88. var connArrleft1 = new Array()
    89. connArrleft1.push(board[index(col,row)])
    90. var connArrDIA1 = new Array()
    91. connArrDIA1.push(board[index(col,row)])
    92. var connArrDIA = new Array()
    93. connArrDIA.push(board[index(col,row)])
    94. var connArrleftnew = new Array()
    95. connArrleftnew.push(board[index(col,row)])
    96. var ind;
    97. // go left
    98. for(var i = col-1; i>=0; i--) {
    99. // playGround.tick()
    100. ind = index(i,row)
    101. if(board[ind]==null) break;
    102. if(board[ind].type != type)
    103. break;
    104. connArrleft1.push(board[ind])
    105. if(connArrleft1.length==4)
    106. {
    107. preferleft++;
    108. if(ply!=0)
    109. {
    110. myParent.score++
    111. }
    112. else if(ply==0)
    113. {
    114. myParent.score1++
    115. }
    116. }
    117. connected++;
    118. }
    To copy to clipboard, switch view to plain text mode 

    //ball.qml

    Qt Code:
    1. import Qt 4.7
    2. import "core.js" as Logic
    3.  
    4. Item {
    5. width:55
    6. height: width
    7. // width:gameCanvas.width/19
    8. // height: width
    9. property int type: 0
    10. property int c
    11. property int r
    12. property int i:0
    13. id:indu
    14. Image {
    15. id: img
    16.  
    17. source: if(type==0) {
    18. "Normal/pics/M_CCblackChess.png"
    19. } else if(type!=0)
    20. {
    21. "Normal/pics/M_CCredChess.png"
    22. }
    23.  
    24. anchors.fill: parent
    25. }
    26.  
    27. Behavior on y {
    28.  
    29. SequentialAnimation {
    30. SmoothedAnimation{ velocity: 800 ;easing.type:Easing.InOutQuad }
    31. ScriptAction {
    32. script: playGround.check()
    33. }
    34. }
    35. }
    36. states: [
    37. State {
    38. name: "black"
    39. PropertyChanges {
    40. target: img
    41. source:"Normal/pics/M_CCblackChessWin.png"
    42. }
    43. },
    44. State {
    45. name: "red"
    46. PropertyChanges {
    47. target: img
    48. source:"Normal/pics/M_CCredChessWin.png"
    49. }
    50. }
    51. ]
    52.  
    53. property int transType: 1
    54.  
    55. transitions: [
    56. Transition {
    57. from: transType == 1 ? "*" : "none"
    58. to: transType == 1 ? "*" : "none"
    59. SequentialAnimation {
    60. loops: Animation.Infinite
    61. NumberAnimation { target:indu; properties: "width,height";from: indu.width+5;to:indu.width; duration: 400 }
    62. NumberAnimation { target:indu;properties: "width,height";from:indu.width;to:indu.width+5; duration: 400 }
    63. }
    64. }
    65. ]
    66.  
    67.  
    68. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by vinayaka; 19th October 2011 at 10:50.

  2. #2
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: x and y setting in qml

    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 and the complete game looks UGLY. So please tell me to change the x and y position of the ball

Similar Threads

  1. Setting buttons on top...
    By Shiva in forum Qt Programming
    Replies: 3
    Last Post: 15th October 2010, 12:35
  2. Dpi setting on MAC OS X
    By nikhil in forum Qt Programming
    Replies: 0
    Last Post: 26th August 2010, 08:55
  3. setting tab order on MAC
    By gren15 in forum Qt Tools
    Replies: 0
    Last Post: 3rd July 2009, 21:08
  4. help setting up qt4 ui from qt3
    By illuzioner in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2007, 04:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.