//Sprite.hx
//import libraries
import kha.graphics2.Graphics;
import kha.math.FastMatrix3;
import kha.Image;
class Sprite{
public var img:Image;
public var ax = 0.5; //anchor x
public var ay = 0.5; //anchor y
public var r = 0.0; //rotation in rad
public var x = 0.0; //x pos
public var y = 0.0; //y pos
public var w = 100.0; //width
public var h = 100.0; //height
public var sx = 1.0; //scale
public var sy = 1.0 ; //scale
public function new(image:Image){
this.img = image;
this.w = this.img.width;
this.h = this.img.height;
}
public function update(){
//this.r+=1.0;
}
public function render(graphics:Graphics){
graphics.pushTransformation(FastMatrix3.translation(this.x,this.y));
graphics.rotate(this.degTorad(this.r),this.x,this.y);
//graphics.fillRect(-this.ax*this.w,-this.ay*this.h,this.w,this.h);
graphics.drawScaledImage(this.img,-this.ax*this.w,-this.ay*this.h,this.w*this.sx,this.h*this.sy);
graphics.popTransformation();
}
private function degTorad(deg:Float){
return deg*(Math.PI/180.0);
}
}