• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Objects are created, but for some of them sprites are not visible.

F

FloresSottile

Guest
I have an object named oSpawner which creates objects named oAlternativeHolder for a Candy Crush look alike game but with numbers written in the "candy". I've been testing my game with subimages made in the GMS2 Editor for my sAlternativeHolder and never bumped into a problem until now that I changed the subimages. I even tried deleting the sprite sAlternativeHolder and creating it again, but I sill have this problem where the objects oAlternativeHolder are created but it's sprite drawn is missing.

I also checked that all sprites are good and not corrupted. I also cleaned cache with the broom icon and manually deleting the project from my temp data. This is the code i'm running for the selection of the subimage (which is selected randomly among all the subimages).

In oAlternativeHolder, Create Event:
Code:
randomize();
ySpeed = random_range(0.3,0.6);
rotation = random_range(0.5,0.8);
image_index = irandom_range(0,sprite_get_number(sAlternativeHolder)-1); // Random selection between the sAlternative sprite subimages
Then, in the draw Event:
Code:
draw_self();
draw_text(x,y,string(numberOnHolder));
A workaround solution that I tried and didin't work either:

oAlternativeHolder, Create Event:
Code:
randomize();
ySpeed = random_range(0.3,0.6);
rotation = random_range(0.5,0.8);
sub_img = irandom_range(0,sprite_get_number(sAlternativeHolder)-1);
Then, in the Draw Event:
Code:
draw_sprite_ext(sAlternativeHolder, sub_img, x, y, 1, 1, 0, c_white, 1);
draw_text(x,y,string(numberOnHolder));
Both are giving me the exact same problem that never happened before with the sprites drawn in the Editor: the objects are created, but the sprite's subimages are not always being drawn or visible.
Lastly, this is my sprite, sAlternativeHolder: http://prntscr.com/psqnlz

Thanks in advance.
 
Last edited by a moderator:

DukeSoft

Member
If you've just added a sprite, you can try clicking the broom icon, which clears cache, and then build again.
I haven't really looked into the code, but that seems to be fine. There might be other causes - but one main cause is usually a cache mismatch.
 
F

FloresSottile

Guest
If you've just added a sprite, you can try clicking the broom icon, which clears cache, and then build again.
I haven't really looked into the code, but that seems to be fine. There might be other causes - but one main cause is usually a cache mismatch.
I did clean the cache, both with the broom and manually. Is there anywhere I'm missing to clean its cache? When I did it manually I went into AppData/GMS2/Cache and it didn't work.
 

Azenris

Member
are the x and y ok? does the text draw that you have in draw too ?
oAlternativeHolder definately has its sprite setup ?
 
F

FloresSottile

Guest
are the x and y ok? does the text draw that you have in draw too ?
oAlternativeHolder definately has its sprite setup ?
They are, that same code worked with sprites that I made myself with the Editor Tool, only difference is that those sprites had image speed different to 0 because it had an animation. Right now I just want them to stay the same sub image. What happens now is that sometimes every sprite gets drawn in its object, but other times they wont, but the object is there and its x and y values are correct. Its just weird. And yes, the sprite has been set up to the object.
 

rIKmAN

Member
They are, that same code worked with sprites that I made myself with the Editor Tool, only difference is that those sprites had image speed different to 0 because it had an animation. Right now I just want them to stay the same sub image. What happens now is that sometimes every sprite gets drawn in its object, but other times they wont, but the object is there and its x and y values are correct. Its just weird. And yes, the sprite has been set up to the object.
Does the sprite have any empty frames?
Wondering if irandom_range() is returning a frame number that contains no image.

Have you tried stepping through the code with the debugger and seeing what the values are?
 
F

FloresSottile

Guest
Does the sprite have any empty frames?
Wondering if irandom_range() is returning a frame number that contains no image.

Have you tried stepping through the code with the debugger and seeing what the values are?
Nope, as you can see here http://prntscr.com/psqnlz there are no empty sprites. I'll need to debug it, but whats weird is that only a sprite change caused this.
 
Top