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 / Possible bug? Can't Get images to load properly

Author
Message
Yodaman Jer
User Banned
Posted: 15th Dec 2014 07:06
I think I might have found a pretty severe bug!

I am trying to load in my own images and create sprites from them. I have made sure my images are located in either the media folder, or where the .exe file is created upon compilation.

Yet when the program begins to run, I just get the basic image with a red cross in the middle against a checkerboard. I have exported my image into different formats to see if that was the problem, but it sadly did nothing. I even went so far as to rename my image file and purposefully misspell the name of my file in the "LoadImage" command, and that's when I discovered that the program ran anyway, completely ignoring the obvious error, and instead of telling me the file doesn't exist it just runs regardless.

I have looked at various examples all night, I have started at least three different projects, and I even reinstalled AppGameKit, and NOTHING I do will make it work. Here's my code:


I have had this work in the past, so I really don't know what's going on here! If anybody can offer any insight, please let me know!

If it matters, I'm using GIMP to create and save my images. Could that be the problem? Does AppGameKit not like interpreting files created by GIMP?

xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 15th Dec 2014 07:46
Which version of AppGameKit are you using? Your code works fine for me, with an image 't.jpg' placed inside the 'media' folder of your project's root directory. Attached is a ZIP showing proper structure, if you run the included EXE you should see the sample image. You can try this image in your own in case it is a file compatibility issue but that is unlikely.

You can alternatively create sprites with images using any of the commands below assuming you do not need to track the image texture itself:





On Android devices and some platforms your files are case-sensitive, so if it is named 'T.jpg' you must reference it in your code as 'T.jpg'

Attachments

Login to view attachments
Yodaman Jer
User Banned
Posted: 15th Dec 2014 08:06
Oh, I didn't realize that the files had to go in the default media folder, I thought I could just place them in the same spot as the final application, much like how DarkBASIC used to work, or in my own media folder.

This seems like a really silly mistake now.

Still, shouldn't the compiler throw an error about not being able to locate the file? That really would have helped me out a lot sooner instead of just having me guess all night. It really did have the appearance of a bug!

Another cause of my problems seems to be that I was also saving everything out as .bmp which didn't help either. Once I converted thigns to .jpgs or .pngs, they worked as expected.

Thank you for helping me out, xCept! Glad to see this isn't a bug after all. And it's even better to see my sprites finally looking how I want!

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 15th Dec 2014 08:22
No compiler can report missing files at compile time. As AppGameKit doesn't return an error for LoadImage(() it might be a good idea to check that the image's width and height are >0, and if not, put up an error box.

-- Jim - When is there going to be a release?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th Dec 2014 10:03
I think you possible meant a runtime error, not compiler error?
On a mobile device, you don't want runtime errors crashing the program. You don't want them on Windows either, but it seems to be frowned upon a lot more on mobile devices, and you run the risk of having your app pulled from the store.

The answer is to use GetFileExists() before loading an image that may not exist (or to test an error on this case). You can create your own function (e.g LoadImageWithCheck()) that does the file check and load . Return the image number or -1 if it fails.

The root of your problem is that the default folder is the media folder, not the folder with the executable in.

Quidquid latine dictum sit, altum sonatur
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 15th Dec 2014 11:51
I think I'll knock up a media checker program that can scan the source files and the media folder and ensure that files exist and that the case is correct. Plus checking audio files for format issues.

-- Jim - When is there going to be a release?
Yodaman Jer
User Banned
Posted: 15th Dec 2014 16:29
@BatVink:

I did indeed mean runtime error, not compiler error. That's what I get for typing up a message at 1am my time!

I will look into using GetFileExists() in the future, as well.

Quote: "The root of your problem is that the default folder is the media folder, not the folder with the executable in."


Now that I know this I feel so silly. I totally missed this part in any of the tutorials I looked at.

@Jim:
Sounds like a cool idea!

Yodaman Jer
User Banned
Posted: 19th Dec 2014 18:38
OK, I really don't know what I'm doing wrong here either.

I'm trying to set up a basic Breakout clone using no media. I looked at the GetImage and SaveImage commands and decided to use those to create my bricks. However, they don't draw to the screen, and when I go to look to see if the image was actually saved it doesn't show up in the media folder.

My code:



What am I doing wrong here? I tried using Update(0) and Render() before and after saving the images but that did nothing.


7+ years and counting!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Dec 2014 18:57
I think you'll need a ClearScreen() first to get your red colour.

Then...

Quote: "...if you want to grab an image of the current scene fully drawn you must call Render then GetImage then ClearScreen to clear the back buffer so Sync doesn't redraw everything over a fully drawn depth buffer"


I would also be tempted to GetImage a white brick, and you can then use one image and SetSpriteColor() for multicoloured bricks.

You could also use CreateImageColor() to create a 1x1 pixel that is used to texture a sprite.

Quidquid latine dictum sit, altum sonatur
Yodaman Jer
User Banned
Posted: 19th Dec 2014 19:30
I tried that but all it did was make the screen flash red for a split second and then go back to black, showing nothing once again. This shouldn't be this confusing but it is.

New code:



Where is AppGameKit storing the images I'm saving if not in the default media folder?


7+ years and counting!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Dec 2014 20:17
The media folder is read only (limitation of mobile devices for security).
Your saved files are in your user folder in the AppGameKit sub folder (if I remember correctly).

If you load any file and save it, you'll get a second copy in the users folder. AppGameKit checks this folder first, then reverts to the media folder if not found.

Quidquid latine dictum sit, altum sonatur
Yodaman Jer
User Banned
Posted: 20th Dec 2014 03:15 Edited at: 20th Dec 2014 03:44
Hmm, I found the images and discovered that it did indeed capture the red!

I moved the image over to the default media folder, but it still won't show up. I got rid of all the lines of code that reset the clear color and now am only loading the image. This is my code:



Once again, all I see on the screen is black. I know the file is there but nothing is drawing, not even the "no sprite" image I was originally getting.

I don't know why this is so hard to get working, what am I doing wrong? Or is THIS now a bug whereas the last one was just misinformation?

EDIT: OK now I think this is a bug for sure. The thumbnail for the image shows as red but when I opened the image into GIMP there was nothing contained in the image file. It wouldn't display anything.

So it does appear to be a bug after all... well at least I know it wasn't my code. I guess I will just have to stick to using media after all...

EDIT 2: AHHA! eureka!

Instead of using SetClearColor(), I used DrawBox() to draw a basic blue box to see if that was maybe the culprit. That appears to have solved the problem!

Looks like I can make a medialess game now. Perhaps I just assumed the SetClearColor() would work with GetImage() but it just grabs nothing? Still doesn't explain why the thumbnail was red though.

EDIT 3: OH jeez, I think figured out why it wasn't working the first time.

I had the update() and Render() commands swapped, so it grabbed the red part of the screen but then quickly changed to nothing and that must be why it saved the image with nothing but the alpha channel and still gave it a red thumbnail. But the drawbox idea works out a lot better I think. Don't know why I didn't think of that at first to begin with honestly...

This is what it looks like now, and it works beautifully.



7+ years and counting!
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 20th Dec 2014 09:23
Yodaman Jer, do you actually need to create the files? Perhaps you wasn't aware, but you can create sprites without the need to Save an image... Like so;



This is truly 'medialess' as none is required and none is ever created
Yodaman Jer
User Banned
Posted: 20th Dec 2014 16:26
I was aware of that technique but I for some reason wanted to overcomplicate things I guess.

The only reason I started saving images was to see if anything actually showed up when I was grabbing images.

I think I will use your technique, it's simple and effective and doesn't require drawing boxes and suchlike!


7+ years and counting!

Login to post a reply

Server time is: 2024-04-20 07:29:23
Your offset time is: 2024-04-20 07:29:23