0
\$\begingroup\$

Currently I have a car game which I give points when a car touches the monster.Now extra to that I also wanted to change the color of the car or replace the car image with a different color car image when it is touching the monster.

So where I give point is

monsters.array.forEach(monster => {
            if(monster.isTouching(this)){
                monster.reset();
                monstersCaught += 1;
            }
        });

So now when I give point I also want to change the color of the car. Any help is appreciated.My pen for the game :pen

\$\endgroup\$
1
\$\begingroup\$

If you only have 1 car image, you can use javascript to give the car a css property hue-rotate() to change its color.

If you have multiple car images with different colors, you can simply change the src attribute using javascript to point to the new car image.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ I have multiple car images but I want to change the color when it hit the monster and change back to default after 5 seconds.Which way will be inappropriate hue-rotate() or change the src attribute \$\endgroup\$ – RKR Apr 13 '17 at 2:11
  • \$\begingroup\$ I also updated my pen. you can see where I have two different images and I want to switch to here_other image when the car hits the monster \$\endgroup\$ – RKR Apr 13 '17 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.