Jump to content


Photo

Screen Drawing [SOLVED (FOR REAL THIS TIME)]


  • Please log in to reply
9 replies to this topic

#1 sebmansigh

sebmansigh

    GMC Member

  • GMC Member
  • 9 posts
  • Version:GM8

Posted 25 March 2012 - 09:20 AM

Hello, I'm relatively new here, and I have a few questions regarding screen drawing. Here's my problem:

Basically, I'm writing all of my cut-scenes in notepad (which worked wonders on my screen transitions, although the game wrote those text files), and It works fine...
except that only the dialogue box, my character, and the save point get drawn. I've tried switching around screen_redraw() and screen_refresh(), and that gets everything I needed drawn, however; it seems that screen_refresh() only works for a single frame and then the dialogue box disappears...

In the text file (Beginning.PHcut) :
while(DialogueBox("Claire","Ahh, what a lovely day today is! I wonder what Charming's up to... Well, no time to dawdle, I have to prepare for the ball!"))
{
  sleep(33);
  event_perform(ev_step,ev_step_begin);
  event_perform(ev_step,ev_step_normal);
  event_perform(ev_step,ev_step_end);
  screen_redraw();
}


//This is so that I can kind of get my function to last multiple frames, also the player doesn't have control during a cut-scene!
The DialogueBox Function:
Dx = view_xview[0];
Dy = view_yview[0];
DrawMenuRectangle(Dx+16,Dy+16,Dx+622,Dy+180,false);
draw_set_font(SmallTimes);
draw_set_halign(fa_left);
draw_text_ext(Dx+20,Dy+20,"                    "+argument1,32,606);
DrawMenuRectangle(Dx+4,Dy+4,Dx+104,Dy+36,false);
draw_text(Dx+8,Dy+8,argument0);
DrawMenuButton(Dx+582,Dy+140,Dx+614,Dy+172,"A");
screen_refresh();
//This is *supposed* to draw my dialogue box, but it only appears for a frame...
return !(keyboard_check_released(ord('A'))|| (mouse_check_button_released(mb_left) && mouse_x > Dx+582 && mouse_x < Dx+614 && mouse_y > Dy+140 && mouse_y < Dy+172));
//This is for the while loop in the notepad file... I should probably get around to a "MouseOver" function...
EDIT: Also, I think I should mention, I can't cheese myself out of this by creating a sprite of the dialogue box; I don't have the pro version...

Edited by sebmansigh, 31 March 2012 - 12:20 AM.

  • 0

#2 Medusar

Medusar

    GMC Member

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

Posted 26 March 2012 - 04:45 PM

Have you tried removing the screen_redraw() function? Because that executes all drawing events (which presumably don't include the dialogue box), erasing everything you've drawn. And I presume that you've disabled automatic drawing?

In any case, might I suggest a different approach? Make a controller object that draws the dialog box in its draw event (set the depth very low so it draws on top). If you want to take control away from the user, set a global variable that you check before responding to the user's actions.
  • 0

#3 xot

xot

    media multimixer

  • Global Moderators
  • 4651 posts
  • Version:GM:Studio

Posted 26 March 2012 - 05:03 PM

I agree with Medusar, but I also don't get why the provided code doesn't work. Maybe it does and it's just a timing issue. Like Medusar says, screen_redraw() is erasing the dialog. But it should be redrawn when the while state is evaluated and screen_refresh() is called. The best case scenario would be a flickering result. You might try reconstructing the loop with do { } until (), but I wouldn't expect it to work any better. A dialog handling object that worked within the normal game loop would certainly be a better approach if the goal is to have the other objects remain animated.
  • 0

#4 sebmansigh

sebmansigh

    GMC Member

  • GMC Member
  • 9 posts
  • Version:GM8

Posted 26 March 2012 - 09:29 PM

I tried the solution, but it didn't work.

As for turning automatic drawing off, it doesn't matter, the code happens during a step, at which point it repeatedly calls all step events, and, yes, the draw event (screen_redraw()) {A good example of why automatic drawing wouldn't work (in case my explanation was horrible) is an infinite loop}

I might just have to make an object for the dialogue box.

(Thinking about it, I could just modify a line or two of code, rewrite the DialogueBox() script to create an object that destroys itself at the end of each step, after being drawn.)

EDIT:
YES!!!!
I created an object for my dialogue boxes (as above).
My computer crashed when I placed the instance_destroy() method at the End step event (Don't know why), so I put it at the end of the Draw event. IT WORKS!!! My text-file cut-scenes WORK!!! Thank you so much!

Edited by sebmansigh, 26 March 2012 - 10:04 PM.

  • 0

#5 Zesterer

Zesterer

    Professor of Articul

  • GMC Member
  • 1021 posts
  • Version:GM8

Posted 26 March 2012 - 09:41 PM

Try screen_refresh() instead... It won't be perfect, but...
  • 0

#6 sebmansigh

sebmansigh

    GMC Member

  • GMC Member
  • 9 posts
  • Version:GM8

Posted 26 March 2012 - 11:40 PM

Okay... It appeared fixed, but now the game crashes if you let it sit there.

Sometimes it takes a few seconds, other times it can sit there for a while just fine, but I think that the event_perform() function is bugged for the step event(s). I hope this is not the case...

EDIT: With the help of windows task manager, I now know that there is no lag or strain on the system. As of now, I highly doubt that my code is to blame...

Edited by sebmansigh, 26 March 2012 - 11:48 PM.

  • 0

#7 DanRedux

DanRedux

    GMC Member

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

Posted 27 March 2012 - 01:06 AM

This is your problem:

return !(keyboard_check_released(ord('A'))|| (mouse_check_button_released(mb_left) && mouse_x > Dx+582 && mouse_x < Dx+614 && mouse_y > Dy+140 && mouse_y < Dy+172));

You need to be clearer with your if statement's to make it easier to read, but the way I read this is.. If you don't release A (which will be true, obviously), or if you press the mouse on the button, return true. This means it's always returning true, as you are always not releasing A.

Remove the !.
  • 0

#8 sebmansigh

sebmansigh

    GMC Member

  • GMC Member
  • 9 posts
  • Version:GM8

Posted 29 March 2012 - 10:35 PM

Well, that statement tests to see weather the player pressed A, or clicked the button to proceed.

Also, it works fine, except for the fact that the game crashes if you leave it alone for a few seconds.

This is probably a case of me not commenting my code well enough...

Returning true with the dialogue box makes the while statement continue, otherwise the player wouldn't get to read the dialogue box unless they released the 'A' button each frame.

Edited by sebmansigh, 29 March 2012 - 10:36 PM.

  • 0

#9 xot

xot

    media multimixer

  • Global Moderators
  • 4651 posts
  • Version:GM:Studio

Posted 30 March 2012 - 03:46 PM

If your original code is in the draw event or any of the step events, you have an infinite recursion problem which leads to a stack overflow and a crash.
  • 0

#10 sebmansigh

sebmansigh

    GMC Member

  • GMC Member
  • 9 posts
  • Version:GM8

Posted 31 March 2012 - 12:17 AM

I used a variable to ensure that it won't get called again.

Also, I know it isn't an infinite loop because... oh...

really...

Oops... the variable I used to ensure it wouldn't loop was apparantly after the method, resulting in the infinite loop...

Boy do I feel stupid.

Works like a charm now!

Edited by sebmansigh, 31 March 2012 - 12:18 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users