This demo shows how to create a simple “flying over a city” effect using PlayBASIC.
The scene is made entirely from 2D squares arranged in a grid. Each square represents a building. Multiple copies of this grid are drawn at different depths, and the camera projects them in perspective so they appear smaller in the distance.
To make the scene more visually interesting:
* The buildings use additive blending to create a glowing effect
* The colour fades with distance to simulate depth
* The camera can move and rotate, giving the feeling of flying over the city
Even though it looks like a 3D world, everything is built from simple 2D drawing commands. The illusion of depth comes from layering and the camera system.
The world also wraps around the camera position, which makes it appear endless without needing to generate new geometry.
Historical Note
This demo was inspired by classic effects from the early demo scene.
I first remember seeing a similar visual style in the Arte demo by the demogroup Sanity back in 1993 on the Commodore Amiga. The top-down city-like perspective left a lasting impression on me.
Seeing the potential to recreate a similar effect using PlayBASIC’s rotated camera system, I took the opportunity to build a modern take on that idea.
Enjoy!
The scene is made entirely from 2D squares arranged in a grid. Each square represents a building. Multiple copies of this grid are drawn at different depths, and the camera projects them in perspective so they appear smaller in the distance.
To make the scene more visually interesting:
* The buildings use additive blending to create a glowing effect
* The colour fades with distance to simulate depth
* The camera can move and rotate, giving the feeling of flying over the city
Even though it looks like a 3D world, everything is built from simple 2D drawing commands. The illusion of depth comes from layering and the camera system.
The world also wraps around the camera position, which makes it appear endless without needing to generate new geometry.
PlayBASIC Code:
; -------------------------------------------------------- ; PlayBASIC Demo: Glowing City Flyover (Rotated Camera) ; -------------------------------------------------------- ; Limit the frame rate SetFPS 60 ; Create and configure the camera Cam = NewCamera() ; Enable rotated / perspective rendering mode CameraDrawMode Cam, 2 ; Disable automatic clearing when drawing the camera CameraCLS Cam, OFF ; Distance between tiles in the grid TileSpacing = 512 ; -------------------------------------------------------- ; Main Loop ; -------------------------------------------------------- Do ; Clear the screen (dark blue background) CLS $223344 ; Begin capturing draw commands into the scene buffer CaptureToScene ; Clear previous frame's scene data ClsScene ; Enable additive blending for glow effect InkMode 1+32 ; ---------------------------------------------------- ; Draw multiple grid layers at different depths ; ---------------------------------------------------- For lp = 0 To 100 Step 8 ; Assign depth (further layers appear smaller) CaptureDepth 500 + (lp * 5) ; Scale value used for color fading Scale# = lp / 100.0 ; Fade color based on distance C = RgbFade($884433, Scale# * 100) ; Draw a grid of glowing blocks Tile_Layer(TileSpacing, TileSpacing * 0.75, 10, 8, C) Next ; Render the scene using the camera DrawCamera Cam ; ---------------------------------------------------- ; Camera Movement Controls ; ---------------------------------------------------- Speed# = 5 If LeftKey() Then MoveCamera Cam, -Speed#, 0 If RightKey() Then MoveCamera Cam, Speed#, 0 If UpKey() Then MoveCamera Cam, 0, -Speed# If DownKey() Then MoveCamera Cam, 0, Speed# ; Wrap camera position to create an infinite scrolling effect x# = WrapValue(GetCameraX(Cam), 0, TileSpacing) y# = WrapValue(GetCameraY(Cam), 0, TileSpacing) PositionCamera Cam, x#, y# ; ---------------------------------------------------- ; Camera Rotation Controls ; ---------------------------------------------------- TurnAngle# = 0 RotationSpeed# = 0.25 If LeftMouseButton() Or KeyState(44) Then TurnAngle# = -RotationSpeed# If RightMouseButton() Or KeyState(45) Then TurnAngle# = RotationSpeed# ; Cycle camera modes when ENTER is pressed If EnterKey() CameraDrawMode Cam, GetCameraDrawMode(Cam) + 1 FlushKeys EndIf ; Apply rotation if needed If TurnAngle# <> 0 Angle# = GetCameraAngle(Cam) RotateCamera Cam, Angle# + TurnAngle# EndIf ; Update display Sync Loop SpaceKey() ; -------------------------------------------------------- ; Function: Draw a grid of blocks (buildings) ; -------------------------------------------------------- Function Tile_Layer(TileSpacing, BlockSize, GridWidth, GridHeight, ThisColour) ; Center the grid around (0,0) BaseX = (TileSpacing * GridWidth) / -2 BaseY = (TileSpacing * GridHeight) / -2 ; Loop through grid positions For ylp = 0 To GridHeight For xlp = 0 To GridWidth ; Calculate block position x1 = BaseX + xlp * TileSpacing y1 = BaseY + ylp * TileSpacing x2 = x1 + BlockSize y2 = y1 + BlockSize ; Draw filled box (building) BoxC x1, y1, x2, y2, TRUE, ThisColour Next Next EndFunction
Historical Note
This demo was inspired by classic effects from the early demo scene.
I first remember seeing a similar visual style in the Arte demo by the demogroup Sanity back in 1993 on the Commodore Amiga. The top-down city-like perspective left a lasting impression on me.
Seeing the potential to recreate a similar effect using PlayBASIC’s rotated camera system, I took the opportunity to build a modern take on that idea.
Enjoy!