(See related changeset on CodePlex)
Registering the tap gesture wasn't as bad as I thought. In the process, I changed the GameplayEntity class so that it has the additional properties and methods:
- ChildEntities: A list of child GameplayEntitiy objects. For now, only the PuzzleGrid contains children, which are the PuzzleSquare objects.
- ClientRect: Instead of having X, Y, Width, Height implemented in every GameplayEntity, this property is a Rectangle. This was done mostly to simplify hit-testing, but also makes the code cleaner overall.
- AcceptsInput (boolean): This property is used to exclude GameplayEntity objects from being asked for hit-testing. It doesn't seem very necessary, though.
- HandleTap(int x, int y): This public method is called by parents to see if any of its children can accept the input. If none of the children can, then the object itself is queried.
- OnTap(int clientX, int clientY): Called when a tap has been accepted. Coordinates local to the entity are used for simplicity.
The PuzzleSquare class overrides OnTap like this:
protected override bool OnTap(int clientX, int clientY)
{
Debug.WriteLine(string.Format("Square ({0}, {1}) tapped at client ({2}, {3}).", this.GridX, this.GridY, clientX, clientY));
return false;
}
Next up, I'll make those taps select the squares (change background color). After that, I'll get started on the HUD buttons. I should probably make a generic button class for that.
0 comments:
Post a Comment