• 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!

Can't get sprite to draw to surface

F

FireflyX91

Guest
Hello all, I am having a slight problem with trying to draw a sprite to a surface. The problem being that when I view "sur.png", the saved surface, it is just displaying as a blank image with the map_width and map_height dimensions that I have specified. Anyway here's the code I have in my objects Draw event:

Code:
    var map_width = 224;
    var map_height = 448;
    
    if(!surface_exists(surface)){

        surface = surface_create(map_width,map_height);
        
    }
    
    surface_set_target(surface);
    
    draw_sprite(spr_hm1,-1,0,0);   

    surface_save(surface,"sur.png");   

    surface_reset_target();
If anybody can let me know what's wrong, your help would be appreciated ;)

Thanks for your time
 
Hmmm, not 100% sure since I never saved a surfaces but you should NEVER draw a surfaces that you are currently have as a target, might be the same with saving?
 
F

FireflyX91

Guest
Hmmm, not 100% sure since I never saved a surfaces but you should NEVER draw a surfaces that you are currently have as a target, might be the same with saving?
I just tried calling the surface_save() after I had reset the target but that hasn't made a difference...
 
F

FireflyX91

Guest
I'm pretty sure setting the value to -1 causes it to draw the default subimage. I did try setting it to 0 anyway and it just does the same thing.

I'm starting to wonder if there's an issue with the sprite itself, rather than this being a coding error...
 
First, make sure that the code is actually running, and that you aren't looking at some old version of your surface saved to disk.

It is possible that gpu states (alpha, blending modes, shader, projection), could be interfering.

Try just drawing the sprite somewhere on screen to see if it shows up correclty.

EDIT: also, make sure you are drawing in the draw event. Probably also a good idea to keep the surface_save after surface_reset_target, even though it didn't solve your problem.
 
Top