What
else does
GetImage do?
Obviously, we know that it gets an area of the backbuffer and assigns an image ID to it but it seems to be doing something else too.
Abstract
Calling
GetImage appears to be moving drawn images in front of sprites.
Problem
I am trying to create images in code that use a combination of sprites and drawn images (boxes, lines, circles). I want to have any drawn images appear behind the sprites but they don't do that, all drawn images appear on top of sprites.
Solution 1
Use
GetImage to capture any drawn images and then using the images associated with sprites transfer all image data into a new memblock and create a new image from that.
This will work and I may go down this route.
Solution 2
Use
GetImage to capture any drawn images and then create sprites from them. Position all my sprites where I want them and in the order I need them, then use
GetImage to capture my final image. This should work in theory and should require less code than solution 1.
If I don't do anything with the drawn images, they appear in front of the sprites and this is to be expected. However, if I call
GetImage and
no other code the drawn images now appear behind the sprites. This is what I want to happen but it makes no sense without actually doing something with the new image.
Test Code
SetWindowSize( 640, 480, 0 )
SetVirtualResolution( 640, 480 )
global spr as integer[9]
spr[0] = LoadImage("test.png")
for k = 1 to 8
spr[k] = createsprite( LoadSubImage( spr[0], str(k) ) )
next k
buildImage( )
SetSpritePosition( spr[9], 100, 100 )
do
sync()
loop
function BuildImage()
sync()
col = MakeColor(128,128,128)
drawbox( 2, 2, 56, 56, col, col, col, col, 1 )
//img = getimage( 4, 4, 54, 54 )
SetSpritePosition( spr[1], 0, 0 )
SetSpritePosition( spr[2], 50, 0 )
SetSpritePosition( spr[3], 0, 50 )
SetSpritePosition( spr[4], 50, 50 )
SetSpritePosition( spr[5], 8, 0 )
setspritesize( spr[5], 42, 4 )
SetSpritePosition( spr[6], 0, 8 )
setspritesize( spr[6], 4, 42 )
SetSpritePosition( spr[7], 54, 8 )
setspritesize( spr[7], 4, 42 )
SetSpritePosition( spr[8], 8, 54 )
setspritesize( spr[8], 42, 4 )
render()
spr[9] = createsprite( GetImage(0,0,58,58) )
for k = 0 to 8
SetSpriteVisible( spr[k], 0 )
next k
endfunction
You'll need the attached image and subimage text file (
sorry) but when you run the code as it is, the drawn box appears on top of the sprite and is as you would expect. However, if you uncomment the
GetImage line the drawn box now appears behind the sprites which is really not expected at all.
So, back to my original question: What else does
GetImage do? It's clearly doing more than just getting an image from the backbuffer.
AGK V2 user - Tier 1 (mostly)