Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / What else does GetImage do?

Author
Message
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 15th Apr 2016 08:59 Edited at: 15th Apr 2016 09:41
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

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)

Attachments

Login to view attachments
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 15th Apr 2016 14:13 Edited at: 15th Apr 2016 14:15
I've simplified the code a little.
You don't need any additional attachments with this:


Running this code will grab an image of a red sprite a green drawn box. The green box is on top of the red sprite as expected but if you uncomment the line: //greenBox = GetImage( 0, 0, 100, 100 ) then the green box will be behind the red sprite - and that is what is confusing me. What is GetImage doing to reverse the draw order?
AGK V2 user - Tier 1 (mostly)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th Apr 2016 14:44
I haven't run the code, but are you missing a render() before the greenbox = getImage(... ?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 15th Apr 2016 14:52
Yes I am.
That was intentional because I was trying to determine the cause of the draw order switch, so I removed it.
AGK V2 user - Tier 1 (mostly)
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 16th Apr 2016 05:33 Edited at: 16th Apr 2016 05:40
*my error*
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 22nd Apr 2016 14:20
Lines, boxes, and ellipses and drawn on demand (so that they can be batched into a single draw call). So GetImage is triggering a draw of all lines and then render() is drawing the red sprite on top of it. If you don't call GetImage then the lines are drawn by render() after the red sprite (normally lines are drawn after everything else but GetImage assumes you have already drawn all your sprites).

Login to post a reply

Server time is: 2024-09-29 13:26:30
Your offset time is: 2024-09-29 13:26:30