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 / GetImage() giving me grief again

Author
Message
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Oct 2013 18:49 Edited at: 13th Oct 2013 18:51
I'm looking for ideas/solutions...

I'm trying to grab some text and convert it to a sprite. If I do it in the screen area, it picks up the background image which I don't want. Even with clearScreen() first, the background is still there.



The second option is to do it "off screen" where there is no background. If I do this - even when the screen offset is changed to bring it on-screen, all I get is a black box. I would have expected a transparent box with text. In this example, sy# is screen height + 1000



The image when done within normal screen area, you can see it has it's own background.



Attachments

Login to view attachments
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 13th Oct 2013 19:40
I don't think you can grab "offscreen"

What about drawing a blank black sprite first, overlaying the text and then grabbing it?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 13th Oct 2013 19:40
Try doing a couple of Sync() calls after ClearScreen(). Just to make sure that everything is actually cleared.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 13th Oct 2013 19:41 Edited at: 13th Oct 2013 19:42
what if you had a black sprite drawn behind the text to hide the background?

edit: haha.... my response was after a few other posts I didn't have loaded yet.

everyones eager to help!

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 13th Oct 2013 19:52 Edited at: 13th Oct 2013 19:55
render() will render everything, including your background.

In your second example the text could be outside the screen, if it for example is fixed to the screen.

I would suggest making a test program with just the text and see what happens.


Edit
In your 2nd example it should probably be:
img = getImage(0, 0, getTextTotalWidth(idx), getTextTotalHeight(idx))

As I think it's relative to the view.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Oct 2013 20:09
Wow, three answers come along all at once!

Black sprite - I'll certainly try it as a temporary measure. I need alpha transparency ultimately, but this is a good start.

Sync()ing - I believe that this will undo the clearScreen(), which is a sub-component of sync(). The helptext for saveImage() is good and explains some of this...but I still can't get it to work

Quote: "I don't think you can grab "offscreen""

You're right. This is why I setScreenOffset() before saveImage(). This should have let me grab with a transparent background.

The plot thickens. I have also found that render() bakes the images to the output permanently (even with clearscreen() afterwards), so I can't do this on-screen or off-screen.

I have another project where this works, I'll do as Digital Awakening says and experiment in isolation.

Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 13th Oct 2013 20:58
Quote: "Black sprite - I'll certainly try it as a temporary measure. I need alpha transparency ultimately, but this is a good start."

The font you show in the sample looks to be shades of gold. You could possible use the Red or Green channel to set the alpha.

Failing that, one technique I use is to do white version, grab it as a mask and use that with setimagemask on the colour version.

How well this works will depend on the source font.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Oct 2013 22:42
so?

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Oct 2013 13:00 Edited at: 14th Oct 2013 13:01
Marl, the alpha channel is a nice idea, but the font is configurable, in terms of style and colour.

Markus, your demo works perfectly for me, so I don't understand what I am doing wrong. I noticed 2 differences:

* clearScreen() followed immediately by render(). This didn't fix it for me.

* You don't move the text. Again this hasn't fixed it.


The big flashing warning sign for me is that the text gets baked to the background in the top left corner where I grabbed it from even after deleting the text.
In this screenshot you are looking at the top left of the screen. You can see the original text with a faint sprite behind it.
The funny blue swoosh is the background sprite recoloured to make the problem clear, the purple and blue is all one sprite.
The text in the centre is the "sprited" text with the blue of the background sprite showing through.

And here is the current version of the code:





Attachments

Login to view attachments
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Oct 2013 13:15 Edited at: 14th Oct 2013 13:21
the textboxes are hold in a list that render show.
therefore clear & render follow. the text i created before.
maybe do not use clearcolor.


try this
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Oct 2013 13:32
Thanks again. It's getting closer.
I need to change my program logic for this approach because the user can "design" their own screen with multiple sprites, I may have to hide lots of them but I already have an array list I can do this from.

I just have one issue left. The text is still visible in the top left corner. I have tried allsorts of variations of the clearScreen / render but none have removed the text. I don't know why it gets baked to the backdrop, especially now that I hide the background before getImage?



Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Oct 2013 14:20
Quote: "
I just have one issue left. The text is still visible in the top left corner. I have tried allsorts of variations of the clearScreen / render but none have removed the text. I don't know why it gets baked to the backdrop, especially now that I hide the background before getImage?
"

hmm,strange. did you use beta 19?

maybe you can use a full screen sprite as background before all
others, then the text on top.
grab the image and then make the image transparent with key color.
SetImageTransparentColor( iImage, r, g, b )
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 14th Oct 2013 16:12
Here's a working example. Not exactly sure why this works over yours. This is in beta 19.



BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Oct 2013 17:57
Thanks again. Each time I try one of these I get a little closer. I know one thing for certain. There is something extremely silly and wrong about this code. I just can't see it for staring at it.

I have now discovered I CAN compose the sprite by setting the view offset. The schoolboy error here was that to get the top left part of the screen, I should start at 1,1. I had started at 1,1000 just like the offset. So effectively I was getting 1, 2000.

So what is my final mistake, I can't see it? I'm offsetting the screen, getting the the text at 1,1, resetting the screen, and I still get the image at the top left. It appears to be a sprite, text or both because when the purple screen ends and I go back to the menu, the text is still there in the top left with the faded box behind it.



Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 14th Oct 2013 18:01
What happens if you toss some sync() calls in there?
That's the only difference I see between your code and mine (other than using the view offset, which isn't needed in my code).

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Oct 2013 01:21
slow motion
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th Oct 2013 10:40
Quote: "What happens if you toss some sync() calls in there?"


I noticed your sync()s in the pause function, but they didn't make a difference for me.

I now have a full solution, and if anyone wants a standalone example, then the one Markus has posted above is identical in method. It is a good solution because it works "off-screen" and doesn't need any messing around with what the user is looking at.

The only thing to add is my mysterious extra copy in the top left corner. This was my fault . I still need to work out where it is happening, but this is an extra sprite copied from the original and never positioned, so it sticks in the top left corner.

Thank you everyone for your help.

Login to post a reply

Server time is: 2024-05-20 08:34:14
Your offset time is: 2024-05-20 08:34:14