Mintoris Forum

Author Topic: GEN005 Bitmap Graphics Overlay  (Read 1712 times)

Mintoris

  • Administrator
  • Full Member
  • *****
  • Posts: 57
GEN005 Bitmap Graphics Overlay
« on: Jul 16, 2018, 02:50 AM »
This example requires Basic 7.5.17 or higher to run.

Here is an example program showing how to use conventional graphics drawing commands in the game engine mode. This program draws a simple overlay pattern on the screen. The same technique could be used to dynamically draw on sprites.

Code: [Select]
' Camera Feed Overlay
' Written By: Charles Charbonneau
' 07-09-18

include "Game Engine Constants.inc"

init()

do
wait 1000
loop


Sub init()

  Global screenWidth = 2048
  Global screenHeight = 1024

  ' Set the orientation and turn on the Game Engine

  Orientation 2  
  GameEngine On, screenWidth, screenHeight
  GenCameraFeed on

  ' Make the background transparent
  ' so you can see the camera view
  GenSetBackgroundColor 0,0,0,0
 
  Global offset = 1
  Global inc = 4

  ' Create a tile overlay
  Global overlay = GenTileAtlas(screenWidth, screenHeight)

  ' Create the Overlay bitmap
  Global bmOverlay = CreateBitmap(screenWidth, screenHeight)

  ' Set the drawing surface to the star bitmap
  SetDrawingSurface bmOverlay

  ' Put the font into the overlay
  tileset = GenTileSet(bmOverlay)
  GenMapToAtlas overlay,  tileset, 0, 0

  ' Load the overlay into the GPU
  GenLoadAtlas overlay

  background = GenBackground(Background_Fixed, tileset)
  GenSetBackground background

  ' Set the overlay update sub
  SetOnGenBackgroundModifierSub background, onBackgroundUpdate()
  GenSetBackgroundTimerA background, 60

End Sub


Sub onBackgroundUpdate(background, type)

 ' Draw the overlay
  color 0,0,0,0
  cls
  Color 0, 100, 0, 100
  strokewidth 4
  line 0, 0 + offset, screenWidth, screenHeight - offset
  line 0, screenHeight - offset, screenWidth, 0 + offset

  ' Update the overlay
  GenReloadAtlas overlay

  if offset < 1 or offset > 511 then inc = inc * -1
  offset = offset + inc

  ' Repeat in 60 ms
  GenSetBackgroundTimerA background, 60

End Sub