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 / Starting out with Games and Graphics in C++

Author
Message
Guerrero Ultimo
10
Years of Service
User Offline
Joined: 25th Jan 2014
Location:
Posted: 25th Jan 2014 09:21
I had originally purchased the first edition and used the DarkGDK for a while. I also have other Gaddis books and they are pretty good. Purchased this one for my son who wanted to learn some programming. Things were going well until chapter 7. At that point we hit section 7-3: Displaying Sprites and program 7-2 which gave him an error. I checked through to make sure things were in the right place. The error was line 20 c2665.

Line 20: agk::CreateSprite(SPRITE_INDEX, "ghost.png");

Basically to fix the error I added (from online example)agk::LoadImage(SPRITE_INDEX, "ghost.png"); and change to
agk::CreateSprite(SPRITE_INDEX);

then things worked. Same issue with 7-3. That program changed 7-2 line 20 to agk::CreateSprite(SPRITE_INDEX, "beach.png");

Also, the command that is being used in the book is
agk::CreateSprite(SpriteIndex, ImageFile);
and it says that image file is the name of a file. Also that this function creates a sprite in memory. I am now thinking that agk::LoadImage is needed to create the sprite in memory before it can be used. Is that the case? If not is there somewhere to learn more about this function because the only thing I found for this was the example that stated to load the image and the create it using the functions agk::LoadImage and agk::CreateSprite respectively?

I noticed that programs 7-4, 7-5, and 7-6 do not use the LoadImage function either but I have not tested yet to see if I get an error just using agk::CreateSprite. I just want to make sure that the functions are being used right before moving on.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Jan 2014 20:48
You cannot use CreateSprite to load an image. However, there is a LoadSprite command that does this. If you want to use the same image for multiple sprite you should load that image separately.

If you use LoadImage you should store the image index into a separate variable from the sprite index variable. Since I don't know much C++ I won't write any code here.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 25th Jan 2014 21:12
Also, there can sometimes be issues with using LoadSprite(sprid,"image.png"). The loaded image doesn't automatically get deleted when you delete the sprite and doesn't get added to any gloval image handling done in AGK.

The preferred way is to use LoadImage(imgid,"image.png") or 'imgid=LoadImage("image.png")' and then CreateSprite(sprid,imgid) or 'sprid=CreateSprite(imgid)'.

As Digital Awakening states, CreateSprite does not take a file name for the image file, LoadSprite does.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Jan 2014 22:08
AL:
According to the AppGameKit help the image loaded with LoadSprite is deleted when the sprite is deleted. Is that incorrect?

Guerrero Ultimo
10
Years of Service
User Offline
Joined: 25th Jan 2014
Location:
Posted: 25th Jan 2014 22:11
"You cannot use CreateSprite to load an image."

"CreateSprite does not take a file name for the image file, LoadSprite does."

Well, that does help a lot. I have the Gaddis book on the kindle app and it does use CreateSprite to load the image. Then the Sync function will display on screen.

AGK is a nice piece of software. Received it as an AppGameKit 2 Kick Starter backer. Glad I did just for the value as an educational tool. Looking forward to playing around with it more.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 25th Jan 2014 22:27
Quote: "According to the AppGameKit help the image loaded with LoadSprite is deleted when the sprite is deleted. Is that incorrect?"

In theory, but some people have had issues with that. The handle to the created image doesn't get stored properly, or something.

Quote: "I have the Gaddis book on the kindle app"

(You can do the fancy quoting by selecting your text and then clicking on the 'quote' button in the message posting editor.)
Is this a book created specifically for AppGameKit?

While many of the DarkSDK commands are similar to AppGameKit, there is not a 100% correspondence between them.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Jan 2014 22:33
Quote: "In theory, but some people have had issues with that. The handle to the created image doesn't get stored properly, or something."

Good thing I am not using it then

Guerrero Ultimo
10
Years of Service
User Offline
Joined: 25th Jan 2014
Location:
Posted: 25th Jan 2014 22:53
Yeah, the book is created for the AppGameKit or at least to use it. The first edition of the book (which I had as well) was for the DarkGDK which I purchased and used a bit. This is the second edition of that book called:

Starting out with Games and Graphics in C++ (2nd edition)

Basically it requires Tier 2 of the AGK. And tells you how to get the free trial as well. I just happen to have the full version. And everything works correctly if I use LoadImage in the program to load the image first and then CreateSprite. I need to contact the author I guess and see if maybe there have been corrections not showing on my ebook. Anyway here is a small snippet of the code:

void app::Begin( void )
{
//set virtual resolution
agk::SetVirtualResolution(SCREEN_WIDTH, SCREEN_HEIGHT);

//Create the ghost sprite
agk::CreateSprite(SPRITE_INDEX, "ghost.png"); <--error location
}

the constants are set correctly and the only thing added is
agk::Sync(); in the Loop.

In fact the programs in chapter 7 of this book basically use the create sprite with the index and then file name as shown. One program does use LoadImage to load the image of a dog and then set the black background as transparent. Every program is giving me the error and using LoadImage helps.

And thanks for the clarifications on how some of these work.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 26th Jan 2014 20:30
I suppose it isn't impossible that the author simply made a mistake and was using copy/paste/edit and didn't edit the command properly in that example. It happens.

For one project I was writing assembly code to draw circles and used a Schaums book for the algorithm. And it didn't work because one '+' should have been a '-'. Even the best can make mistakes. In technical books it is very hard to check everything properly. Proof readers don't know what the real rules are for some things and the original writers might simply look for obvious stuff and not be checking everything everywhere.

And, it might be that the earlier versions of AppGameKit actually supported that usage and it was changed.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Guerrero Ultimo
10
Years of Service
User Offline
Joined: 25th Jan 2014
Location:
Posted: 26th Jan 2014 22:46
I am assuming you are correct about an earlier version of AppGameKit actually supporting the usage of CreateSprite with the image name. All the Gaddis books I have are great and easy to read and understand and this would just be the odd book out really if that was not the case.

Login to post a reply

Server time is: 2024-11-25 02:41:47
Your offset time is: 2024-11-25 02:41:47