Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

splitting to use requirejs

  • Loading branch information...
commit ab90103b9ef823b95d28ad96b86cb62f232575ad 1 parent d4c1669
Andrew Henninger authored
Showing with 11 additions and 9 deletions.
  1. +1 −1  index.html
  2. +8 −6 js/background.js
  3. +2 −2 js/shuttle.js
2  index.html
View
@@ -2,7 +2,7 @@
<head>
<title>databyss/shuttle @ GitHub</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
- <script type="text/javascript" src="js/shuttle.js"></script>
+ <script data-main="js/shuttle" src="js/lib/require.js"></script>
<link rel="stylesheet" href="css/site.css" />
</head>
<body>
14 js/background.js
View
@@ -1,5 +1,5 @@
// background class from canvasbg project http://www.github.com/databyss/canvasbg
-function Background() {
+function Background(c, ctx) {
"use strict";
this.image = null;
this.scale = 1;
@@ -15,6 +15,8 @@ function Background() {
x: 0,
y: 0
};
+ this.c = c;
+ this.ctx = ctx;
}
// returns the drawn width of image
@@ -52,19 +54,19 @@ Background.prototype.update = function (ms) {
};
// render the background to the canvas
-Background.prototype.draw = function (c, ctx, gameWorld, clearScreen) {
+Background.prototype.draw = function (gameWorld, clearScreen) {
var xPoint, yPoint;
if (clearScreen) {
- ctx.clearRect(0, 0, c.width, c.height);
+ this.ctx.clearRect(0, 0, this.c.width, this.c.height);
}
if (this.image !== null) {
xPoint = this.scroll.x - ((gameWorld.xOffset * this.scrollFactor.x) % this.gameWidth()) - (this.gameWidth() * 2); // replace by scroll and scrollFactor
yPoint = this.scroll.y - ((gameWorld.yOffset * this.scrollFactor.y) % this.gameHeight()) - (this.gameHeight() * 2);
- while (xPoint < c.width) {
- while (yPoint < c.height) {
+ while (xPoint < this.c.width) {
+ while (yPoint < this.c.height) {
//TODO: if image is too big, only draw to edge of canvas
- ctx.drawImage(this.image, xPoint, yPoint, this.gameWidth(), this.gameHeight());
+ this.ctx.drawImage(this.image, xPoint, yPoint, this.gameWidth(), this.gameHeight());
yPoint += this.gameHeight();
}
yPoint = this.scroll.y - ((gameWorld.yOffset * this.scrollFactor.y) % this.gameHeight()) - (this.gameHeight() * 2);
4 js/shuttle.js
View
@@ -924,9 +924,9 @@ define(['imageloader', 'background'], function() {
if (this.backgrounds[i] !== null) {
if (i === 0) {
// clear bg on first one
- this.backgrounds[i].draw(c, ctx, this.levels[this.currentLevel], true);
+ this.backgrounds[i].draw(this.levels[this.currentLevel], true);
} else {
- this.backgrounds[i].draw(c, ctx, this.levels[this.currentLevel], false);
+ this.backgrounds[i].draw(this.levels[this.currentLevel], false);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.