diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2009-07-23 05:28:46 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2009-07-23 05:28:46 (GMT) |
commit | 1d1b32453519eb952438c734e21ae5ddf09e4966 (patch) | |
tree | 5db1593d0a2dd4f1fbee06875d114432eb572ae4 /demos/declarative/samegame | |
parent | f8dff7351ede7ec032947e8d5b6c3268485a1da5 (diff) | |
download | Qt-1d1b32453519eb952438c734e21ae5ddf09e4966.zip Qt-1d1b32453519eb952438c734e21ae5ddf09e4966.tar.gz Qt-1d1b32453519eb952438c734e21ae5ddf09e4966.tar.bz2 |
Move the mouse control of the game from the main file to the blocks
This allows for spin on hover - note that the code to spin back is in
there but not working at the moment.
Diffstat (limited to 'demos/declarative/samegame')
-rw-r--r-- | demos/declarative/samegame/SameGame.qml | 4 | ||||
-rw-r--r-- | demos/declarative/samegame/content/BoomBlock.qml | 5 | ||||
-rw-r--r-- | demos/declarative/samegame/content/FastBlock.qml | 7 | ||||
-rw-r--r-- | demos/declarative/samegame/content/SpinBlock.qml | 9 | ||||
-rw-r--r-- | demos/declarative/samegame/content/samegame.js | 8 |
5 files changed, 21 insertions, 12 deletions
diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml index 5e998e8..4edcf5c 100644 --- a/demos/declarative/samegame/SameGame.qml +++ b/demos/declarative/samegame/SameGame.qml @@ -20,10 +20,6 @@ Rect { anchors.fill: parent } - MouseRegion { id: gameMR; anchors.fill: parent; - onClicked: handleClick(mouseX, mouseY); - onPositionChanged: handleHover(mouseX, mouseY); - } } HorizontalLayout { anchors.top: gameCanvas.bottom diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index 9148e60..92ae3a4 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -9,6 +9,11 @@ Item { id:block x: Follow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } y: Follow { source: targetY; spring: 2; damping: 0.2 } + MouseRegion { + id: gameMR; anchors.fill: parent + onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); + } + Image { id: img source: { if(type == 0){ diff --git a/demos/declarative/samegame/content/FastBlock.qml b/demos/declarative/samegame/content/FastBlock.qml index 5149911..fb3a686 100644 --- a/demos/declarative/samegame/content/FastBlock.qml +++ b/demos/declarative/samegame/content/FastBlock.qml @@ -13,8 +13,11 @@ Rect { id:block opacity: 0 y: targetY x: targetX - //y: Behavior { NumberAnimation { properties:"y"; duration: 200 } } - //opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } } + + MouseRegion { + id: gameMR; anchors.fill: parent + onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); + } states: [ diff --git a/demos/declarative/samegame/content/SpinBlock.qml b/demos/declarative/samegame/content/SpinBlock.qml index 2597bfb..eaf48ad 100644 --- a/demos/declarative/samegame/content/SpinBlock.qml +++ b/demos/declarative/samegame/content/SpinBlock.qml @@ -16,6 +16,9 @@ Item { id:block "pics/gnome/greenStone.gif"; } paused: !selected + paused: Behavior { to: true; from: false; + NumberAnimation { properties:"currentFrame"; to:0; duration: 200} + } } opacity: 0 y: targetY @@ -23,6 +26,12 @@ Item { id:block y: Behavior { NumberAnimation { properties:"y"; duration: 200 } } x: Behavior { NumberAnimation { properties:"x"; duration: 200 } } opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } } + MouseRegion { + id: gameMR; anchors.fill: parent + onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); + onEntered: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); + onExited: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); + } states: [ diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index 91d97d5..6bcfd17 100644 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -50,10 +50,8 @@ var fillFound; var floodBoard; var lastHoveredIdx = -2 -function handleHover(x,y, btn) +function handleHover(xIdx,yIdx, btn) { - xIdx = Math.floor(x/tileSize); - yIdx = Math.floor(y/tileSize); if(index(xIdx, yIdx) == lastHoveredIdx) return; lastHoveredIdx = index(xIdx, yIdx); @@ -67,11 +65,9 @@ function handleHover(x,y, btn) //Could use the fillFound value to tell the player how many stones/points } -function handleClick(x,y) +function handleClick(xIdx,yIdx) { //NOTE: Be careful with vars named x,y - they can set to the calling object - xIdx = Math.floor(x/tileSize); - yIdx = Math.floor(y/tileSize); if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) return; if(board[index(xIdx, yIdx)] == null) |