Trying to draw multiple lines in a loop in a draw event?

Gozeraye

  • Posts: 6
Hi!

I'm making a game for a college portfolio  and my game requires a grid with squares in it. The squares are completely cosmetic and will not be in the final game but I need them as a point of reference so I know where the spaces are as I program.

I tried doing this by drawing one large region to show the whole area and a bunch of smaller region to represent each space. However while it drew the larger region  it couldn't draw the smaller ones. The game just takes forever to load and then doesn't have the smaller regions drawn. So I figured that the game engine just couldn't handle the 625 regions  I needed (thats a large region with 25 small regions across and down at 20 pixels each) so I decided to do this with squares instead.  ???

STILL DIDN'T draw them all! So I decided it would be simpler to draw 25 horizontal lines and 25 vertical lines across the region to give the game less to draw and STILL DOES. NOT. WORK.   >:( It will draw the first line and that's IT. I have a deadline to make and this is so frustrating. I have a picture of the draw behavior and the resulting screen . 

numOfSquares = Number of squares in each row
squareSize          = The size of each smaller square that needs to be represented
regionX                 = The x coordinate of the top left corner of the main region (where all the smaller squares are)
regionY                 = Same as regionX, but the Y coordinate.
maxRangeX       =  The maximum value of x in the giant square AKA the x coordinate of the bottom right corner
maxRangeX       = Same as maxRangeX but the maximum Y

Any suggestion to  other way to do this rather than what I'm already trying to  implement is appreciated   :)

mdotedot

  • Posts: 1654
Hello Gozeraye,

Welcome to the forum.

When debugging you should consider using the Flow->Debug->Print block. This will print text in the logviewer.
You could use that block together with []&[] text block to display text in the logviewer with the contents of your variables.

I replaced your attributes with static values since I don't know what yours are:

(This produces a lot of lines , but of course no square since you only draw one line [use rectangle for boxes!])

A few tips:
* Use stroke color instead of color for the line since it will default to black (which you obviously wanted)
* For the next step you probably are going to nest another repeat until loop <- BEWARE nesting [current loop count] can have bad results since nested [current loop count] is not always the last nested loop !
* When creating actors and regions  you might want to turn on debug drawing to ensure that what you want actually is created (Run->Enable debug drawing)

Hope this helps and have fun with Stencyl!

Best regards from
M.E.
(P.S. if you are on deadline and need to continue working : I'm on chat now so you can ask me other questions)


Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

Gozeraye

  • Posts: 6
Thanks! But i can't get the print block to show what's printed out :( Is there a certain view you have to be in to see this?

Gozeraye

  • Posts: 6
Okay, this is weird. For some reason the draw event doesn't take numbers that were declared outside of the draw event.

Gozeraye

  • Posts: 6
Thanks medotedot! 

I got it to work with the template you supplied. I just had to enter the values of the coordinates for each line as opposed to having the draw event retrieve  and calculate them for me. For some reason the draw event can retrieve values from another even in the same behavior, and calculate it's own, but not both at the same time. This may be because the draw event needs to do what it does fast (considering it has to draw a frame up to 60 times a second) it takes shortcuts and just doesn't draw what it doesn't have time to do before the next frame begins, which would explain why it has enough time to calculate the coordinates for and draw the first line but skips the rest. That's my theory anyway.

Much appreciated!  Here is a marching band of smiley faces:
 :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D

« Last Edit: May 02, 2015, 03:58:02 pm by Gozeraye »