Skip to content

Instantly share code, notes, and snippets.

@psihy
Created December 6, 2012 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save psihy/4225738 to your computer and use it in GitHub Desktop.
Save psihy/4225738 to your computer and use it in GitHub Desktop.
enchant.js sample in BiwaScheme.
<!-- BiwaScheme 0.6.1 -->
<html>
<head>
<title>enchant.js sample in BiwaScheme</title>
</head>
<body>
<div id="enchant-stage" />
<script src="./enchant.js"></script>
<script src="./biwascheme.js">
(js-call (js-eval "enchant"))
(js-set! (js-eval "window") "onload" (js-closure (lambda ()
(let ((game (js-new "Game" 320 320)))
(js-set! game "fps" 24)
(js-invoke game "preload" "bear.png")
;; the images used in the game should be preloaded
(js-set! game "onload" (js-closure (lambda ()
(let ((bear (js-new "Sprite" 32 32)))
(js-set! bear "x" 8)
(js-set! bear "y" 8)
(js-set! bear "image" (js-ref (js-ref game "assets") "bear.png"))
(js-invoke bear "addEventListener" "enterframe" (js-closure (lambda (e)
;; check input from key on every frame
(if (js-ref (js-ref game "input") "right")
(js-set! bear "x" (+ (js-ref bear "x") 2)))
(if (js-ref (js-ref game "input") "left")
(js-set! bear "x" (- (js-ref bear "x") 2)))
(if (js-ref (js-ref game "input") "up")
(js-set! bear "y" (- (js-ref bear "y") 2)))
(if (js-ref (js-ref game "input") "down")
(js-set! bear "y" (+ (js-ref bear "y") 2))))))
;; add bear to rootScene (default scene)
(js-invoke (js-ref game "rootScene") "addChild" bear))
(js-set! (js-ref game "rootScene") "backgroundColor" #xffffff))))
(js-invoke game "start")))))
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment