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

Drawing to Surface

Neptune

Member
Hello!
I'm trying to draw some sprites to a surface. However, they do not appear?
If I change the draw_clear_alpha to a value higher than 0, I can see the surface is indeed in the right area.

Code:
if active = true
{
        if surface_exists(surf) {draw_surface(surf,xx,y);}
        if surface_exists(surf) {surface_set_target(surf);}
        draw_clear_alpha(c_black,0);
       
        for(i = 0; i < (sprite_width/160)+1; i++)
        {
            for(a = 0; a < (sprite_height/160)+1; a++)
            {
                draw_sprite(test,0,x+160*i,y+160*a);
            }
        }
       
       
       
       
        surface_reset_target();
}
Any ideas or suggestions are greatly appreciated!
Thank-you,

Vether
 
P

PlayLight

Guest
Hi Vether,
You have the right idea, just not executing in the correct order.
First check if the surface exists. (create if not)
Target and prep the surface.
Draw to the surface.
Reset surface target.
Draw the surface (within a draw event).

Example:
Code:
[STEP EVENT]
if ( active )
    {
    if !( surface_exists( surf ) ) { surf = surface_create( surfWidth, surfHeight ); }
    surface_set_target( surf );
    draw_clear_alpha( c_black, 0 );

    // DRAW  YOUR SPRITE/S TO SURFACE NOW

    surface_reset_target();
    }

[DRAW EVENT]
if ( surface_exists( surf ) )
    {
    draw_surface( surf, posx, posy );
    }
 
Last edited by a moderator:
P

PlayLight

Guest
No worries, could you explain your draw_sprite code to me?
also it would help to know the following as well.

What is it you are trying to achieve?
What's the width and height of surf?
What's the width and height of test sprite?
What's the width and height of the sprite_index (of the instance which is calling this code)?
 
Top