| 1147 |
function Resource() { |
function Resource() { |
| 1148 |
this.requests = []; |
this.requests = []; |
| 1149 |
this.loaded = new Trigger(); |
this.loaded = new Trigger(); |
| 1150 |
this.images = { |
this.clear(); |
|
}; |
|
|
this.scripts = { |
|
|
}; |
|
|
this.sounds = { |
|
|
}; |
|
| 1151 |
this.loaders = { |
this.loaders = { |
| 1152 |
}; |
}; |
| 1153 |
this.loaders["js"] = new ScriptResourceLoader(this); |
this.loaders["js"] = new ScriptResourceLoader(this); |
| 1165 |
return Resource.instance; |
return Resource.instance; |
| 1166 |
})(); |
})(); |
| 1167 |
}; |
}; |
| 1168 |
|
Resource.prototype.clear = function () { |
| 1169 |
|
this.images = { |
| 1170 |
|
}; |
| 1171 |
|
this.scripts = { |
| 1172 |
|
}; |
| 1173 |
|
this.sounds = { |
| 1174 |
|
}; |
| 1175 |
|
}; |
| 1176 |
Resource.prototype.get = function (name) { |
Resource.prototype.get = function (name) { |
| 1177 |
return this.images[name]; |
return this.images[name]; |
| 1178 |
}; |
}; |
| 1374 |
this.y = 0; |
this.y = 0; |
| 1375 |
this.width = width; |
this.width = width; |
| 1376 |
this.height = height; |
this.height = height; |
| 1377 |
|
this.srcWidth = width; |
| 1378 |
|
this.srcHeight = height; |
| 1379 |
this.image = image; |
this.image = image; |
| 1380 |
this.sep = Math.floor(this.image.width / this.width); |
this.sep = Math.floor(this.image.width / this.width); |
| 1381 |
this.frame = [ |
this.frame = [ |
| 1384 |
this.fno = 0; |
this.fno = 0; |
| 1385 |
} |
} |
| 1386 |
Sprite.prototype.draw = function (context) { |
Sprite.prototype.draw = function (context) { |
| 1387 |
context.drawImage(this.image, (this.frame[this.fno] % this.sep) * this.width, Math.floor(this.frame[this.fno] / this.sep) * this.height, this.width, this.height, 0, 0, this.width, this.height); |
context.drawImage(this.image, (this.frame[this.fno] % this.sep) * this.srcWidth, Math.floor(this.frame[this.fno] / this.sep) * this.srcHeight, this.srcWidth, this.srcHeight, 0, 0, this.width, this.height); |
| 1388 |
}; |
}; |
| 1389 |
Sprite.prototype.refresh = function () { |
Sprite.prototype.refresh = function () { |
| 1390 |
if(this.image instanceof HTMLCanvasElement) { |
if(this.image instanceof HTMLCanvasElement) { |
| 2532 |
BufferedRenderer.prototype.clear = function () { |
BufferedRenderer.prototype.clear = function () { |
| 2533 |
this.c.clearRect(0, 0, this.size.width, this.size.height); |
this.c.clearRect(0, 0, this.size.width, this.size.height); |
| 2534 |
}; |
}; |
| 2535 |
BufferedRenderer.prototype.createImage = function (area, distArea) { |
BufferedRenderer.prototype.createImage = function (area, distArea, canvasSize) { |
| 2536 |
if(!area) { |
if(!area) { |
| 2537 |
area = { |
area = { |
| 2538 |
x: 0, |
x: 0, |
| 2549 |
height: area.height |
height: area.height |
| 2550 |
}; |
}; |
| 2551 |
} |
} |
| 2552 |
var canvas = window.createCanvas(area.width, area.height); |
if(!canvasSize) { |
| 2553 |
|
canvasSize = area; |
| 2554 |
|
} |
| 2555 |
|
var canvas = window.createCanvas(canvasSize.width, canvasSize.height); |
| 2556 |
var context = canvas.getContext("2d"); |
var context = canvas.getContext("2d"); |
| 2557 |
context.drawImage(this.buffer, area.x, area.y, area.width, area.height, distArea.x, distArea.y, distArea.width, distArea.height); |
context.drawImage(this.buffer, area.x, area.y, area.width, area.height, distArea.x, distArea.y, distArea.width, distArea.height); |
| 2558 |
if(this.filter) { |
if(this.filter) { |
| 2559 |
this.applyFilter(context, area); |
this.applyFilter(context, distArea); |
| 2560 |
} |
} |
| 2561 |
return canvas; |
return canvas; |
| 2562 |
}; |
}; |
| 2563 |
BufferedRenderer.prototype.createSprite = function (area, distArea) { |
BufferedRenderer.prototype.createSprite = function (area, distArea, canvasSize) { |
| 2564 |
if(!area) { |
if(!area) { |
| 2565 |
area = { |
area = { |
| 2566 |
x: 0, |
x: 0, |
| 2577 |
height: area.height |
height: area.height |
| 2578 |
}; |
}; |
| 2579 |
} |
} |
| 2580 |
return new Sprite(area.width, area.height, this.createImage(area, distArea)); |
return new Sprite(area.width, area.height, this.createImage(area, distArea, canvasSize)); |
| 2581 |
}; |
}; |
| 2582 |
BufferedRenderer.prototype.applyFilter = function (c, size) { |
BufferedRenderer.prototype.applyFilter = function (c, size) { |
| 2583 |
var imageData = c.getImageData(0, 0, size.width, size.height); |
var imageData = c.getImageData(0, 0, size.width, size.height); |