Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 17, 2016
0 parents commit e0dbc1b
Show file tree
Hide file tree
Showing 18 changed files with 2,693 additions and 0 deletions.
Binary file added 9781430247432.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
181 changes: 181 additions & 0 deletions Chapter 1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
Listing 1-1.
//Player object creation
var player = new Sprite(32, 32);
player.image = game.assets['player.png'];
//Enemy character object creation
var enemy = new Sprite(32, 32);
enemy.image = game.assets['enemy.png'];
//Registration in the display object tree
var scene = game.currentScene;
scene.addChild(player);
scene.addChild(enemy);


Listing 1-2.
//player (character) object creation
var player = new Sprite(32, 32);
//handling of the character in each frame
player.addEventListener(Event.ENTER_FRAME, function() {
...
});
//handling touch events
player.addEventListener(Event.TOUCH_START, function(e) {
var x = e.localX;
var y = e.localY;
...
});


Listing 1-3.
document.write('<p>Hello, World!</p>');


Listing 1-4.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<title>HelloWorld</title>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<p>Hello World! This is the content part of an HTML page.</p>
</body>
</html>


Listing 1-5.
body { background-color: #DDDDDD; font: 30px sans-serif; }


Listing 1-6.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HelloWorld</title>
<script type="text/javascript" src="enchant.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>
<body>
</body>
</html>


Listing 1-7.
enchant();
var game;

window.onload = function(){
game = new Core(320, 320);
game.onload = function(){
sign = new Label();
sign.text = "Hello World!";
game.rootScene.addChild(sign);
};
game.start();
};


Listing 1-8.
enchant(); //the magic words that start enchant.js

window.onload = function() {
game = new Game();
game.onload = function() { //Prepares the game
hello = new Label("Hello,Bear"); //Create a new label with the words "Hello,Bear"
hello.x = 10; //Place the label 10 pixels to the right (0 will always be the left border)
hello.y = 150; //Place the label 150 pixels from the top (0 will always be the top border)
game.rootScene.addChild(hello); //Show the label on the active screen
}
game.start(); //Begin the game
}


Listing 1-9.
<script src='/static/enchant.js-latest/enchant.js'></script>
<script src='/code.9leap.js'></script>
<script src='main.js'></script>


Listing 1-10.
enchant();


Listing 1-11.
window.onload = function() {
//code to be executed
};


Listing 1-12.
var game = new Core(320, 320);


Source code for the HelloEnchant example at http://code.9leap.net/codes/show/21345:
//initialization of enchant.js
enchant();

//code written here will be executed once the HTML file is completely loaded
window.onload = function() {
//game object creation
var game = new Game(320, 320);

//image loading
game.preload('chara1.gif');

//execution once the image has loaded completely
game.onload = function() {
//Sprite creation
var bear = new Sprite(32, 32);
bear.image = game.assets['chara1.gif'];
bear.frame=4;

//frame loop to move the bear every frame
bear.addEventListener(Event.ENTER_FRAME, function() {
this.x += 3; //move by 3 pixels
});

//add the bear to the display object tree
game.rootScene.addChild(bear);
};
game.start();
};


Listing 1-20.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<style type="text/css">
body {
margin: 0;
}
</style>
<link rel='stylesheet' href='style.css' type='text/css'>
<script src='/static/enchant.js-latest/enchant.js'></script>
<script src='/code.9leap.js'></script>
<script src='main.js'></script>
<title>HelloEnchant</title>
</head>
<body>
</body>
</html>







0 comments on commit e0dbc1b

Please sign in to comment.