From ca9f7764982b90bb316ccca55dbd57edc5b40d4f Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 10 Nov 2009 13:14:52 +1000 Subject: Fix samegame tutorial 3 the js file hadn't been updated to avoid global vars Also updating a missed particles element --- .../tutorials/samegame/samegame3/samegame.js | 24 +++++++++++----------- .../qmlcomponent/samegame/BoomBlock.qml | 15 +++++++------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.js b/examples/declarative/tutorials/samegame/samegame3/samegame.js index 528a73c..38efb3b 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.js @@ -75,8 +75,8 @@ var floodBoard;//Set to 1 if the floodFill reaches off that node //![1] function handleClick(x,y) { - xIdx = Math.floor(x/gameCanvas.tileSize); - yIdx = Math.floor(y/gameCanvas.tileSize); + var xIdx = Math.floor(x/gameCanvas.tileSize); + var yIdx = Math.floor(y/gameCanvas.tileSize); if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) return; if(board[index(xIdx, yIdx)] == null) @@ -124,13 +124,13 @@ function shuffleDown() { //Fall down for(var xIdx=0; xIdx=0; yIdx--){ + var fallDist = 0; + for(var yIdx=maxY-1; yIdx>=0; yIdx--){ if(board[index(xIdx,yIdx)] == null){ fallDist += 1; }else{ if(fallDist > 0){ - obj = board[index(xIdx,yIdx)]; + var obj = board[index(xIdx,yIdx)]; obj.y += fallDist * gameCanvas.tileSize; board[index(xIdx,yIdx+fallDist)] = obj; board[index(xIdx,yIdx)] = null; @@ -139,14 +139,14 @@ function shuffleDown() } } //Fall to the left - fallDist = 0; - for(xIdx=0; xIdx 0){ - for(yIdx=0; yIdx=0; xIdx--) + var deservesBonus = true; + for(var xIdx=maxX-1; xIdx>=0; xIdx--) if(board[index(xIdx, maxY - 1)] != null) deservesBonus = false; if(deservesBonus) @@ -181,7 +181,7 @@ function floodMoveCheck(xIdx, yIdx, type) return false; if(board[index(xIdx, yIdx)] == null) return false; - myType = board[index(xIdx, yIdx)].type; + var myType = board[index(xIdx, yIdx)].type; if(type == myType) return true; return floodMoveCheck(xIdx + 1, yIdx, myType) || diff --git a/tests/benchmarks/declarative/qmlcomponent/samegame/BoomBlock.qml b/tests/benchmarks/declarative/qmlcomponent/samegame/BoomBlock.qml index a495cd0..723e62a 100644 --- a/tests/benchmarks/declarative/qmlcomponent/samegame/BoomBlock.qml +++ b/tests/benchmarks/declarative/qmlcomponent/samegame/BoomBlock.qml @@ -21,14 +21,16 @@ Item { id:block } } opacity: 0 - opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } } + opacity: Behavior { NumberAnimation { duration: 200 } } anchors.fill: parent } Particles { id: particles - width:1; height:1; anchors.centerIn: parent; opacity: 0 - lifeSpan: 700; lifeSpanDeviation: 600; count:0; streamIn: false - angle: 0; angleDeviation: 360; velocity: 100; velocityDeviation:30 + width:1; height:1; anchors.centerIn: parent; + emissionRate: 0; + lifeSpan: 700; lifeSpanDeviation: 600; + angle: 0; angleDeviation: 360; + velocity: 100; velocityDeviation:30; source: { if(type == 0){ "pics/redStar.png"; @@ -45,10 +47,9 @@ Item { id:block PropertyChanges { target: img; opacity: 1 } }, State{ name: "DeathState"; when: dying == true - PropertyChanges { target: particles; count: 50 } - PropertyChanges { target: particles; opacity: 1 } - PropertyChanges { target: particles; emitting: false } // i.e. emit only once + StateChangeScript { script: particles.burst(50); } PropertyChanges { target: img; opacity: 0 } + StateChangeScript { script: block.destroy(1000); } } ] } -- cgit v0.12