summary history branches tags files
commit:63636a6a92ac3dde812d5a92588489284630a172
author:mrmekon
committer:mrmekon
date:Mon Mar 26 17:12:58 2012 -0400
parents:2050ee7473286da75cb343ea9a33f785886230ab
50% increase in frame rate by drawing level once on a background canvas, instead of redrawing each frame.
diff --git a/src/tempest_cljs/views/welcome.clj b/src/tempest_cljs/views/welcome.clj
line changes: +4/-1
index 2716165..493a433
--- a/src/tempest_cljs/views/welcome.clj
+++ b/src/tempest_cljs/views/welcome.clj
@@ -11,7 +11,10 @@
 (defpage "/tempest/:level" {:keys [level]}
   (common/site-layout
    (include-js "/tempest.js")
-   [:canvas#canv1 {:width "900" :height "900"}]
+   [:canvas#canv-bg {:width "900" :height "900"
+                     :style "position: absolute; z-index: 0;"}]
+   [:canvas#canv-fg {:width "900" :height "900"
+                     :style "position: absolute; z-index: 1;"}]
    [:p#fps "FPS 0.0"]
    (javascript-tag (str "tempest.canvasDraw(" (pr-str level) ");"))
    ))

diff --git a/tempest/tempest.cljs b/tempest/tempest.cljs
line changes: +6/-2
index f260ef2..8de6833
--- a/tempest/tempest.cljs
+++ b/tempest/tempest.cljs
@@ -786,7 +786,7 @@
   [context dims level]
   (doseq []
     (.clearRect context 0 0 (:width dims) (:height dims))
-    (draw-board context dims level)
+    ;;(draw-board context dims level)
     (draw-player context dims level (deref *player*))
     (draw-entities context dims level @*enemy-list*)
     (draw-entities context dims level @*projectile-list*)
@@ -855,11 +855,15 @@
   (let [document (dom/getDocument)
         timer (goog.Timer. 20)
         level (get levels/*levels* (- (js/parseInt level) 1))
-        canvas (dom/getElement "canv1")
+        canvas (dom/getElement "canv-fg")
         context (.getContext canvas "2d")
+        bgcanvas (dom/getElement "canv-bg")
+        bgcontext (.getContext bgcanvas "2d")
         handler (goog.events.KeyHandler. document)
         dims {:width (.-width canvas) :height (.-height canvas)}]
 
+    (draw-board bgcontext dims level)
+    
     (def *frame-count* (atom 0))
     (def *frame-time* (atom (goog.now)))