Skip to content

Commit

Permalink
Add texture loading
Browse files Browse the repository at this point in the history
  • Loading branch information
una-ada committed Jun 4, 2021
1 parent 4c47617 commit fe4b7e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ let saturn = new Celestial({
physical: true,
mass: 5.683e26,
size: 3.06e8,
texture: "./img/celestial-saturn.svg",
}),
titan = new Celestial({
name: "Titan",
Expand Down
7 changes: 6 additions & 1 deletion js/modules/DOMRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default class DOMRenderer extends Renderer {
`${obj.size.x / this.scale}px`,
`${obj.size.y / this.scale}px`,
];
obj.collisions.length > 0 && (style.backgroundColor = "red");
}
);
}
Expand All @@ -65,6 +64,12 @@ export default class DOMRenderer extends Renderer {
// Clean up the name for adding into a CSS class
cleanName = obj.name.replace(/\s+/g, "-").toLowerCase();
element.classList.add(`gravity__${type}_${cleanName}`);
obj.texture &&
([
element.style.backgroundColor,
element.style.borderRadius,
element.style.backgroundImage,
] = [`transparent`, `0`, `url(${obj.texture})`]);
obj.element = element;
this.container.append(obj.element);
return element;
Expand Down

0 comments on commit fe4b7e0

Please sign in to comment.