Jump to content


Photo

draw_surface does nothing [probably solved]


  • Please log in to reply
4 replies to this topic

#1 banov

banov

    GMC Member

  • GMC Member
  • 1160 posts
  • Version:Unknown

Posted 03 June 2012 - 01:11 AM

This is a problem I'm encountering in GameMaker 8.1.

I'm encountering a weird issue. I'm hoping it's something simple I've overlooked, but...
//draw_blurshape( sprite, x, y, glow width, color, alpha )
var quality,surf,mx,my;
quality=10;
surf=surface_create_color_alpha(512,512,c_black,0);

mx=(sprite_get_width(argument0)+(argument3*2)+80)/2;
my=(sprite_get_height(argument0)+(argument3*2)+80)/2;

if surf!=-1{
surface_set_target(surf);
for(a=-quality;a<=quality;a+=1)
{
for(b=-quality;b<=quality;b+=1)
{
draw_sprite_color(argument0,0,mx+(a*argument3/quality),my+(b*argument3/quality)
,1,1,0,c_white,(1/(quality*8)));
}
}
surface_reset_target();
surface_save(surf,"glow.png"); //test
var s;
s=sprite_create_from_surface(surf,0,0,sprite_get_width(argument0)+(argument3*2)+80,sprite_get_height(argument0)+80+argument3*2,
1,1,mx,my);
draw_sprite_ext(s,0,argument1,argument2,1,1,0,argument4,argument5); //more test
sprite_delete(s);
draw_surface_ext(surf,argument1-(mx),argument2-(my),1,1,0,argument4,argument5);
surface_free(surf);
}

For some reason, when I run the above code, draw_surface does not work. As you can see, to test some ideas I tried saving out the surface to an external file, and I also tried saving it as a sprite and drawing the sprite to the screen. Both of these test methods worked; the surface appears as intended. But draw_surface does nothing.

Any ideas what the cause may be?

Edited by banov, 03 June 2012 - 03:42 AM.

  • 0

#2 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 03 June 2012 - 01:22 AM

Looks like you're drawing to the surface in the draw event?

You should never change the drawing target while you are actually drawing on the screen, that is, never use it in drawing events. This will cause serious problems with the projection and viewport.


  • 0

#3 Beaver

Beaver

    GMC Member

  • GMC Member
  • 82 posts
  • Version:GM8.1

Posted 03 June 2012 - 02:54 AM

It could have something to do with using my as a variable.

Edited by Beaver, 03 June 2012 - 02:55 AM.

  • 0

#4 banov

banov

    GMC Member

  • GMC Member
  • 1160 posts
  • Version:Unknown

Posted 03 June 2012 - 03:42 AM

Looks like you're drawing to the surface in the draw event?


You should never change the drawing target while you are actually drawing on the screen, that is, never use it in drawing events. This will cause serious problems with the projection and viewport.

Ah, I bet that's it...
Drat. That really ruins the flow of this. :P

Also does anyone have any idea what "my" is...? It doesn't highlight in gm, so it may just be a mistake in the forum's code formatting?
  • 0

#5 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 03 June 2012 - 03:58 AM

my is a keyword in some other languages, e.g. Perl. My guess is that the forums {code} tag is just formatted to try accommodate all languages. (my isn't anything in GM)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users