Jump to content


Photo

Please explain how drawing/loading works


  • Please log in to reply
1 reply to this topic

#1 stoneyftw

stoneyftw

    GMC Member

  • GMC Member
  • 112 posts
  • Version:GM:Studio

Posted 16 April 2012 - 07:05 AM

I'll give a simple example, because this is REALLY stumping me.

Script delay():
delay = 500000;
while(delay>0) {
delay = delay -.1;
}

Room 1:
Contains object_a -> On left mouse click, load room 2.

Room 2:
Contains object_b -> On create, run the following:
draw_set_color( c_blue );
        draw_set_font( font0 );
        draw_set_halign( fa_center );
        draw_set_valign( fa_center );
for(a=0;a<=4;a=a+1)
{
    for(b=0;b<=3;b=b+1)
    {
        draw_text( 400, 400, string(a) + '-' + string(b));
        delay();
    }
}

Now, I would think that upon clicking on object_a, the game would load room2, load object_b, run the create script, which SHOULD iterate through the for loops, drawing a-b in each iteration, delaying in between.

What happens, is that I click on object_a, and it seems that the delays happen before room 2 is even loaded, and then "snap", room 2 loads and all of the drawing happens at one time.

I've tried substantially increasing the delay, which just increases the time before the "snap" happens. I've tried using sleep. Same thing.

Can someone explain to me whats going on here? This should be able to be executed as simple as this...
  • 0

#2 Yal

Yal

    Gun Princess

  • Global Moderators
  • 5837 posts
  • Version:GM8.1

Posted 16 April 2012 - 07:14 AM

delay = 500000;
while(delay>0) {
delay = delay -.1;
}

Hmm... first of all, while this technically works, I wouldn't recommend doing it - the delay will depend on how fast the processor is, and on really bad computers the game will seem like it's crashed, while on really good computers the delay won't even be noticeable! I'd use sleep() instead - it's also nicer on the processor. Clogging it up with loads of unnecessary processing is in general always a bad idea.




The main reason your code won't work is that you call draw_text() to draw on the "Internal Surface" but you never update the screen with the internal surface. So basically all the drawing happens, but you never get to see it. Also each time a Draw Event happens the first thing that happens is that the background color and images are drawn to the internal image so everything you draw outside a draw event will be erased.

To draw outside a draw event, you need to call screen_refresh() once you've drawn everything to refresh the screen with the internal surface.

Also, NOTE! When drawing outside a draw event you specify the coordinates on the internal surface to draw on, so you should NOT take the view into the account - if you draw something at view_xview + 64, for instance, and the view is in the right-hand part of the room, this stuff won't be visible on the internal surface since you draw outside it. To draw the text properly outside of a draw event, draw it at just 64 instead of view_xview + 64.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users