Muni Rotates Things

master 0.1
sigonasr2, Sig, Sigo 4 years ago
parent b8a03d651c
commit bc9b273481
  1. 38
      canvasUtils.js
  2. 18
      objects.js

@ -51,12 +51,24 @@ function drawSprite(x,y,sprite) {
con.drawImage(sprite,x,y); con.drawImage(sprite,x,y);
} }
function drawSpriteExt(x,y,sprite,w,h) { function drawSpriteExt(x,y,sprite,w,h,image_angle) {
con.drawImage(sprite,x,y,w*sprite.width,h*sprite.height); transformTranslate(x,y);
} transformRotate(image_angle);
//con.globalCompositeOperation = 'multiply';
function drawSpritePart(x,y,sprite,spritex,spritey,spritew,spriteh,w,h) { con.drawImage(sprite,-(w*sprite.width)/2,-(h*sprite.height)/2,w*sprite.width,h*sprite.height);
con.drawImage(sprite,spritex,spritey,spritew,spriteh,x,y,w,h); /*con.fillStyle = image_blend;
con.fillRect(0,0, w*sprite.width, h*sprite.height);
con.globalCompositeOperation = 'destination-atop';
con.drawImage(sprite,-(w*sprite.width)/2,-(h*sprite.height)/2,w*sprite.width,h*sprite.height);
con.globalCompositeOperation = 'normal';*/
resetTransform();
}
function drawSpritePart(x,y,sprite,spritex,spritey,spritew,spriteh,w,h,image_angle) {
transformTranslate(x,y);
transformRotate(image_angle);
con.drawImage(sprite,spritex,spritey,spritew,spriteh,-(w*spritew)/2,-(h*spriteh)/2,spritew*w,spriteh*h);
resetTransform();
} }
function drawText(x,y,text) { function drawText(x,y,text) {
@ -117,3 +129,17 @@ function drawCircle(x,y,r,outline) {
con.fill(); con.fill();
} }
} }
function toDataURL(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
}

@ -10,23 +10,26 @@ class Object {
this.image_angle=0; this.image_angle=0;
} }
stepEvent() { stepEvent() {
this.image_angle+=0.5;
} }
drawEvent() { drawEvent() {
if (!this.visible) { if (!this.visible) {
return; return;
} else { } else {
resetTransform(); resetTransform();
transformRotate(this.image_angle);
drawSetColor("white"); drawSetColor("white");
if (typeof this.sprite!=="undefined" && this.sprite!=null) { if (typeof this.sprite!=="undefined" && this.sprite!=null) {
drawSpriteExt(this.x,this.y,this.sprite,this.image_xscale,this.image_yscale); drawSpriteExt(this.x,this.y,this.sprite,this.image_xscale,this.image_yscale,this.image_angle);
//drawSpritePart(this.x,this.y,this.sprite,3,3,20,20,this.image_xscale,this.image_yscale,this.image_angle)
} }
resetTransform(); resetTransform();
} }
} }
mouseMoveEvent(e) { mouseMoveEvent(e) {
}
touchMoveEvent(e) {
} }
keyPressEvent(e) { keyPressEvent(e) {
@ -116,13 +119,16 @@ class DebugObj extends Object{
super.keyReleaseEvent(e); super.keyReleaseEvent(e);
this.lastMessage="Key Release Event: "+e.key+""; this.lastMessage="Key Release Event: "+e.key+"";
} }
touchMoveEvent(e) {
this.eventCount++;
super.touchMoveEvent(e);
this.lastMessage="Key Release Event: "+e.key+"";
}
} }
class IronPlate extends Object{ class IronPlate extends Object{
constructor(x,y,sprite) { constructor(x,y,sprite) {
super(sprite,true,x,y); super(sprite,true,x,y);
this.image_xscale=0.5;
this.image_yscale=0.5;
} }
stepEvent() { stepEvent() {
super.stepEvent(); super.stepEvent();
@ -131,4 +137,4 @@ class IronPlate extends Object{
drawEvent() { drawEvent() {
super.drawEvent(); super.drawEvent();
} }
} }
Loading…
Cancel
Save