The y position of the camera.
The default y position is 0. All camera properties can be both accessed and updated.
The camera enables scrolling and zooming for scenes extending beyond the display area. A camera has a position, a zoom factor, and mouse coordinates relative to the view. The camera is automatically created and available for use.
Link the camera to the main sprite movement and scroll stationary sprites.
// Link the camera to the main sprite movement and scroll stationary sprites. var sprite = createSprite(200,200); sprite.setAnimation("alienBlue_walk_1"); var cactus = createSprite(100, 300); var fence = createSprite(300, 300); cactus.setAnimation("cactus_1"); fence.setAnimation("fence_wood_1"); camera.on(); function draw() { background("white"); drawSprites(); camera.x=sprite.x; camera.y=sprite.y; if (keyDown("right")) { sprite.x = sprite.x+5; sprite.mirrorX(1); } if (keyDown("left")) { sprite.x = sprite.x-5; sprite.mirrorX(-1); } if(sprite.x-cactus.x>200) cactus.x=sprite.x+200; if(cactus.x-sprite.x>200) cactus.x=sprite.x-200; if(sprite.x-fence.x>200) fence.x=sprite.x+200; if(fence.x-sprite.x>200) fence.x=sprite.x-200; }
Explore a background by linking the camera to the mouse.
// Explore a background by linking the camera to the mouse. var back = createSprite(200, 200); back.setAnimation("stone_snow_1"); back.scale = 5; camera.on(); function draw() { background("white"); drawSprites(); camera.x=World.mouseX; camera.y=World.mouseY; }
camera.y
The y coordinate of the center of the camera.
drawSprites()
is called.Found a bug in the documentation? Let us know at documentation@code.org