This is a bit of code that the developer Paul helped me with for an app I made called Doodle Draw.
Might help you out. The link is below too.
Global w,h,rw,rh,screenTop as integer
w = 800
h = 1280
//Global sw#, sh# as float
//sw# = w/rw
//sh# = h/rh
//sw# = w/rw
//sh# = h/rh
screenTop=51 // Change this to position drawing screen height
SetWindowTitle( "Paint" )
SetScreenResolution( w, h)
SetSyncRate( 60, 0 )
SetVirtualResolution( w, h )
SetScissor( 0, 0, 0, 0 )
SetClearColor(0,0,0)
SetPrintSize(20)
// create two render targets and swap between them
global buffer as integer[1]
buffer[0] = CreateRenderImage( 512, 1024, 0, 0 ) // currently render targets must be a power of 2
buffer[1] = CreateRenderImage( 512, 1024, 0, 0 ) // luckily they don't have to match the current screen size to work
global currBuffer as integer = 0
// clear them both
SetRenderToImage( buffer[currBuffer], 0 )
ClearScreen()
SetRenderToImage( buffer[1-currBuffer], 0 )
ClearScreen()
SetRenderToScreen()
// create the screen sprite, this will be used to display the final image and draw the
// background of the next render image
global screen as integer
screen = CreateSprite(buffer[currBuffer])
SetSpriteDepth(screen,1000)
SetSpriteTransparency(screen,0)
// these positions only matter if you have black borders, the render image will also have
// them so the sprite displaying it must be in the true top left corner of the screen
// if you can guarantee no black borders then you can use 0,0 and w,h
SetSpritePosition(screen,GetScreenBoundsLeft(),GetScreenBoundsTop())
SetSpriteSize(screen, GetScreenBoundsRight()-GetScreenBoundsLeft(),GetScreenBoundsBottom()-GetScreenBoundsTop())
iBrush = LoadImage( "/media/brush2.png" )
Global Brush as integer
Brush = CreateSprite(iBrush)
SetSpriteSize(brush,128,128)
SetSpriteOffset(brush, GetSpriteWidth(brush)/2,GetSpriteHeight(brush)/2)
SetSpriteColorAlpha(brush, 60)
SetSpritePosition(brush,-200,0)
SetSpriteVisible(Brush,0)
Do
Print("FPS:"+str(ScreenFPS(),0))
if getpointerpressed()
SetSpriteColor(brush, Random(0,255), Random(0,255), Random(0,255), 255)
endif
if GetPointerState()=1
x = GetPointerX()
y = GetPointerY()
Paint(x,y)
endif
sync()
Loop
function Paint(x,y)
// Draw the current screen with the old render image onto the new render image
// Draw the new brush onto the new render image
// Set the new render image as the screen image and swap the buffers ready to do it again
// make sure the background image is in the right place just in case
SetSpriteImage( screen, buffer[1-currBuffer] )
SetSpritePosition(screen,GetScreenBoundsLeft(),GetScreenBoundsTop())
SetSpriteSize(screen, GetScreenBoundsRight()-GetScreenBoundsLeft(),GetScreenBoundsBottom()-GetScreenBoundsTop())
// clear the image and draw the background (the current scene)
SetRenderToImage( buffer[currBuffer], 0 )
ClearScreen()
DrawSprite(screen)
// draw the new brush
SetSpritePositionByOffset(Brush,x,y)
SetSpriteAngle(Brush, random(0,360))
SetSpriteVisible(Brush,1)
DrawSprite(Brush)
SetSpriteVisible(Brush,0)
SetRenderToScreen()
// set the new render image as the current scene and swap the buffers for next time
SetSpriteImage( screen, buffer[currBuffer] )
currBuffer = 1-currBuffer
endfunction
Check out the link for Doodle Draw here to see how it got to this:
https://forum.thegamecreators.com/thread/214589