Technology Demo

Visibility Demo

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Spot for images

Intro

This project will show you two different ways of how to control the visibility of an object on the stage.

Individual Visibility

Controlling the visibility of a single object is very easy, and takes only one line of code. False hides an object, and true shows it (it is true by default).

self.entity.visible = false

Group Visibility

To hide a group of objects at the same time, we need to use the visibilityFlags property of the objects, and the visibilityMask property of the viewport.

An object gets their visibilityFlags property set to an integer number that sets the visibility of the object, and the viewport has the visibilityMask also set to an integer. For example, we'll set one of our objects to have a flag of 2, and the mask to have 3. A bitwise AND operation is used to determine which entities will be visible. We'll need to see what the previously set integers would be when converted to binary.

  • 2 = 10
  • 3 = 11
  • In a bitwise AND operation, if there aren't two 1's in a column, then the result is 0. Here, the first column would result in 0 and the second would result in 1. If any of the columns result in 1, then the object will be visible.

    self.cube1.visibilityFlags = 2
    stage:getViewport(0).visibilityMask = 3
    

    NOTE: The visibilityMask overwrites the visible property. If the mask is hiding an object, you can change the visible property, but it will still be hidden until you change the flag.