| 434 |
} |
} |
| 435 |
entity.scene = this.scene; |
entity.scene = this.scene; |
| 436 |
entity.parent = this; |
entity.parent = this; |
| 437 |
|
if(typeof index != "number") { |
| 438 |
|
for(var i = 0; i < this.entities.length; i++) { |
| 439 |
|
if(this.entities[i] == index) { |
| 440 |
|
index = i; |
| 441 |
|
break; |
| 442 |
|
} |
| 443 |
|
} |
| 444 |
|
} |
| 445 |
this.entities.splice(index, 0, entity); |
this.entities.splice(index, 0, entity); |
| 446 |
entity.activate(); |
entity.activate(); |
| 447 |
}; |
}; |
| 955 |
this.changeMode(newMode); |
this.changeMode(newMode); |
| 956 |
} |
} |
| 957 |
}; |
}; |
| 958 |
Scene.prototype.createLayer = function (name) { |
Scene.prototype.createLayer = function (name, size) { |
| 959 |
for(var i in this.layers) { |
for(var i in this.layers) { |
| 960 |
if(!this.layers[i].hasBuffer()) { |
if(!this.layers[i].hasBuffer()) { |
| 961 |
this.layers[i].createBuffer(); |
this.layers[i].createBuffer(); |
| 962 |
} |
} |
| 963 |
} |
} |
| 964 |
this.layers[name] = new Layer(this); |
this.layers[name] = new Layer(this); |
| 965 |
|
if(size) { |
| 966 |
|
this.layers[name].width = size.width; |
| 967 |
|
this.layers[name].height = size.height; |
| 968 |
|
} |
| 969 |
this.layers[name].createBuffer(); |
this.layers[name].createBuffer(); |
| 970 |
this.layerCount++; |
this.layerCount++; |
| 971 |
return this.layers[name]; |
return this.layers[name]; |
| 1611 |
entity.draw(area, c); |
entity.draw(area, c); |
| 1612 |
if(entity.entities) { |
if(entity.entities) { |
| 1613 |
for(var i = 0; i < entity.entities.length; i++) { |
for(var i = 0; i < entity.entities.length; i++) { |
| 1614 |
this.renderEntity(new Area(0, 0, 0, 0), entity.entities[i], c); |
this.renderEntity(new Area(0, 0, entity.width, entity.height), entity.entities[i], c); |
| 1615 |
} |
} |
| 1616 |
} |
} |
| 1617 |
c.restore(); |
c.restore(); |
| 1720 |
for(var i in this.scene.layers) { |
for(var i in this.scene.layers) { |
| 1721 |
var layer = this.scene.layers[i]; |
var layer = this.scene.layers[i]; |
| 1722 |
if(layer.isUpdate()) { |
if(layer.isUpdate()) { |
| 1723 |
layer.context.clearRect(0, 0, this.game.width, this.game.height); |
layer.context.clearRect(0, 0, layer.width, layer.height); |
| 1724 |
this.renderParent(layer, layer.context); |
this.renderParent(layer, layer.context); |
| 1725 |
} |
} |
| 1726 |
this.bc.drawImage(layer.canvas, 0, 0); |
this.bc.drawImage(layer.canvas, 0, 0); |
| 1727 |
layer.reflected(); |
layer.reflected(); |
| 1728 |
} |
} |
| 1729 |
if(this.transferMode == RenderTransferMode.Flip) { |
if(this.bc != this.fc) { |
| 1730 |
this.flip(); |
this.fc.drawImage(this.buffer[1], 0, 0); |
| 1731 |
} else { |
} else { |
| 1732 |
if(this.bc != this.fc) { |
if(this.transferMode == RenderTransferMode.Flip) { |
| 1733 |
this.fc.drawImage(this.buffer[1], 0, 0); |
this.flip(); |
| 1734 |
} |
} |
| 1735 |
} |
} |
| 1736 |
} |
} |
| 2700 |
action.action_start = new Trigger(); |
action.action_start = new Trigger(); |
| 2701 |
action.action_tick.handle(action, function (e) { |
action.action_tick.handle(action, function (e) { |
| 2702 |
if(func.call(action, e)) { |
if(func.call(action, e)) { |
| 2703 |
_this.next(); |
_this.next(0); |
| 2704 |
} |
} |
| 2705 |
}); |
}); |
| 2706 |
this.add(action); |
this.add(action); |
| 3163 |
x: pos.x, |
x: pos.x, |
| 3164 |
y: pos.y |
y: pos.y |
| 3165 |
}); |
}); |
| 3166 |
this.p.push({ |
if(line) { |
| 3167 |
x: line.x, |
this.p.push({ |
| 3168 |
y: line.y |
x: line.x, |
| 3169 |
}); |
y: line.y |
| 3170 |
this.width = line.x; |
}); |
| 3171 |
this.height = line.y; |
this.updateSize(); |
| 3172 |
|
} |
| 3173 |
if(color) { |
if(color) { |
| 3174 |
this.setColor(color); |
this.setColor(color); |
| 3175 |
} |
} |
| 3177 |
this.setLineWidth(width); |
this.setLineWidth(width); |
| 3178 |
} |
} |
| 3179 |
} |
} |
| 3180 |
|
Line.prototype.updateSize = function () { |
| 3181 |
|
var min = { |
| 3182 |
|
x: this.p[0].x, |
| 3183 |
|
y: this.p[0].y |
| 3184 |
|
}; |
| 3185 |
|
var max = { |
| 3186 |
|
x: this.p[0].x, |
| 3187 |
|
y: this.p[0].y |
| 3188 |
|
}; |
| 3189 |
|
for(var i = 1; i < this.p.length; i++) { |
| 3190 |
|
var x = this.p[0].x + this.p[i].x; |
| 3191 |
|
var y = this.p[0].y + this.p[i].y; |
| 3192 |
|
if(min.x > x) { |
| 3193 |
|
min.x = x; |
| 3194 |
|
} else { |
| 3195 |
|
if(max.x < x) { |
| 3196 |
|
max.x = x; |
| 3197 |
|
} |
| 3198 |
|
} |
| 3199 |
|
if(min.y > y) { |
| 3200 |
|
min.y = y; |
| 3201 |
|
} else { |
| 3202 |
|
if(max.y < y) { |
| 3203 |
|
max.y = y; |
| 3204 |
|
} |
| 3205 |
|
} |
| 3206 |
|
} |
| 3207 |
|
this.width = max.x - min.x; |
| 3208 |
|
this.height = max.y - min.y; |
| 3209 |
|
}; |
| 3210 |
Line.prototype.setColor = function (color) { |
Line.prototype.setColor = function (color) { |
| 3211 |
this.setDrawOption("strokeStyle", color); |
this.setDrawOption("strokeStyle", color); |
| 3212 |
return this; |
return this; |
| 3214 |
Line.prototype.getColor = function () { |
Line.prototype.getColor = function () { |
| 3215 |
return this.getDrawOption("strokeStyle"); |
return this.getDrawOption("strokeStyle"); |
| 3216 |
}; |
}; |
| 3217 |
|
Line.prototype.setFillColor = function (color) { |
| 3218 |
|
this.setDrawOption("fillStyle", color); |
| 3219 |
|
return this; |
| 3220 |
|
}; |
| 3221 |
|
Line.prototype.getFillColor = function () { |
| 3222 |
|
return this.getDrawOption("fillStyle"); |
| 3223 |
|
}; |
| 3224 |
Line.prototype.setLineWidth = function (width) { |
Line.prototype.setLineWidth = function (width) { |
| 3225 |
this.setDrawOption("lineWidth", width); |
this.setDrawOption("lineWidth", width); |
| 3226 |
return this; |
return this; |
| 3249 |
Line.prototype.getMiterLimit = function () { |
Line.prototype.getMiterLimit = function () { |
| 3250 |
return this.getDrawOption("miterLimit"); |
return this.getDrawOption("miterLimit"); |
| 3251 |
}; |
}; |
| 3252 |
Line.prototype.addLine = function (line) { |
Line.prototype.setFill = function (fill, color, closePath, stroke) { |
| 3253 |
|
this.fill = fill; |
| 3254 |
|
this.setFillColor(color); |
| 3255 |
|
if(closePath !== undefined) { |
| 3256 |
|
this.closePath = closePath; |
| 3257 |
|
} |
| 3258 |
|
if(stroke !== undefined) { |
| 3259 |
|
this.stroke = stroke; |
| 3260 |
|
} |
| 3261 |
|
return this; |
| 3262 |
|
}; |
| 3263 |
|
Line.prototype.addLine = function (line, y) { |
| 3264 |
|
if(arguments.length == 2) { |
| 3265 |
|
line = { |
| 3266 |
|
x: line, |
| 3267 |
|
y: y |
| 3268 |
|
}; |
| 3269 |
|
} |
| 3270 |
this.p.push(line); |
this.p.push(line); |
| 3271 |
|
this.updateSize(); |
| 3272 |
|
return this; |
| 3273 |
|
}; |
| 3274 |
|
Line.prototype.addQuadraticLine = function (cp, p) { |
| 3275 |
|
var qp; |
| 3276 |
|
if(arguments.length == 4) { |
| 3277 |
|
qp = { |
| 3278 |
|
cp1x: arguments[0], |
| 3279 |
|
cp1y: arguments[1], |
| 3280 |
|
x: arguments[2], |
| 3281 |
|
y: arguments[3] |
| 3282 |
|
}; |
| 3283 |
|
} else { |
| 3284 |
|
if(arguments.length == 2) { |
| 3285 |
|
qp = { |
| 3286 |
|
cp1x: cp.x, |
| 3287 |
|
cp1y: cp.y, |
| 3288 |
|
x: p.x, |
| 3289 |
|
y: p.y |
| 3290 |
|
}; |
| 3291 |
|
} else { |
| 3292 |
|
qp = cp; |
| 3293 |
|
} |
| 3294 |
|
} |
| 3295 |
|
this.p.push(qp); |
| 3296 |
|
this.updateSize(); |
| 3297 |
|
return this; |
| 3298 |
|
}; |
| 3299 |
|
Line.prototype.addBezierLine = function (cp1, cp2, p) { |
| 3300 |
|
var bp; |
| 3301 |
|
if(arguments.length == 6) { |
| 3302 |
|
bp = { |
| 3303 |
|
cp1x: arguments[0], |
| 3304 |
|
cp1y: arguments[1], |
| 3305 |
|
cp2x: arguments[2], |
| 3306 |
|
cp2y: arguments[3], |
| 3307 |
|
x: arguments[4], |
| 3308 |
|
y: arguments[5] |
| 3309 |
|
}; |
| 3310 |
|
} else { |
| 3311 |
|
if(arguments.length == 3) { |
| 3312 |
|
bp = { |
| 3313 |
|
cp1x: cp1.x, |
| 3314 |
|
cp1y: cp1.y, |
| 3315 |
|
cp2x: cp2.x, |
| 3316 |
|
cp2y: cp2.y, |
| 3317 |
|
x: p.x, |
| 3318 |
|
y: p.y |
| 3319 |
|
}; |
| 3320 |
|
} else { |
| 3321 |
|
bp = cp1; |
| 3322 |
|
} |
| 3323 |
|
} |
| 3324 |
|
this.p.push(bp); |
| 3325 |
|
this.updateSize(); |
| 3326 |
|
return this; |
| 3327 |
|
}; |
| 3328 |
|
Line.prototype.addArc = function (p, p2, radius) { |
| 3329 |
|
var ap; |
| 3330 |
|
if(arguments.length == 5) { |
| 3331 |
|
ap = { |
| 3332 |
|
x: arguments[0], |
| 3333 |
|
y: arguments[1], |
| 3334 |
|
x2: arguments[2], |
| 3335 |
|
y2: arguments[3], |
| 3336 |
|
radius: arguments[4] |
| 3337 |
|
}; |
| 3338 |
|
} else { |
| 3339 |
|
if(arguments.length == 3) { |
| 3340 |
|
ap = { |
| 3341 |
|
x: p.x, |
| 3342 |
|
y: p.y, |
| 3343 |
|
x2: p2.x, |
| 3344 |
|
y2: p2.y, |
| 3345 |
|
radius: radius |
| 3346 |
|
}; |
| 3347 |
|
} else { |
| 3348 |
|
ap = p; |
| 3349 |
|
} |
| 3350 |
|
} |
| 3351 |
|
this.p.push(ap); |
| 3352 |
|
this.updateSize(); |
| 3353 |
|
}; |
| 3354 |
|
Line.prototype.add = function () { |
| 3355 |
|
if(arguments.length == 1) { |
| 3356 |
|
return this.addLine.apply(this, arguments); |
| 3357 |
|
} |
| 3358 |
|
if(arguments.length == 2) { |
| 3359 |
|
return this.addLine.apply(this, arguments); |
| 3360 |
|
} |
| 3361 |
|
if(arguments.length == 3) { |
| 3362 |
|
return this.addLine.apply(this, arguments); |
| 3363 |
|
} |
| 3364 |
|
throw "invalid arguments"; |
| 3365 |
}; |
}; |
| 3366 |
Line.prototype.draw = function (area, context) { |
Line.prototype.draw = function (area, context) { |
| 3367 |
context.beginPath(); |
context.beginPath(); |
| 3368 |
context.moveTo(0, 0); |
context.moveTo(0, 0); |
| 3369 |
for(var i = 1; i < this.p.length; i++) { |
for(var i = 1; i < this.p.length; i++) { |
| 3370 |
context.lineTo(this.p[i].x, this.p[i].y); |
var p = this.p[i]; |
| 3371 |
|
if(p.cp2x !== undefined) { |
| 3372 |
|
context.bezierCurveTo(p.cp1x, p.cp1y, p.cp2x, p.cp2y, p.x, p.y); |
| 3373 |
|
} else { |
| 3374 |
|
if(p.cp1x !== undefined) { |
| 3375 |
|
context.quadraticCurveTo(p.cp1x, p.cp1y, p.x, p.y); |
| 3376 |
|
} else { |
| 3377 |
|
if((this.p[i]).radius !== undefined) { |
| 3378 |
|
var ap = this.p[i]; |
| 3379 |
|
context.arcTo(ap.x, ap.y, ap.x2, ap.y2, ap.radius); |
| 3380 |
|
} else { |
| 3381 |
|
context.lineTo(p.x, p.y); |
| 3382 |
|
} |
| 3383 |
|
} |
| 3384 |
|
} |
| 3385 |
|
} |
| 3386 |
|
if(this.closePath) { |
| 3387 |
|
context.closePath(); |
| 3388 |
|
} |
| 3389 |
|
if(this.fill) { |
| 3390 |
|
context.fill(); |
| 3391 |
|
if(this.stroke) { |
| 3392 |
|
context.stroke(); |
| 3393 |
|
} |
| 3394 |
|
} else { |
| 3395 |
|
context.stroke(); |
| 3396 |
} |
} |
|
context.stroke(); |
|
| 3397 |
}; |
}; |
| 3398 |
return Line; |
return Line; |
| 3399 |
})(E); |
})(E); |