GameMaker: Studio

GameMaker: Studio

View Stats:
necromedes Dec 24, 2015 @ 12:38pm
sprite_add from "working_directory" is not loading png file as sprite
I have had it with the game maker forums being fill with bratty children who constantly waste my time with bickering among themselves, so I've decided to try the discussions here for help instead.

I am working on a card game sandbox and need to be able to load images from an EXTERNAL source and apply them to an object in game.

The code I am using can easily be found by searching for sprite add external on google and youtube. Everywhere I see people using the code and it works fine for them. For myself, however, it doesn't load the sprite. It simply doesn't exist.

global.card=sprite_add(working_directory+"\Dragons.png",1,true,false,0,0)
sprite_index = global.card

As you can see, the variable global.card should search for the working directory that stores the file named "Dragons." It is my understanding that you can simply plug this file into your project folder and it will automatically load them from there when using this code or by defining another folder that is within your project folder.

However, when I do so, the sprite does not load. I have used the if image_exists function to check if the sprite has indeed been loaded and it has not.

I have tried losing the working_directory line, I have tried removing the \'s, I have tried everything that I can and it still doesn't work.

I am so frustrated with this because I see everyone else having no problems with the supplied code.

Hopefully someone can explain clearly and simply here so that this issue can finally be resolved.

Thanks in advance.
Last edited by necromedes; Dec 24, 2015 @ 12:40pm
< >
Showing 1-15 of 16 comments
🐭 Dec 24, 2015 @ 12:41pm 
https://www.youtube.com/watch?v=79xVgyvxJWQ have you watched this? Are you using the Steam version? (The most recent update removed some functions though honestly I don't think they would remove something so essental but they might have changed it.)

This video taught me how to do this and it worked.

Edit:

You might not even need to include working_directory perhaps something more like /images/dragon.png read http://docs.yoyogames.com/source/dadiospice/002_reference/game%20assets/sprites/sprite_add.html
Last edited by 🐭; Dec 24, 2015 @ 12:43pm
🐭 Dec 24, 2015 @ 12:45pm 
Originally posted by Alex AmFm:
I had this problem before...all the tutorials was for gm8 no gms right?

in gms , the best way to use external sprites, is :

go to resource tree > right click on "included files" > "create included file"

then:

global.sEnemy2_idle = sprite_add("anima_enemy2_idle.png", 10,0,0,0, 0);

should work just fine
^This is more like what http://docs.yoyogames.com/source/dadiospice/002_reference/game%20assets/sprites/sprite_add.html says,
🐭 Dec 24, 2015 @ 12:49pm 
Originally posted by Alex AmFm:
Originally posted by YeeFee (Ferret):
^This is more like what http://docs.yoyogames.com/source/dadiospice/002_reference/game%20assets/sprites/sprite_add.html says,

the only problem is that they don't they you about "included files"
http://docs.yoyogames.com/source/dadiospice/001_advanced%20use/002_including%20files.html

A-am I the only one that reads the docs?
necromedes Dec 24, 2015 @ 12:53pm 
FINALLY! Someone who actually explained things CLEARLY. I have it working at last!

Quick question though. When I add the included file into the editor, does that simply contain the file name? because I am wanting the sprites in the card sandbox to be user defined. Does this mean that if I were to replace the image but retain the name that it would still work and use the new image provided?
🐭 Dec 24, 2015 @ 12:56pm 
Originally posted by Alex AmFm:
Originally posted by YeeFee (Ferret):
http://docs.yoyogames.com/source/dadiospice/001_advanced%20use/002_including%20files.html

A-am I the only one that reads the docs?

lets think..sprite_add documentation NEVER TELLS ABOUT YOU INCLUDED FILES

so quit bitchlng, kiddo.
Dude the documentation is one whole thing, you can't just expect that ♥♥♥♥ to work without reading it completely so watch the ♥♥♥♥♥♥♥ attatude you know it all.

Originally posted by necromedes:
FINALLY! Someone who actually explained things CLEARLY. I have it working at last!

Quick question though. When I add the included file into the editor, does that simply contain the file name? because I am wanting the sprites in the card sandbox to be user defined. Does this mean that if I were to replace the image but retain the name that it would still work and use the new image provided?
Yes it would, so long as the image is the same size it wont conflict with the game in any way. I'd read into user customization and perhaps making your game opensource so people could add their own cards with their own effects (like Relic Hunters Zero, you can grab its source code for GMS on its forums.
Last edited by 🐭; Dec 24, 2015 @ 12:58pm
necromedes Dec 24, 2015 @ 1:01pm 
Originally posted by YeeFee (Ferret):
Originally posted by Alex AmFm:

lets think..sprite_add documentation NEVER TELLS ABOUT YOU INCLUDED FILES

so quit bitchlng, kiddo.
Dude the documentation is one whole thing, you can't just expect that ♥♥♥♥ to work without reading it completely so watch the ♥♥♥♥♥♥♥ attatude you know it all.

Originally posted by necromedes:
FINALLY! Someone who actually explained things CLEARLY. I have it working at last!

Quick question though. When I add the included file into the editor, does that simply contain the file name? because I am wanting the sprites in the card sandbox to be user defined. Does this mean that if I were to replace the image but retain the name that it would still work and use the new image provided?
Yes it would, so long as the image is the same size it wont conflict with the game in any way.

Hmm... I just tried replacing the image in the folder with another image of the same name, same size, etc... and it is still using the originally provided png file. Am I missing something or is it simply not possible at this point?
🐭 Dec 24, 2015 @ 1:07pm 
Originally posted by Alex AmFm:
gmc is your home buddy
If thats directed to me I hope you notice that your attitude is exactly why people don't like GMC here, you sound like a bigot "Ooo GMC is so toxic so I'll be a toxic ♥♥♥♥♥♥♥ here too" Sure your advice was valid I should have included a link to that docs file as well, but that doesnt mean you need to be an ♥♥♥♥♥♥♥, I honestly assume if your going to use a developers software that you'll read the whole developers manual (the docs in this case).

Maybe its you that belongs in GMC, where you can call others ♥♥♥♥♥♥♥ for doing something wrong.

Originally posted by necromedes:
Originally posted by YeeFee (Ferret):
Dude the documentation is one whole thing, you can't just expect that ♥♥♥♥ to work without reading it completely so watch the ♥♥♥♥♥♥♥ attatude you know it all.


Yes it would, so long as the image is the same size it wont conflict with the game in any way.

Hmm... I just tried replacing the image in the folder with another image of the same name, same size, etc... and it is still using the originally provided png file. Am I missing something or is it simply not possible at this point?
Hmm, let me make a quick program and Ill message it to you, showing that the image can be replaced, or Ill record on fraps and link you to it.
necromedes Dec 24, 2015 @ 1:10pm 
Originally posted by YeeFee (Ferret):
Originally posted by Alex AmFm:
gmc is your home buddy
If thats directed to me I hope you notice that your attitude is exactly why people don't like GMC here, you sound like a bigot "Ooo GMC is so toxic so I'll be a toxic ♥♥♥♥♥♥♥ here too" Sure your advice was valid I should have included a link to that docs file as well, but that doesnt mean you need to be an ♥♥♥♥♥♥♥, I honestly assume if your going to use a developers software that you'll read the whole developers manual (the docs in this case).

Maybe its you that belongs in GMC, where you can call others ♥♥♥♥♥♥♥ for doing something wrong.

Originally posted by necromedes:

Hmm... I just tried replacing the image in the folder with another image of the same name, same size, etc... and it is still using the originally provided png file. Am I missing something or is it simply not possible at this point?
Hmm, let me make a quick program and Ill message it to you, showing that the image can be replaced, or Ill record on fraps and link you to it.

I would greatly appreciate that. Thank you!
🐭 Dec 24, 2015 @ 1:21pm 
Actually much better idea, and I hope you can trust me on this, but could you add me to friends and send me your project file? (use mega or something, make a .gmz) And I can edit the game and make a change log so you don't repeat the mistake?
🐭 Dec 24, 2015 @ 1:22pm 
I cant upload high quality videos so you wont be able to read the text well.
🐭 Dec 24, 2015 @ 1:42pm 
are you making a draw event where you draw the sprite?
necromedes Dec 24, 2015 @ 3:14pm 
01: I don't need to send you my game copy because there is literally nothing else in it yet. Its just the code that I have posted here.

02: Can you simply write out a detailed explanation of how to do it instead of a video?

03: No, I am not using a draw event. All of this has been done in a create event.
🐭 Dec 24, 2015 @ 4:55pm 
You need to draw the sprite mate, something like:

CREATE EVENT:
sprite=sprite_add(...);
if(!sprite) //you should include an error check.
{
show_message("problem with sprite Dragons.png error 1 is missing!");
}

DRAW EVENT:

if(sprite)
{
draw_sprite(sprite,image_index,x,y);
}
necromedes Dec 24, 2015 @ 6:22pm 
I am assuming that the draw code should read if sprite_index = or if sprite_exists? Please be detailed.
🐭 Dec 24, 2015 @ 6:39pm 
CREATE EVENT
global.sprite = sprite_add("dragons.png", 0, 0, 0, 0, 0); //create a var, it reads to add the file dragons.png to memory at frame 0 (first frame) with no additional effects

if(!sprite) //check for sprite if(!something) is if something doesnt exist, the ! is sorta like no/false
{
show_message("Error 1 Sprite dragons.png MISSING!!!"); //display message error 1
}

DRAW EVENT
if(sprite) //draw sprite if it exists, notice how there is no !
{
draw_sprite(global.sprite,0,0,0); //draw at 0,0 of where object is placed in room (top left corner of it)
}
Last edited by 🐭; Dec 24, 2015 @ 6:50pm
< >
Showing 1-15 of 16 comments
Per page: 1530 50

Date Posted: Dec 24, 2015 @ 12:38pm
Posts: 16