none
Shapes Add, Hide then Show trouble RRS feed

  • Question

  • GNM524    Challenge: "Use the Clock to time user response times when a box is flashed up on the GraphicsWindow"

    Does anyone know how this works?

    What I wanted to do is Add 1 shape, then hide it in the program setup. Then let the timer flag the ShowShape subroutine which Zooms and positions the shape.

    But I found that I have to, only at the start where the shape is added, run the ShowShape subroutine first before I can hide it.

    It's got me stumped, because later in the program the Shape is hidden then Zoomed & Positioned then I show it and all the coordinates are doing what their supposed to.

    Sunday, November 3, 2013 11:06 AM
    Moderator

Answers

  • I see the issue,

    Interesting!

    The first step to debug and understand this is to simplify as much as possible, here's mine:

    gw = GraphicsWindow.Width
    gh = GraphicsWindow.Height
    boxSize = 3
    box = Shapes.AddRectangle(boxSize, boxSize)
    Shapes.HideShape(box) 'Comment this to see problem effect disappear
    ShowBox()

    Program.Delay(1000)
    HideBox()

    Sub ShowBox
      boxZoom = 20
      boxX = gw/2
      boxY = gh/2
      Shapes.Zoom(box, boxZoom, boxZoom)
      Shapes.Move(box, boxX, boxY)
      Shapes.ShowShape(box)
    EndSub

    Sub HideBox
      While boxZoom > 0.5
        boxZoom = boxZoom - 0.2
        Shapes.Zoom(box, boxZoom, boxZoom)
        Program.Delay(5)
      EndWhile
      Shapes.HideShape(box)
    EndSub

    Obviously the combination of hide, show, zoom and move is causing what you see.

    When you zoom, the zoom is a zoom about the center of the shape.

    When you position a shape it is the upper left corner of the UNZOOMED shape.

    If we put the ShowShape before the zoom and move it seems to work!

      Shapes.ShowShape(box)
      Shapes.Zoom(box, boxZoom, boxZoom)
      Shapes.Move(box, boxX, boxY)

    Without checking SB code in detail it looks like this is a bug/feature of some sort.  Perhaps when the shape is hidden, zoom and move are not handled correctly in some way.

    Also works on your code I think.

    Sunday, November 3, 2013 9:02 PM
    Moderator

All replies

  • I don't really follow what the problem is.

    Perhaps it is the Timer which is first call 1000ms into the run?

    If I delete ShowBox() and Shapes.HideShape(box) at the start, then the box first appears after 1000 ms and it can be clicked by the user.  After the new delay set as Math.GetRandomNumber(2500) + 500, the box disappear and a new one appears.

    Please explain the problem with this.

    Sunday, November 3, 2013 3:02 PM
    Moderator
  • To make the program run properly ShowBox() has to run at set up before Shapes.HideShape(box).

    This is the working setup:

    12:    box = Shapes.AddRectangle(boxSize, boxSize)
    13:    ShowBox()               'initialise boxZoom and position, then hide.  ?????
    14:    Shapes.HideShape(box)

    When lines 13 and 14 are switched the mouse tracking and Zoom animation code play up.

    It's as if I have to initialise the dependent variables in ShowBox() first before I can hide the shape.

    I'm starting to suspect the problem has something to do with:

    boxZoomOffset = ((boxSize * boxZoom) - boxSize) / 2

    This modification sheds a bit of light on it:

    'Timer.Tick = OnTick
    'Timer.Interval = 1000
    
    InitialiseGraphicsWindow()
    box = Shapes.AddRectangle(boxSize, boxSize)
    'ShowBox()               'initialise boxZoom and position, then hide.  ?????
    Shapes.HideShape(box)
    
    flag = "Show Box" 

    What I wanted to do is have the setup as:

    addShape

    hideShape

    Then calculate the dependent variables in ShowShape() each time they are needed.

    It looks a bit like the boxZoomOffset is involved as the Zoom animation animates to the left top corner instead of to the centre.

    Thanks for having a look litdev. I'll test it again without the Timer (the above sample comments out the timer). Very interesting, there must be a reason.

    Sunday, November 3, 2013 8:24 PM
    Moderator
  • I see the issue,

    Interesting!

    The first step to debug and understand this is to simplify as much as possible, here's mine:

    gw = GraphicsWindow.Width
    gh = GraphicsWindow.Height
    boxSize = 3
    box = Shapes.AddRectangle(boxSize, boxSize)
    Shapes.HideShape(box) 'Comment this to see problem effect disappear
    ShowBox()

    Program.Delay(1000)
    HideBox()

    Sub ShowBox
      boxZoom = 20
      boxX = gw/2
      boxY = gh/2
      Shapes.Zoom(box, boxZoom, boxZoom)
      Shapes.Move(box, boxX, boxY)
      Shapes.ShowShape(box)
    EndSub

    Sub HideBox
      While boxZoom > 0.5
        boxZoom = boxZoom - 0.2
        Shapes.Zoom(box, boxZoom, boxZoom)
        Program.Delay(5)
      EndWhile
      Shapes.HideShape(box)
    EndSub

    Obviously the combination of hide, show, zoom and move is causing what you see.

    When you zoom, the zoom is a zoom about the center of the shape.

    When you position a shape it is the upper left corner of the UNZOOMED shape.

    If we put the ShowShape before the zoom and move it seems to work!

      Shapes.ShowShape(box)
      Shapes.Zoom(box, boxZoom, boxZoom)
      Shapes.Move(box, boxX, boxY)

    Without checking SB code in detail it looks like this is a bug/feature of some sort.  Perhaps when the shape is hidden, zoom and move are not handled correctly in some way.

    Also works on your code I think.

    Sunday, November 3, 2013 9:02 PM
    Moderator
  • Litdev, thanks for the nice debug tip.

    I'm not real keen on working around something when i'm not exactly sure what i'm working around.

    I'll do some more debugging and try and isolate the specific cause. If anyone else wants to demonstrate what's happening, always welcome. Could be good debugging practice.

    In the meantime i'll do something a bit wreck less and continue on and work in a menu bar at the top.

    Thanks again.

    Sunday, November 3, 2013 9:19 PM
    Moderator
  • I'll test your idea, I think that is the issue:

    "Perhaps when the shape is hidden, zoom and move are not handled correctly in some way."

    Sunday, November 3, 2013 9:23 PM
    Moderator