Last active
April 8, 2016 22:00
-
-
Save tonyromarock/e05ffb93bc526b500d5e33f452f3722c to your computer and use it in GitHub Desktop.
Creating a simple scene using enchant.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enchant(); | |
window.onload = function () { | |
var game = new Core(400, 320); | |
game.width = 400; | |
game.height = 320; | |
game.preload('http://ratherreadblog.com/runnerdemo/images/WalkingBlob.png', | |
'http://ratherreadblog.com/runnerdemo/images/window.png', | |
'http://ratherreadblog.com/runnerdemo/images/background.png'); | |
game.fps = 10; | |
var jumping = false; | |
game.onload = function () { | |
//----- Background ----- | |
var bg = new Sprite(400,320); | |
bg.image = game.assets['http://ratherreadblog.com/runnerdemo/images/background.png']; | |
game.rootScene.addChild(bg); | |
//----- Hero Character ----- | |
var hero = new Sprite(32,32); | |
hero.image = game.assets['http://ratherreadblog.com/runnerdemo/images/WalkingBlob.png']; | |
hero.frame = [0,1,2,3]; | |
hero.x = 180; | |
hero.y = 175; | |
game.rootScene.addChild(hero); | |
// make the hero jump when clicking the left mouse button | |
game.rootScene.on('touchstart', function(evt) { | |
if(!jumping) { | |
jumping = true; | |
hero.frame = 4; | |
hero.tl.moveBy(0,-20,7) | |
.moveBy(0,20,7); | |
hero.tl.delay(1).then(function() {hero.frame = [0,1,2,3]; | |
jumping = false;}); | |
} | |
}) | |
//----- Background Windows ----- | |
var bg_window = new Sprite(64,64); | |
bg_window.image = game.assets['http://ratherreadblog.com/runnerdemo/images/window.png']; | |
bg_window.x = 380; | |
bg_window.y = 80; | |
game.rootScene.addChild(bg_window); | |
bg_window.tl.moveTo(-50,80,60).moveTo(380,80,1).loop(); | |
}; | |
game.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment