Density 2.0 Alpha
Update: Density 3 is now available and I highly recommend using it instead! I might write a blogpost about it later.
It's Here!
The next generation of Density almost here and more powerful than ever and a brand new syntax!
Keep in mind that this is only an alpha and changes are to be expected. For any issues please submit one on our github.
First of all, lets look at the new drawable classes.
Rectangle
import Density, { Rectangle, Vec2 } from "./Density/Core.js";
// A red rectangle at (0,0) with the scale (100, 100)
Density.draw(
new Rectangle({pos: new Vec2(0,0), scale: new Vec2(100, 100), color: "red"})
);
Text
import Density, { Text, Vec2 } from "./Density/Core.js";
// A red text "Hello World!" at (0,0) with the scale (100, 100) (scale is required for culling)
Density.draw(
new Text({pos: new Vec2(0,0), scale: new Vec2(100, 100), color: "red", text: "Hello World!"})
);
Sprite (Using Asset Manager)
import Density, { Sprite, Vec2 } from "./Density/Core.js";
import assets from "./Density/Assets.js";
// Draw the asset "donut" at (0,0) with the scale (100, 100)
Density.draw(
new Sprite({pos: new Vec2(0,0), scale: new Vec2(100, 100), image: assets.donut})
);
That's great but I want a custom drawable!
import Density, { Drawable, Vec2 } from "./Density/Core.js";
class MyCustomDrawable extends Drawable {
render(item, modifiedX, modifiedY, modifiedW, modifiedH, ctx) {
// Draw whatever you want!
ctx.translate(modifiedX, modifiedY);
ctx.beginPath();
ctx.rect(0, 0, modifiedW, modifiedH);
ctx.fillStyle = item.color;
ctx.fill();
ctx.translate(-modifiedX, -modifiedY);
}
}
Updated on January 23, 2022