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 / Image blending with memblocks

Author
Message
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 5th Feb 2015 21:13 Edited at: 6th Feb 2015 16:15
Hi,

[Edit]I've edited the AppGameKit code to show the now working version should anyone wish to use it [/Edit]

Back in 2007 I wrote a function that would blend two images together based on a third alpha mask image and posted here on the code snippets board. I'm trying to convert it to AppGameKit which I thought would be pretty straight forward but it isn't working.
Is there a BUG with the memblock image commands or am I doing something wacky that I can't see?

This is the original code from the link above:


And this is my attempt to convert it to AppGameKit v2:


If you'd like to test it then I used this test code to call the function:


And I've attached the images I used to this post

AGK V2 user - Tier 1 & 2

Attachments

Login to view attachments
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 6th Feb 2015 10:55 Edited at: 6th Feb 2015 11:02
It doesn't like iResult for some reason. Swapped it for a constant and BOOM!




These are the changes I made to the blend_images function:



I'm guessing it is something to do with iResult being a local variable in the function. No idea why you can't return that value though :s I hope this points you in the right direction!

V2 T1 (Mostly)
Uzmadesign

Attachments

Login to view attachments
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Feb 2015 11:51
I'm impressed that you picked out iResult as the culprit!
It's because iResult is 0, it never gets set.

This should also fix it, replace:

CreateImageFromMemblock( iResult, mResult )

with

iResult = CreateImageFromMemblock(mResult)

Quidquid latine dictum sit, altum sonatur
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 6th Feb 2015 14:58
"I can only show you the door. You're the one that has to walk through it."



V2 T1 (Mostly)
Uzmadesign
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Feb 2015 15:07
You have the look of a man who accepts what he sees because he expects to wake up

Quidquid latine dictum sit, altum sonatur
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 6th Feb 2015 16:10 Edited at: 6th Feb 2015 16:11
Thank you both of you.

I'm not sure why we have slipped into matrix quotes but thanks anyway

So, what have we learned here?
Is there a bug in the createImageFromMemblock command? Or should the help files be amended?

AGK V2 user - Tier 1 & 2
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Feb 2015 16:21
The help files are ok, there's 2 ways of writing the command. The way you wrote it requires you to manually set the imageID (iResult). Because it was 0, it failed silently and gave you an empty image.

I think you wanted it to automatically assign a new image number to it, in which case you need the second syntax, as shown in my post above.

Quidquid latine dictum sit, altum sonatur
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 6th Feb 2015 17:45
I don't think the help files are OK.
It's this part I have an issue with:
Quote: " if the image exists it will be overwritten, if not it will be created."


That obviously didn't happen for me and no error was reported either.

AGK V2 user - Tier 1 & 2
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th Feb 2015 17:47
Isn't zero an invalid ID?

Onwards and sometimes upwards
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Feb 2015 17:53 Edited at: 6th Feb 2015 17:55
Quote: "if the image exists it will be overwritten.."


If you have a nice image of an alien in image 99 then:

CreateImageFromMemblock( 99, memID )

will replace your alien with your memblock image.


Quote: "...if not it will be created."


If image 99 has never been used then:

CreateImageFromMemblock( 99, memID )

will create the image.

But this will never work:

CreateImageFromMemblock( 0, memID )

because you can't have an image 0. Thisis what your code has tried to do. AppGameKit fails silenty. In other words the damage isn't catastrophic enough to halt your program, so it carries on without erroring. This is an expectation of iOS and Android. You can use GetErrorOccurred() to manually check, or SetErrorMode() to force an error.

Finally...

iResult = CreateImageFromMemblock( memID )

will return an image ID plucked from the pool. These start at 10,000 and increment each time you create an image.

Quidquid latine dictum sit, altum sonatur

Login to post a reply

Server time is: 2024-11-25 16:39:46
Your offset time is: 2024-11-25 16:39:46