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 / V107 - Code examples

Author
Message
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st May 2012 17:25 Edited at: 1st May 2012 17:31
I have a couple of examples of some V107 commands I thought I would share with you in anticipation of the imminent release these come with compiled exe's. DON'T try to compile using V1065 as it won't compile, the code is just included so you can see how it is used here.

This is the full set of draw commands I made in V1065 using the "drawSprite(spriteID)" command (which works much like paste sprite in DBP):
Draw Commands

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st May 2012 17:27 Edited at: 1st May 2012 17:27
Here is the new command "setScissor" in action allowing a simple split screen effect. We use this command to set what area of the screen is rendered to when the "render()" command is used:
Split Screen

Attachments

Login to view attachments
The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 1st May 2012 18:45
Quote: "This is the full set of draw commands I made in V1065 using the "drawSprite(spriteID)" command (which works much like paste sprite in DBP):"


Isn't that v1070?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st May 2012 18:55 Edited at: 1st May 2012 18:55
I made a set of similar commands in V1065 that I have converted to V107 is what I meant, yes that version is V107.

Here is a sample using my "Spriter" import functions to create and save a single image to the "MyDocuments" folder with the new commands ( for you bjadams )
imageID = getImage(x#,y#,w#,h#)
saveImage(imageID,file$)

Image Combine example

Attachments

Login to view attachments
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 1st May 2012 18:59
Great work!!!
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st May 2012 18:59
Please something on HTTP

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st May 2012 19:09
Quote: "Please something on HTTP"

I wondered how long it would be before someone asked that. Unfortunately I haven't been using those commands so I don't have any examples. These are just examples I've made to test some of the commands while Beta testing. Most of my testing was in the draw, file, spriteUV commands I'm afraid as these were the ones I needed to use. Also my knowledge of how to use HTTP is minimal. I'm sure some good examples will be put into the release

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 1st May 2012 19:20
Baxslash, sorry to bother you, but I see a file save command, but would it be possible to save the file to the iOS photo gallery?
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st May 2012 19:24
Quote: "I'm sure some good examples will be put into the release"


I WISH I WISH I WISH

Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 1st May 2012 19:55
Quote: "would it be possible to save the file to the iOS photo gallery?"


SaveImage() will save the file to the write folder on all platforms, but PrintImage() will save the image to the photos folder on mobile devices, and send it to a printer on desktop devices.
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 1st May 2012 21:02
Paul thanks for doing the Save to photo folders command! This was the only thing stopping me from finishing my app!
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 2nd May 2012 21:24
I pasted some sprites to the screen, and used the GetImage command, but I am only getting a black rectangle
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd May 2012 21:38
Code?

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 2nd May 2012 22:01 Edited at: 2nd May 2012 22:02
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 2nd May 2012 22:03
Using SetSpriteScissor I am creating my image as desired. All work fine.

Next step is to grab the image using GetImage.

I am only getting a black rectangle at this point
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 00:10 Edited at: 3rd May 2012 00:12
You need to either use the render command or drawSprite for each of those sprites before you use getImage. Otherwise nothing has been drawn to the backburner. Then call clearScreen after you get the image.

Edit: and remove the sync command before getImage as this clears the buffer after displaying it.

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 00:49
Thanks a lot Baxslash, works perfectly now.

Unfortunately it seems that the semi transparent areas of the image are ignored Is there a way around this, maybe with some other command?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 08:18
I'm not sure I would post the question in the sticky Lee started.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 11:57
Here is a link to a working semitransparent image from getImage: LINK

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 12:39
Thanks Baxslash, but this is not what I wanted to achieve.

I want to take an opaque spite, use the setspritecolouralpha command to change its transparency, build a new image by combining multiple sprites, and then GetImage.

all works fine until the getimage. the getimage is not taking into consideration the setspritecolouralpha command.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 13:02
Replace the code in the example I sent with this:


It works fine here but I do notice the transparency is not quite right as it should be 50% transparent in the middle of the screen...

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 13:41
Baxslash thanks a lot for your precious support, but the problem is that there is no way to turn the background from black to transparent, so it's impossible to grab transparencies when the background is black!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 13:57
The background is only black if you tell it to be black. Are you using "agk::setClearColor()"?

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 14:03
No by default the background is black, I am not setting agk::setClearColor()
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 14:28
All I can tell you is that the example I have given a link to is getting semi-transparent images out I can make it save one out to a file if you like?. Can you provide a compilable example of this problem?

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 14:42
example:



bg01.png can be any 640x960 picture. I am grabbing the top 160pixels part, and then the next 20 pixels are set to different transparency levels to create a transparent gradient effect. all works fine until then.

i would then like to getimage this image i constructed, preserving the transparency, to use as a mask. this part is failing. the lower 20pixels that should be semi transparent are opaque.

at this point i just want to know if this is possible with agk, or if getimage will not support this kind of image grabbing over a transparent background.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 14:46
Quote: "at this point i just want to know if this is possible with agk, or if getimage will not support this kind of image grabbing over a transparent background."

I will turn your code into T1 and try to replicate it (I'll make it compilable too )...

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 15:05
This should work:


bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 15:14 Edited at: 3rd May 2012 15:19
Baxslash doesn't work.

You need to remove Sync too else it will somehow effect GetImage and make it grab a black rectangle.

using Render() is now reproducing the gradient effect, but not with transparency, but on a black bg

I think unless there is a way to clear the screen transparent it won't work.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 15:19
Attached is the Tier 1 project I did to test this code. Perhaps you could make an exact Tier 2 version and see if the results differ?

Attachments

Login to view attachments
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 15:27
Baxslash tried the T1 project too, they are both producing the same result.

Thanks to your adjustments the gradient effect is now showing. however it does not produce true transparency, as anything underneath does not show up. hence it won't work as a mask. GetImage is capturing the screen as a whole, including the black background. I think the trick here is to have some way to turn the background transparent.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 15:30 Edited at: 3rd May 2012 15:30
Here is what I get in Tier 1. Works fine as far as I can tell...


Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 15:33 Edited at: 3rd May 2012 15:33
And here it is over a red background showing the transparency of the sprite IS working:


Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 15:37 Edited at: 3rd May 2012 15:37
...and here is the image saved using this code:



Attachments

Login to view attachments
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 15:39
Yes that is the right result, but it did not behave like that for me
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 15:41
That's why I suggested you test it by producing an exact T2 copy of my code

Then you have something to show to TGC to say "Hey, this isn't working right!"

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 15:44
This is the result i am getting in TIER1 using your exact code...

Attachments

Login to view attachments
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 15:45
Baxslash are you using AppGameKit 107 or some other experimental version?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 16:05
I'm using the same version as everyone else. That's weird...

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 16:06
Did it do that before you compiled it yourself?

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 16:06
I'm banging my head on the wall
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 16:35
Quote: "I'm banging my head on the wall"



Did my pre-compiled version have the same result on your machine?

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 3rd May 2012 17:06
baxslash it's hard to check the precompiled version against a black background!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd May 2012 17:12
Maybe just report it as a bug then. I have no idea what might make it work differently on your PC to mine... sorry!

xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 4th May 2012 07:09
The transparency in baxslash's code (both versions) does not work when I preview it on my PC, I get the same result as bjadams... However, it works as expected when I run it through the compiled AppGameKit player on my iPod.
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 4th May 2012 09:25
Thanks Xcept I stopped banging my head on the wall now!

I am using Windows7 & an Nvidia card with the latest drivers. Maybe this is the problem.
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 4th May 2012 16:38
I've added a change for the next update that specifically requests 8 bits of alpha in the back buffer, I think on some cards it is using a 24 bit back buffer as alpha is not technically needed in the back buffer when using source alpha.
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 4th May 2012 17:33
Paul, unfortunately I could not make it work on iOS Xcode3 too

What happens on iOS is that the whole rectangle is 100% transparent, or GetImage did not grab anything!
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 4th May 2012 18:33
By any chance are you using SetOrientationAllowed(0,0,1,1) ? I think there may be a bug in landscape use of GetImage
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 4th May 2012 20:12
No I am using:

agk::SetVirtualResolution (640, 960);
agk::SetResolutionMode (1);
agk::SetOrientationAllowed (1, 1, 0, 0);

Login to post a reply

Server time is: 2024-11-23 11:25:50
Your offset time is: 2024-11-23 11:25:50