Camera focuses on a specific tile?

I need to make it so that when a sprite overlaps a specific tile, the camera focuses on that tile.

1 Like

maybe this block will help
image

1 Like

Welcome to the forum! :smiley:

Disclaimer:
I’m kind of new to the whole helping people with coding problems thing so I apologize if this isn’t very helpful. I also don’t know your coding experience level/If you have prior coding knowledge, so I’m going to treat you like you know absolutely nothing about makecode so sorry about that too.

First off let’s take a look at the block @codinggrizzlybear suggested. you can find it in the scene category. To make the camera focus on that tile your code would look something like this:


first we have some general code that makes the tilemap, sprite, and scrolling in the “on start” block. then there is the “on sprite of kind player overlaps with tile at location” in that we have the previously mentioned “center camera at” block. you would put in sprite x and sprite y (form the sprite catagory) in the x and y number input spots, and drag the sprite from the "on sprite of kind player overlaps with tile at location over the mysprite variable. It should play something like this:
Microsoft MakeCode Arcade - Google Chrome 2024-05-21 11-39-30.mp4 [video-to-gif output image]
now this code is very unoptimized and it could defiantly be better.

Now lets look at the better version of this code. first your going to go into extensions. then your going to want to add the tile-util extension
image
once the editor has finished loading and the extension is added, your going to want to scroll all the way down and grab the “center camera on tilemap col num row num”
image
Then use it to replace the “center camera at” block. then grab the “location” from the “on sprite of kind player overlaps with tile at location” block and snap it to the “center camera” block’s “tilemap col num row num”
the code should now look something like this:


and now it plays something like this:
MicrosoftMakeCodeArcade-GoogleChrome2024-05-2113-07-17online-video-cutter.com-ezgif.com-video-to-gif-converter (1)
And the code (for the second version) is here:

I hope that this helps! feel free to ping me if you need anymore help or if I didn’t do a good job explaining. Also there are way more extensions then just the one’s in that menu. to add other one’s, just copy the GitHub link and paste it into the search bar. then it should pop up and you just need to click it to add it. you can find a list of community extensions on this cool website made by @UnsignedArduino here:

Good luck with your project!
-pecan4

3 Likes

thanks

1 Like