Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How to draw a 10 x 10 grid (like a checkerboard)?

I'm just getting started with TI. I want to create a game that uses a 10x10 grid board similar to checkers. While I can put a custom image in place that looks like a grid, I need to really create a "invisible" or "virtual" grid to overlay it so I can tell when a piece is in a certain square.

Any ideas on how best to create this invisible grid programmatically in TI?

I'm focused on iPhone right now, but something that works in both iPhone and Android is obviously preferred.

I'm using iPhone SDK 4.0 with Titanium SDK 1.4.1

— asked August 21st 2010 by Stephen Babigian
  • game
  • grid
  • layout
  • view
0 Comments

2 Answers

  • I think you're going to have to create a view for each square in the grid. You'll likely be hanging listeners and other objects on each one, so you probably want them all to be distinct. Depending on the size of your grid, that could be very tedious. :) Good luck.

    — answered August 22nd 2010 by Clifton Labrum
    permalink
    0 Comments
  • Here's what I did so far, subject to change of course:

    • Created a main window.
    • Created a view that holds the background image for the gameboard.
    • Added a for loop that creates a 10 rows of 10 views, each with an eventListener.
    • Each of those "cells" has a title like: a0,a1,a2…etc

    All pretty simple actually.

    Now I just need to figure out how to get one of those cells to see when I drag a piece onto it.

    — answered August 23rd 2010 by Stephen Babigian
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.