summaryrefslogtreecommitdiffstats
path: root/demos/declarative/snake
diff options
context:
space:
mode:
Diffstat (limited to 'demos/declarative/snake')
-rw-r--r--demos/declarative/snake/content/pics/pause.pngbin0 -> 4327 bytes
-rw-r--r--demos/declarative/snake/content/snake.js4
-rw-r--r--demos/declarative/snake/snake.qml13
3 files changed, 14 insertions, 3 deletions
diff --git a/demos/declarative/snake/content/pics/pause.png b/demos/declarative/snake/content/pics/pause.png
new file mode 100644
index 0000000..056d97d
--- /dev/null
+++ b/demos/declarative/snake/content/pics/pause.png
Binary files differ
diff --git a/demos/declarative/snake/content/snake.js b/demos/declarative/snake/content/snake.js
index 2a99aa8..837b82a 100644
--- a/demos/declarative/snake/content/snake.js
+++ b/demos/declarative/snake/content/snake.js
@@ -39,7 +39,7 @@ function startNewGame()
return;
}
- if (heartbeat.running) {
+ if (activeGame) {
endGame();
startNewGameTimer.running = true;
return;
@@ -93,7 +93,7 @@ function startNewGame()
function endGame()
{
- heartbeat.running = false;
+ activeGame = false;
for(var i in snake)
snake[i].dying = true;
if (cookie) {
diff --git a/demos/declarative/snake/snake.qml b/demos/declarative/snake/snake.qml
index 5cbf1be..37e64ec 100644
--- a/demos/declarative/snake/snake.qml
+++ b/demos/declarative/snake/snake.qml
@@ -47,6 +47,7 @@ Rectangle {
id: screen;
SystemPalette { id: activePalette }
color: activePalette.window
+ property bool activeGame: false
property int gridSize : 34
property int margin: 4
@@ -75,6 +76,7 @@ Rectangle {
Timer {
id: heartbeat;
interval: heartbeatInterval;
+ running: activeGame && runtime.isActiveWindow
repeat: true
onTriggered: { Logic.move() }
}
@@ -94,7 +96,16 @@ Rectangle {
Timer {
id: startHeartbeatTimer;
interval: 1000 ;
- onTriggered: { state = "running"; heartbeat.running = true;}
+ onTriggered: { state = "running"; activeGame = true; }
+ }
+
+ Image{
+ id: pauseDialog
+ z: 1
+ source: "content/pics/pause.png"
+ anchors.centerIn: parent;
+ //opacity is deliberately not animated
+ opacity: gameActive && !runtime.isActiveWindow
}
Image {