8000 fix logging uses; fix canvas not properly resized on setMode · GameJs/gamejs@902fce2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 902fce2

Browse files
committed
fix logging uses; fix canvas not properly resized on setMode
1 parent b8b0d56 commit 902fce2

File tree

7 files changed

+32
-25
lines changed

7 files changed

+32
-25
lines changed

doc/changelog

+10-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
* feature: add "debug" loglevel (even lower than "info")
1111
* feature: special gamejs.event callbacks for different types of events: onMouseMotion, onKeyDown, onFullscreen(),...
1212
* docs: overhaul all jsdoc with better text and more relevant examples
13-
* rename: move some utils.* modules into math.*
14-
* rename: gamejs.callback -> gamejs.utils.callback
15-
* rename: gamejs.worker.Worker -> gamejs.thread.Worker
16-
* rename: gamejs.tmx -> gamejs.tiledmap
13+
* rename:
14+
* gamejs.log/debug/info/error/fatal -> gamejs.logging.*
15+
* gamejs.tmx -> gamejs.tiledmap
16+
* gamejs.worker.Worker -> gamejs.thread.Worker
17+
* gamejs.Surface -> gamejs.graphics.Surface
18+
* gamejs.transform.* -> instance methods on gamejs.graphics.Surface
19+
* gamejs.draw.* -> static functions in gamejs.graphics
20+
* gamejs.utils.vectors -> gamejs.math.vectors
21+
* gamejs.utils.prng -> gamejs.math.random
22+
* gamejs.utils.matrix -> gamejs.math.matrix

examples/thread/main.js

-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ function main() {
3131
primes.push(event.prime);
3232
});
3333

34-
primeWorker.onError(function(data) {
35-
gamejs.log('worker threw an exception', data);
36-
});
37-
3834
// draw resutls
3935
gamejs.onTick(function(msDuration) {
4036
var yOffset = 56;

examples/thread/prime-worker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var handleEvent = function(data) {
3030
}
3131
};
3232
} else {
33-
gamejs.log('unknown todo');
33+
gamejs.logging.log('unknown todo');
3434
}
3535
}
3636
gamejs.ready(function() {

src/gamejs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var Callback = require('./gamejs/utils/callback').Callback;
77
*
88
* var gamejs = require('gamejs');
99
* ready(function() {
10-
* gamejs.log('I am ready!')
10+
* gamejs.logging.info('I am ready!')
1111
* });
1212
*
1313
* If you use images or sounds preload all assets with `gamejs.preload(['./files/foo.png'])` before calling `ready()`.

src/gamejs/display.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ var _flags = 0;
9393

9494
/**
9595
* @returns {document.Element} the canvas dom element
96+
* @ignore
9697
*/
97-
var getCanvas = function() {
98+
var getCanvas = exports._getCanvas = function() {
9899
var displayCanvas = document.getElementById(CANVAS_ID);
99100
if (!displayCanvas) {
100101
displayCanvas = document.createElement("canvas");
@@ -223,8 +224,9 @@ exports._hasFocus = function() {
223224
exports.setMode = function(dimensions, flags) {
224225
SURFACE = null;
225226
var canvas = getCanvas();
226-
canvas.width = dimensions[0];
227-
canvas.height = dimensions[1];
227+
canvas.width = canvas.clientWidth = dimensions[0];
228+
canvas.height = canvas.clientHeight = dimensions[1];
229+
228230
_flags = _flags || flags;
229231
// @ xbrowser firefox allows pointerlock only if fullscreen
230232
if (_flags & POINTERLOCK) {
@@ -243,7 +245,7 @@ exports.setMode = function(dimensions, flags) {
243245
document.addEventListener('webkitfullscreenchange', fullScreenChange, false);
244246
document.addEventListener('mozfullscreenchange', fullScreenChange, false);
245247
}
246-
return getSurface();
248+
return getSurface(dimensions);
247249
};
248250

249251
/**
@@ -279,13 +281,16 @@ exports._getCanvasOffset = function() {
279281
* Drawing on the Surface returned by `getSurface()` will draw on the screen.
280282
* @returns {gamejs.Surface} the display Surface
281283
*/
282-
var getSurface = exports.getSurface = function() {
284+
var getSurface = exports.getSurface = function(dimensions) {
283285
if (SURFACE === null) {
284286
var canvas = getCanvas();
285-
SURFACE = new Surface([canvas.clientWidth, canvas.clientHeight]);
287+
if (dimensions === undefined) {
288+
dimensions = [canvas.clientWidth, canvas.clientHeight];
289+
}
290+
SURFACE = new Surface(dimensions);
286291
SURFACE._canvas = canvas;
287-
SURFACE._canvas.width = canvas.clientWidth;
288-
SURFACE._canvas.height = canvas.clientHeight;
292+
SURFACE._canvas.width = dimensions[0];
293+
SURFACE._canvas.height = dimensions[1];
289294
SURFACE._context = canvas.getContext('2d');
290295
if (!(_flags & DISABLE_SMOOTHING)) {
291296
SURFACE._smooth();

src/gamejs/event.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ var Callback = require('./utils/callback').Callback;
99
*
1010
* gamejs.onEvent(function(event) {
1111
* if (event.type === gamejs.event.MOUSE_UP) {
12-
* gamejs.log(event.pos, event.button);
12+
* gamejs.logging.info(event.pos, event.button);
1313
* } else if (event.type === gamejs.event.KEY_UP) {
14-
* gamejs.log(event.key);
14+
* gamejs.logging.info(event.key);
1515
* }
1616
* });
1717
*
1818
* Or recieve more specific callbacks, e.g. only for `KEY\_UP` with `gamejs.event.onKeyUp()`:
1919
*
2020
* gamejs.onKeyUp(function(event) {
21-
* gamejs.log(event.key);
21+
* gamejs.logging.info(event.key);
2222
* });
2323
*
2424
* All events passed to your callback are instances of `gamejs.event.Event` and have a `type` property to help
@@ -56,9 +56,9 @@ var Callback = require('./utils/callback').Callback;
5656
* @example
5757
* gamejs.onEvent(function(event) {
5858
* if (event.type === gamejs.event.MOUSE_UP) {
59-
* gamejs.log(event.pos, event.button);
59+
* gamejs.logging.log(event.pos, event.button);
6060
* } else if (event.type === gamejs.event.KEY_UP) {
61-
* gamejs.log(event.key);
61+
* gamejs.logging.log(event.key);
6262
* }
6363
* });
6464
*
@@ -526,7 +526,7 @@ exports.init = function() {
526526

527527
// IE does not support addEventListener on document itself
528528
// FX events don't reach body if mouse outside window or on menubar
529-
var canvas = display.getSurface()._canvas;
529+
var canvas = display._getCanvas();
530530
document.addEventListener('mousedown', onMouseDown, false);
531531
document.addEventListener('mouseup', onMouseUp, false);
532532
document.addEventListener('keydown', onKeyDown, false);

src/gamejs/image.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ exports.preload = function(imgIdents) {
8181
_PRELOADING = false;
8282
}
8383
if (countLoaded % 10 === 0) {
84-
gamejs.log('gamejs.image: preloaded ' + countLoaded + ' of ' + countTotal);
84+
gamejs.logging.debug('gamejs.image: preloaded ' + countLoaded + ' of ' + countTotal);
8585
}
8686
}
8787

0 commit comments

Comments
 (0)
0