center Camera At

Center the camera view at a location in the scene.

00center camera at xy
JavaScript
function scene.centerCameraAt(x: number, y: number): void;
Python
def scene.center_camera_at(x: number, y: number): None

The size of your scene might be larger that the screen size. To move a part of the scene into the view of the screen, you can set the camera view to center at a location in the scene.

Parameters

  • x: a number that’s the horizontal location of the scene to center the camera view at.
  • y: a number that’s the vertical location of the scene to centere the camera view at.

Example

Make a tile map that’s 1.5 times the size of the screen. Draw a “X” pattern in the scene with tiles. Randomly center the camera view to each corner of the scene.

50003pick randomtocorner0=corner1=corner2=00center camera at xysceneX1-0center camera at xy0sceneY1-center camera at xysceneX1-sceneY1-center camera at xyifthenelse ifthenelse ifthenelsesetcornertoon game update everymsscreen width3×2/screen height3×2/sceneXsceneX8remainder of/-sceneYsceneY8remainder of/-88create image widthheightbaseTilesceneX8/sceneY8/create image widthheightsceneMapsceneMap00sceneX8/sceneY8/sceneMap00sceneX8/sceneY8/sceneMap0sceneY8/sceneX8/0scene.setTileMap(sceneMap)draw line infrom xyto xydraw line infrom xyto xydraw rectangle inat xywidthheightfillwithscene.setTile(8, baseTile)setsceneMaptofillwithsetbaseTiletosetsceneYtosetsceneXtosetsceneYtosetsceneXtolet sceneMap: Image = nulllet baseTile: Image = nullon start

See also

camera follow sprite