0
\$\begingroup\$

Hi I recently created a javascript game, in this game, math random is used to pick a random shape.

The shapes are in strings, and the associated numbers within the string are then used to show a color.

Is there any way to replace the simple hex colors with an image?

For example:

else if (shape === "H"){
    return [[8,8,8],
            [8,8,8],
            [8,8,8]];

The "8" ties into the following string to get the #F10B38 color.

const color = [null,"#FF2D00","#FF9300","#51FF00","#00FF93","#0087FF","#4E49A7","#9649A7","#F10B38"];
\$\endgroup\$
3
  • 1
    \$\begingroup\$ I am not sure what you are trying to do. Is the return value in that first code snippet supposed to be a 3x3 bitmap where all 9 pixels are the color 8 (#F10B38)? Why not just load sprites as images? \$\endgroup\$ Commented Nov 22, 2020 at 17:04
  • \$\begingroup\$ yes so its a tetris style game, and the 3x3 block is now just a solid color. I was trying to change that from being a solid color to being an image, or maybe something a bit more stylish than a simple solid color \$\endgroup\$ Commented Nov 22, 2020 at 21:24
  • \$\begingroup\$ So what you actually want to ask is how to use images in Javascript? Are you using canvas or DOM to visualize your game? \$\endgroup\$ Commented Nov 22, 2020 at 22:05

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.