Liberty BASIC Community Forum
« Sprites Understanding the graphics box »

Welcome Guest. Please Login or Register.
Oct 23rd, 2017, 02:50am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Sprites Understanding the graphics box  (Read 336 times)
michael
Team Liberty BASIC


member is offline

Avatar




PM


Posts: 111
question Sprites Understanding the graphics box
« Thread started on: Jan 11th, 2016, 6:05pm »

EDITED: LOOK BELLOW this post.
I am suspecting that with previous examples of how sprites work, people acknowledge the examples but just do that because they don't want to cause more effort than is necessary in explaining things.
I have seen people that are long time contributors who have posted questions about sprites. I don't think the majority of programmers here understand them.

My first question is about this: Why, when you have a window declared do you add .g?
Here is a clip:
Code:
  WindowHeight = 300
    WindowWidth = 400
    graphicbox #w.g, 0, 0, 400, 300
    open "sprite test" for window_nf as #w
    #w "trapclose [quit]"
 


Notice how the graphics box has #w.g and its size, but the window has #w as the window.
In Laymans' terms can someone explain how the graphics box relates to the window and sprites?
I would ask to not use any scrolling background.. Just sprites in the most simple explanation.

Here is a link to Alyce's most simple example.. but it doesn't use the same method as in the index training.

http://lbpe.wikispaces.com/sprite1

So now that I found this link.. my next question is: why would you use a graphics box command if you can just use a graphics window?

« Last Edit: Jan 11th, 2016, 7:07pm by michael » User IP Logged

I like making program generators and reinventing the wheel.. I never make mistakes.. Not ever.. (lie)
Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2282
xx Re: Sprites Understanding the graphics box
« Reply #1 on: Jan 11th, 2016, 7:44pm »

on Jan 11th, 2016, 6:05pm, michael wrote:
My first question is about this: Why, when you have a window declared do you add .g?
Here is a clip:
Code:
  WindowHeight = 300
    WindowWidth = 400
    graphicbox #w.g, 0, 0, 400, 300
    open "sprite test" for window_nf as #w
    #w "trapclose [quit]"
 



Because you are (supposed to) give each control(more accurate terminology, "child window") a unique identifier.

When creating a control, you give it the name #<ParentWindowHandle>.<UniqueName>

In your case, the graphicbox is explicitly created as a child of the main window.

Try creating a random GUI in FreeForm, and look at the code it generates.

Code:
'Form created with the help of Freeform 3 v07-15-08
'Generated on Jan 11, 2016 at 19:37:22


[setup.main.Window]

    '-----Begin code for #main

    WindowWidth = 400
    WindowHeight = 340
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)


    '-----Begin GUI objects code

    graphicbox #main.graphicbox5, 270,   7, 100, 100
    TextboxColor$ = "white"
    textbox #main.textbox1, 130,   7, 100,  25
    statictext #main.statictext2, "StaticText Caption",   5,  12, 108,  20
    button #main.button3,"Button Caption",[button3Click], UL, 135,  47,  96,  25
    ComboboxColor$ = "white"
    combobox #main.combobox4, array$(, [combobox4DoubleClick],   10, 122, 220, 170

    '-----End GUI objects code

    open "untitled" for window as #main
    print #main.graphicbox5, "down; fill white; flush"
    print #main, "font ms_sans_serif 10" 


on Jan 11th, 2016, 6:05pm, michael wrote:
In Laymans' terms can someone explain how the graphics box relates to the window and sprites?


Essentially, the window is the "main" display. The graphic box is a control, a child window, of the main window. In LB, sprites can only be used in graphicboxes. (Whether that graphicbox is from an explicit graphicbox or the automatic one in a graphic window doesn't matter).

on Jan 11th, 2016, 6:05pm, michael wrote:
why would you use a graphics box command if you can just use a graphics window?


So you can use other controls.


When you create a graphic window, the graphicbox is automatically sized to fill the entire window. You cannot place any other controls, and all interaction has to be done directly using the graphicbox.

(You are not supposed to create controls like buttons on top of a graphics window, because it's been known to cause issues with mouse and keyboard detection, among other things)

This is fine for things like games, but is overkill for some applications, it's overkill.


For example, what if I just want to create a basic form, but have my logo on the form?

I'd lay out the form like normal, with regular buttons, checkboxes, radiobuttons, textboxes, etc, and add a small graphicbox(that doesn't have to fill the whole window) that I'd use to display just the logo.
« Last Edit: Jan 11th, 2016, 7:49pm by Chris Iverson » User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
michael
Team Liberty BASIC


member is offline

Avatar




PM


Posts: 111
question Re: Sprites Understanding the graphics box
« Reply #2 on: Jan 11th, 2016, 8:39pm »

Ok.. so lets take part of Carl's demo and dissect the function of the code: ( corrected )
1) You will notice that in graphicbox #w.s (0,301,100,100)- - the two happy faces are created (within the window #w which is 410x450)
2) Later on, within graphicbox #w.g (0,0,400,300) the sprites are added to that graphics box
3) (the window appears to host the graphic boxes and graphicbox #w.g hosts the show of happy faces.)
4) I also noticed that graphicbox #w.g is where the background is created.

I think I am starting to understand the graphics boxes....

So... the main window... #w would be used for controls like buttons and other controls..

Correct?

Code:
 WindowWidth=410
   WindowHeight=450
   UpperLeftX=50
   UpperLeftY=5
   graphicbox #w.g, 0,0,400,300
   graphicbox #w.s, 0,301,100,100
   open "Animation" for window_nf as #w
   print #w, "trapclose [quit]"
   'draw background:
   print #w.g, "down;fill blue"
   print #w.g, "color red;backcolor red"
   print #w.g, "boxfilled 200 150"
   print #w.g, "getbmp landscape 0 0 399 299";
   'set background:
   print #w.g, "background landscape";
   'draw sprite and mask:
   print #w.s, "down; fill white;backcolor black"
   print #w.s, "color black;place 0 40"
   print #w.s, "boxfilled 80 80"
   'masks:
   print #w.s, "place 20 20;circlefilled 18"
   print #w.s, "place 60 20;circlefilled 18"
   'sprite 1:
   print #w.s, "color yellow;backcolor yellow"
   print #w.s, "place 20 60;circlefilled 18"
   print #w.s, "color black;backcolor black;size 4"
   print #w.s, "set 12 55;set 28 55;size 1"
   print #w.s, "place 20 67"
   print #w.s, "ellipsefilled 20 5"
   print #w.s, "Getbmp ball1 0 0 40 80"
   'add sprite, set auto-move
   print #w.g, "addsprite guy ball1"
   print #w.g, "spritemovexy guy 3 2"
  

« Last Edit: Jan 11th, 2016, 10:50pm by michael » User IP Logged

I like making program generators and reinventing the wheel.. I never make mistakes.. Not ever.. (lie)
Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2282
question Re: Sprites Understanding the graphics box
« Reply #3 on: Jan 11th, 2016, 8:52pm »

#w would basically be the parent of any child control on the window.


Technically, you don't have to give child windows separate names(for example, like you said, you could use #w for all your controls).

However, this has the downside of being unable to give your child window commands.


For example, if you wanted to enable or disable a button on command, you wouldn't be able to do so if you didn't give it a unique name.


To disable/enable a button, you send it the command "!disable" or "!enable".

Code:
#main.button, "!disable" 



If you didn't give it a unique name, when you tried to disable it:

Code:
#main, "!disable" 


You'd get an error message saying it's an invalid command, because !DISABLE doesn't work on a parent window, and anything sent to #<WindowHandle> goes to the parent window.



Always giving your controls unique identifiers is so ingrained into me that, despite using LB for ten years now, I didn't even know you could omit the unique identifiers when creating windows until a few months ago!
« Last Edit: Jan 11th, 2016, 8:53pm by Chris Iverson » User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
michael
Team Liberty BASIC


member is offline

Avatar




PM


Posts: 111
question Re: Sprites Understanding the graphics box
« Reply #4 on: Jan 11th, 2016, 9:06pm »

Hold on!!
Are you saying that I should put my button controls within the graphics box and make sure that the graphics box is defined separate from a parent window to get maximum stability?
This would make the main window nothing more than the host for the graphics boxes, which would technically be the place to put all your controls.
User IP Logged

I like making program generators and reinventing the wheel.. I never make mistakes.. Not ever.. (lie)
Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2282
xx Re: Sprites Understanding the graphics box
« Reply #5 on: Jan 11th, 2016, 9:15pm »

on Jan 11th, 2016, 9:06pm, michael wrote:
Hold on!!
Are you saying that I should put my button controls within the graphics box and make sure that the graphics box is defined separate from a parent window to get maximum stability?
This would make the main window nothing more than the host for the graphics boxes, which would technically be the place to put all your controls.


Not quite.

You don't want to put button controls within a graphicbox.


ALL of the controls/visual elements of a window in LB are children to the primary window you open with the OPEN command. They should be treated as exactly that.


My warning a couple posts ago was to explain that you shouldn't create other control types in a graphic window(i.e. a window opened for graphics_*, instead of for window_*)
User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
michael
Team Liberty BASIC


member is offline

Avatar




PM


Posts: 111
xx Re: Sprites Understanding the graphics box
« Reply #6 on: Jan 11th, 2016, 9:19pm »

Thanks.. the previous post seemed to make the main window look like it really was no more than a host


NOTE: if you look at Carls demo you will notice that it sets up a normal window and makes graphics boxes.. interesting...

Now that you have cleared that up, I will now start my next project.
Thanks Chris!!
« Last Edit: Jan 11th, 2016, 10:29pm by michael » User IP Logged

I like making program generators and reinventing the wheel.. I never make mistakes.. Not ever.. (lie)
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls