Lights Out with Daikon Forge

DaikonForgeLightsOut

This Grids example uses Daikon Forge for cell rendering to implement the game Lights Out.

It’s very similar to the examples using NGUI, but there are some differences and things to look out for:

  • Daikon Forge uses proper GUI coordinates, which means the origin is at the top left of the screen, and Y is inverted. You can deal with this by adding the RelfectAboutX in your map construction method chain. This will correctly invert Y coordinates. However, for anchoring and alignment, you still need to flip vertical directions. For instance, instead of anchoring top left, you will anchor bottom left. The example shows the grid coordinates of each cell, this will make it easier to see if they are correct.
  • GUI coordinates are relative to the parent container. The map is set up to convert from grid coordinates to these panel-relative coordinates. In this example, the grid container is GridRoot. The rectangle you feed to align your grid must be the dimensions of this panel.
  • Daikon Forge GUI anchors its sprites top left by default; remember to tell your map (by adding AnchorBottomLeft to the map construction chain. Remember vertical directions are inverted!)
  • Mouse input is handled on the grid panel. We only have access to the mouse coordinates – this is first converted to Unity world coordinates (using the UI camera), and from this a panel-relative coordinate is calculated using an extension method GetRelativePosition. This relative position is consistent with the positions of cell placements – when you feed it to your map, you will get the correct grid position.
  • The DFCell component is implemented as a dfPanel, which has a sprite and label as children. This allows us to add cells to the grid root (a dfPanel) using AddControl, which will ensure correct layout.
  • Make sure pixel perfect is switched off (on the dfGUIManager) if you want to run it at different resolutions. Otherwise, make sure all your resolutions match up: the resolution set in the build settings, the resolution you run it in the editor (for testing), and the resolution set up on DfGUIManager.
  • This example use the script PanelEvents to capture input. Make sure to add it to the panel in your own projects (or add your own version there-of) to the panel to capture mouse input. Also make sure there is a main camera (tagged as such) so that input is handled.

Download

Make a new project, import Grids, import Daikon Forge, and finally import this package. Then open the LightsOut scene to look at the setup or run the game.

(We have had some mysterious behavior with this package before – it should just work. If it doesn’t please let us know, because the mysterious behavior may be back.)

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top