Home > Cocos2D-Touchable-Nodes

Cocos2D-Touchable-Nodes

Cocos2D-Touchable-Nodes is a project mainly written in Objective-C, it's free.

Provides lightweight CCNodes which can respond to touches within a given rectangle.

README TouchableNodes

Created by Jay Roberts on 2010-02-25. Copyright 2010 GloryFish.org. All rights reserved. License: http://www.cocos2d-iphone.org/wiki/doku.php/license (GNU LGPL v3 with an extension)

Lightweight classes providing invisible and semi-invisible UI elements for responding to touches. Supports canceling a button press by dragging off of the button.

Created for use in TCG Counter http://tcgcounter.com where most of the UI is provided by a single static background image and touches are indicated with particle system emits. TouchableRegions are used to define static button locations on the screen and are wired into methods on the parent view.

TouchableOverlays are also used for simple static buttons that are part of the background but also have a hover state. An additional CCSprite is provides which is displayed when touched and faded out when cancelled.

Usage:

// Layer init -(id)init { TouchableRegion *button = [TouchableRegion regionWithRect: CGRectMake(0.0f, 100.0f, 100.0f, 100.0f) target: self selector:@selector(buttonPress)]; button.showOutline = YES; // Optionally draw an outline for testing [self addChild: button z: 1];

}

// Layer method -(void) buttonPress { NSLog(@"Button Pressed!"); }