CreateJS facade types for Scala.js
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
project
src/main/scala/com/scalawarrior/scalajs/createjs
.gitignore
LICENSE
README.md
build.sbt
sbt-launch-0.13.8.jar
sbt.bat
sbt.sh

README.md

scalajs-createjs

Static types for the CreateJS API for Scala.js programs.

Usage

Add the following to your sbt build definition:

resolvers += "amateras-repo" at "http://amateras.sourceforge.jp/mvn/"

libraryDependencies += "com.scalawarrior" %%% "scalajs-createjs" % "0.0.2"

and add following import statement to the head of your Scala.js program:

import com.scalawarrior.scalajs.createjs._

then enjoy CreateJS in Scala.js!

// Declare the stage
val stage = new Stage("demoCanvas")
val w = stage.canvas.width
val h = stage.canvas.height

// Define images
val manifest = js.Array(
  js.Dictionary("src" -> "background.png", "id" -> "background"),
  js.Dictionary("src" -> "knight.png", "id" -> "knight")
)

// Pre-load images
val loader = new LoadQueue(false)
loader.addEventListener("complete", (e: Object) => {
  // Assemble shapes on the stage
  val background = new Shape()
  background.graphics.beginBitmapFill(loader.getResult("background")).drawRect(0, 0, w, h)

  var spriteSheet = new SpriteSheet(js.Dictionary(
    "framerate" -> 30,
    "images"    -> js.Array(loader.getResult("knight")),
    "frames"    -> js.Dictionary("regX" -> -70, "height" -> 88, "count" -> 64, "regY" -> -60, "width" -> 74)
  ))
  val knight = new Sprite(spriteSheet);

  stage.addChild(background, knight);
  stage.update();
  true
})
loader.loadManifest(manifest)