From bc9b27348124072aaed63dcd0dec6e9bf2b9e8c3 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Fri, 30 Apr 2021 01:06:31 +0000 Subject: [PATCH] Muni Rotates Things --- canvasUtils.js | 38 ++++++++++++++++++++++++++++++++------ objects.js | 18 ++++++++++++------ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/canvasUtils.js b/canvasUtils.js index d7f1e47..ede97b8 100644 --- a/canvasUtils.js +++ b/canvasUtils.js @@ -51,12 +51,24 @@ function drawSprite(x,y,sprite) { con.drawImage(sprite,x,y); } -function drawSpriteExt(x,y,sprite,w,h) { - con.drawImage(sprite,x,y,w*sprite.width,h*sprite.height); -} - -function drawSpritePart(x,y,sprite,spritex,spritey,spritew,spriteh,w,h) { - con.drawImage(sprite,spritex,spritey,spritew,spriteh,x,y,w,h); +function drawSpriteExt(x,y,sprite,w,h,image_angle) { + transformTranslate(x,y); + transformRotate(image_angle); + //con.globalCompositeOperation = 'multiply'; + con.drawImage(sprite,-(w*sprite.width)/2,-(h*sprite.height)/2,w*sprite.width,h*sprite.height); + /*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) { @@ -117,3 +129,17 @@ function drawCircle(x,y,r,outline) { 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(); +} \ No newline at end of file diff --git a/objects.js b/objects.js index 61b59fb..fd15648 100644 --- a/objects.js +++ b/objects.js @@ -10,23 +10,26 @@ class Object { this.image_angle=0; } stepEvent() { - + this.image_angle+=0.5; } drawEvent() { if (!this.visible) { return; } else { resetTransform(); - transformRotate(this.image_angle); drawSetColor("white"); 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(); } } mouseMoveEvent(e) { + } + touchMoveEvent(e) { + } keyPressEvent(e) { @@ -116,13 +119,16 @@ class DebugObj extends Object{ super.keyReleaseEvent(e); 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{ constructor(x,y,sprite) { super(sprite,true,x,y); - this.image_xscale=0.5; - this.image_yscale=0.5; } stepEvent() { super.stepEvent(); @@ -131,4 +137,4 @@ class IronPlate extends Object{ drawEvent() { super.drawEvent(); } -} +} \ No newline at end of file