0

I'm working on a basic game for micro:bit just as a way to learn the technology, and I was hoping that one of the sprites would move in the direction of the compass.

Is there a way to do this?

Ryan
  • 123
  • 1
  • 12
  • 1
    Yes, this is possible. I'll assume you're talking about the "sprites" in the "game" library in the PXT editor / "Microsoft Block editor". From "Inputs" you'll need the `compass heading`. From the "Game" blocks, you should look at the blocks that initially appear as `item set x to 0` (or `item change x by 1`). You can modify the parameters of this latter type of block to set various attributes of a sprite, including the sprite's `direction`. This is the direction the sprite will move in, if you subsequently call `move by [amount]` for that sprite. – neillb Oct 30 '17 at 03:11
  • 1
    Be sure to state what you've already tried, if you need further help. Also, don't be afraid to both experiment with all the blocks in the editor, and read the help for each block (generally found by right-clicking the block and choosing `help`). – neillb Oct 30 '17 at 03:13
  • @neillb Thank you so much! Totally worked! – Ryan Nov 01 '17 at 03:31
  • Great! Consider writing up the essence of your solution and accepting it as your own answer! If you're using the "makecode" blocks editor, you can either right-click on the canvas and choose to capture a screenshot, or you can switch to javascript mode to get textual code which you can paste into your answer here (perhaps with a note explaining how people can translate this code back into blocks mode). – neillb Nov 02 '17 at 13:25

1 Answers1

2

picture of blocks

Use the "set" block to set the direction of the sprite to "compass heading (º)", then "move" the sprite a number of steps (in that direction). It might also be good to add "if on edge, bounce" block.
Thank you @neillb!

Ryan
  • 123
  • 1
  • 12