none
Help! Numbers get overwritten. RRS feed

  • Question

  • Hello, i try to make a Cookie-Clicker like game.. But when i try to write a number, it just write over anothernumber.. Ill show you the Code! Ive marked it in the Code:

    GraphicsWindow.Height=700
    GraphicsWindow.Width=800
    Controls.ButtonClicked=buttonclicked
    GraphicsWindow.BrushColor="Black"
    chopW=Controls.AddButton("Chop Wood",200,30)
    sellW=Controls.AddButton(" Sell Wood ",200,60)
    GraphicsWindow.BrushColor="Green"
    GraphicsWindow.DrawBoundText(30,10,400,"Wood")
    GraphicsWindow.BrushColor="Black"

    -------------------------------------------------------------------

    GraphicsWindow.DrawBoundText(30,30,800,wood)     - This is the TextWindow, where the number of wood gets shown.
    -------------------------------------------------------------------
    wood=0

    Sub buttonclicked
      lastbutton=Controls.LastClickedButton

    ----------------------------

      If lastbutton = chopW Then         
        wood=wood+1                    - It starts at 0 Wood and everytime i click the chopW the number get up by 1. But the 0 doesnt turn into a 1 it. The 0 stays and the 1 just gets written over the 0. P

    ----------------------------------------------

      ElseIf lastbutton = sellW Then
        GraphicsWindow.ShowMessage("Du hast ein Stück Holz verkauft!","Holz verkauft")
      EndIf
      GraphicsWindow.DrawBoundText(30,30,800,wood)
    EndSub

    Saturday, November 9, 2013 8:49 PM

Answers

  • All of the GraphicsWindow.Draw... and GraphicsWindow.Fill...  commands just draw on top of what is already there.

    You either have to clear the region before each draw - perhaps a FillRectangle with the background color (option 1), or use a Shape or control, perhaps a textbox (option 2).

    See here for more details for GraphicsWindow layers.

    This is example of the easier option 1 solution

      GraphicsWindow.BrushColor=GraphicsWindow.BackgroundColor
      GraphicsWindow.FillRectangle(30,30,800,100)
      GraphicsWindow.BrushColor="Black"
      GraphicsWindow.DrawBoundText(30,30,800,wood)
    

    Saturday, November 9, 2013 9:26 PM
    Moderator
  • SB features 2 types of graphics: static & dynamic.

    1. Static -> Drawing functions from GraphicsWindow. It's like a painter brushing some canvas. Once drawn, it stays. And can't be erased w/o blurring other drawings around it.
    2. Dynamic -> Functions from Shape & Control. They're layers floating atop canvas. We can modify, move, hide them w/o affecting the canvas below!

    So, GraphicsWindow.DrawBoundText() doesn't erase its previous drawing. It draws upon any previous 1s!

    Either you clear whole screen, or at least the region you wanna draw upon again, or...

    use Shape.AddText() to create an object that you can freely change its text dynamically!  :D


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Saturday, November 9, 2013 9:29 PM
    Answerer

All replies

  • All of the GraphicsWindow.Draw... and GraphicsWindow.Fill...  commands just draw on top of what is already there.

    You either have to clear the region before each draw - perhaps a FillRectangle with the background color (option 1), or use a Shape or control, perhaps a textbox (option 2).

    See here for more details for GraphicsWindow layers.

    This is example of the easier option 1 solution

      GraphicsWindow.BrushColor=GraphicsWindow.BackgroundColor
      GraphicsWindow.FillRectangle(30,30,800,100)
      GraphicsWindow.BrushColor="Black"
      GraphicsWindow.DrawBoundText(30,30,800,wood)
    

    Saturday, November 9, 2013 9:26 PM
    Moderator
  • SB features 2 types of graphics: static & dynamic.

    1. Static -> Drawing functions from GraphicsWindow. It's like a painter brushing some canvas. Once drawn, it stays. And can't be erased w/o blurring other drawings around it.
    2. Dynamic -> Functions from Shape & Control. They're layers floating atop canvas. We can modify, move, hide them w/o affecting the canvas below!

    So, GraphicsWindow.DrawBoundText() doesn't erase its previous drawing. It draws upon any previous 1s!

    Either you clear whole screen, or at least the region you wanna draw upon again, or...

    use Shape.AddText() to create an object that you can freely change its text dynamically!  :D


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Saturday, November 9, 2013 9:29 PM
    Answerer
  • Thanks for the quick answer and help! Im using Option 1 now. :)
    Saturday, November 9, 2013 9:31 PM