(https://makecode.com/_bwRV4yJqjLHi)
I’m having a hard time making my enemies face the direction that they are moving. Only one will face to the left when moving left. Anyone have any insight?
I included a link to my game.
Thank you!
(https://makecode.com/_bwRV4yJqjLHi)
I’m having a hard time making my enemies face the direction that they are moving. Only one will face to the left when moving left. Anyone have any insight?
I included a link to my game.
Thank you!
Welcome, @LukaBakio !
Let’s focus on this code:
Your variable Bumper
only points to one sprite - the last Bumper that was created. Instead, you want to work on all Bumpers. You need a loop for that:
Each time the code inside of the for element
loop runs, value
(called the loop variable) will change and point to a different Enemy
sprite. (In your game, value
will change to each of your Bumper sprites.) So, inside of the for element
loop, be sure to use the loop variable and not your Bumper
variable.
Give it a try! If you get stuck, reveal the spoiler below for my version of the code.
Version 1
This is similar to your version of the code:
You’ll probably get some flicker, though. Reveal the next spoiler for a version that should reduce flicker.
Version 2
This version should have less flicker:
Besides doing the image flip manually, you could try an extension that riknoll wrote. Take a look at these two forum threads:
Make my enemy sprite face the right direction? - Arcade / Help - Microsoft MakeCode
If you are not familiar with using extensions, then take a look at the Simple Extensions tutorial. You can find it in the Tutorials section on the MakeCode Arcade home screen. (Scroll to the right to find it.)
Thanks so much! Huge help!