i rebuilt the minimap. it's probably a little easier to understand now. Without using viewzoom and viewoffset.
In the example you can control with the WASD keys. With PgUp/PgDown zoom the main map and with F1, F2, F3 call the pre-set zoom modes for the minimap.
// Project: MiniMap
// Created: 2019-06-17
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "MiniMap" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
LoadImage(1, "The-Witchlands.jpg") // load map image
LoadImage(2, "mask.png") // load mask
CreateImageColor(3, 255, 0, 0, 255) // a red square image for the player
CreateRenderImage(4, 128, 128, 0, 0) // image for minimap
global g_PlayerPosX as float // players position on the map
global g_PlayerPosY as float
global g_PlayerAngle as float // players angle
global g_MapZoomLevel as float
global g_MiniMapZoomLevel as float
g_PlayerPosX = GetImageWidth(1)/2
g_PlayerPosY = GetImageHeight(1)/2
g_PlayerAngle = 0
g_MapZoomLevel = 4.0
g_MiniMapZoomLevel = 1.0
CreateSprite(1, 1) // create a sprite for the world
SetSpritePositionByOffset(1, 0, 0)
SetSpriteScale(1, 4, 4)
SetSpriteVisible(1, 0)
CreateSprite(2, 2) // create the mask sprite
SetSpriteTransparency(2, 1) // need to set mask sprite to transparent pixels
SetSpriteVisible(2, 0)
SetSpriteDepth(2, 0)
CreateSprite(3, 3) // player sprite
SetSpriteScale(3, 16, 16) // scale player to 16 pixel
SetSpritePositionByOffset(3, GetVirtualWidth()/2, GetVirtualHeight()/2)
SetSpriteVisible(3, 0)
createSprite(4, 4)
SetSpriteTransparency(4, 1)
SetSpritePosition(4, 0, 0)
do
draw_main_map()
draw_minimap()
// control
if GetRawKeyState(65) Then Dec g_PlayerAngle, 1
if GetRawKeyState(68) Then Inc g_PlayerAngle, 1
if GetRawKeyState(87) Then MovePosition(3, 1)
if GetRawKeyState(83) Then MovePosition(3, -1)
if GetRawKeyState(33) Then Inc g_MapZoomLevel, 0.1
if GetRawKeyState(34) Then Dec g_MapZoomLevel, 0.1
if GetRawKeyState(112) Then g_MiniMapZoomLevel = 0.75
if GetRawKeyState(113) Then g_MiniMapZoomLevel = 1.5
if GetRawKeyState(114) Then g_MiniMapZoomLevel = 1.0
Print( ScreenFPS() )
Sync()
loop
function draw_main_map()
centerx as float
centery as float
centerx = GetVirtualWidth()/2
centery = GetVirtualHeight()/2
// zoom the main map
SetSpriteScale(1, g_MapZoomLevel, g_MapZoomLevel)
// set player position. here we set the map offset position.
// the map ist scaled by 4. so the position must be also scaled by 4
SetSpriteOffset(1, g_PlayerPosX*g_MapZoomLevel, g_PlayerPosY*g_MapZoomLevel)
SetSpritePositionByOffset(1, centerx, centery)
// no rotation for the main map
SetSpriteAngle(1, 0)
// center player sprite in the middle of the screen
SetSpritePositionByOffset(3, centerx, centery)
// rotate player
SetSpriteAngle(3, g_PlayerAngle)
// draw map and player
SetSpriteVisible(1, 1)
SetSpriteVisible(3, 1)
DrawSprite(1)
DrawSprite(3)
SetSpriteVisible(1, 0)
SetSpriteVisible(3, 0)
endfunction
function draw_minimap()
centerx as float
centery as float
lastvx as float
lastvy as float
//save some current states
lastvx = GetVirtualWidth()
lastvy = GetVirtualHeight()
// set renderer to minimap image
SetRenderToImage(4, 0)
SetVirtualResolution(GetImageWidth(4), GetImageHeight(4))
centerx = GetVirtualWidth()/2
centery = GetVirtualHeight()/2
// zoom the main map
SetSpriteScale(1, g_MiniMapZoomLevel, g_MiniMapZoomLevel)
// set player position. here we set the map offset position.
// the map ist scaled by 4. so the position must be also scaled by 4
SetSpriteOffset(1, g_PlayerPosX*g_MiniMapZoomLevel, g_PlayerPosY*g_MiniMapZoomLevel)
SetSpritePositionByOffset(1, centerx, centery)
// rotate the map inverse of the player rotation
SetSpriteAngle(1, -g_PlayerAngle)
// draw mini map
SetSpriteVisible(1, 1)
SetSpriteVisible(2, 1)
DrawSprite(1)
DrawSprite(2)
SetSpriteVisible(1, 0)
SetSpriteVisible(2, 0)
// restore all values to default
SetRenderToScreen()
SetVirtualResolution(lastvx, lastvy)
// set black to transparent
SetImageTransparentColor(4, 0, 0, 0)
endfunction
function MovePosition(id as integer, move as float)
angle as float
mx as float
my as float
angle = GetSpriteAngle(id)
mx = sin(angle) * move
my = -cos(angle) * move
//SetSpritePosition(id, getspritex(id)+mx, GetSpriteY(id)+my)
g_PlayerPosX = g_PlayerPosX + mx
g_PlayerPosY = g_PlayerPosY + my
endfunction
If you now want to display your 3D environment as minimap. Then you should do it as fubarpk suggests, as described in the thread.
Simply place the camera a few units above your player position with the direction of view to the player. As minimap it is recommended to set an orthogonal view for the camera.
Share your knowledge. It\'s a way to achieve immortality.
(Tenzin Gyatso)

