Skip to content

Instantly share code, notes, and snippets.

View LearnCocos2D's full-sized avatar

Steffen Itterheim LearnCocos2D

View GitHub Profile
-(void) draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform
{
// Drawing the triangle fan. Simple explanation of how a triangle fan is drawn:
// http://stackoverflow.com/questions/8043923/gl-triangle-fan-explanation
// in a triangle fan the first 3 vertices form one triangle, then each additional vertex forms another triangle
// thus number of triangles is number of vertices minus the initial 2 vertices for the first triangle
int numTriangles = _numVertices - 2;
CCRenderBuffer buffer = [renderer enqueueTriangles:numTriangles
andVertexes:_numVertices
@LearnCocos2D
LearnCocos2D / gist:4557102
Last active December 11, 2015 06:08
Scrolling tilemap API from KoboldTouch. It covers practically every need: scrolling to or by position or tile coordinate. Moving with speed, duration or instantly. Check out KoboldTouch at: http://www.koboldtouch.com
/** Scrolls to the coordinate (in points) instantly. */
-(void) scrollToPosition:(CGPoint)position;
/** Scrolls to a tile coordinate instantly. */
-(void) scrollToTileCoordinate:(CGPoint)tileCoord;
/** Scrolls by a certain distance (in points) instantly. */
-(void) scrollByPointOffset:(CGPoint)pointOffset;
/** Scrolls by a certain distance (in tile coordinates) instantly. */
-(void) scrollByTileOffset:(CGPoint)tileOffset;
/** Scrolls to the coordinate (in points) with a given duration (in seconds). */
@LearnCocos2D
LearnCocos2D / gist:4569215
Last active December 11, 2015 07:49
KTTilemap API for the individual aspects of a tilemap (map, layers, tilesets, properties, etc.). All of this is configurable at runtime in KoboldTouch. You can create entire tilemaps with all features from scratch at runtime if you want.
typedef enum : unsigned char
{
KTTilemapOrientationOrthogonal,
KTTilemapOrientationIsometric,
KTTilemapOrientationHexagonal,
} KTTilemapOrientation;
/** Represents a Tilemap. The tilemap is usually created from a TMX file via the parseTMXFile method. */
@interface KTTilemap : NSObject <NSXMLParserDelegate, NSCoding>
@LearnCocos2D
LearnCocos2D / gist:4569305
Last active December 11, 2015 07:49
Multi-Touch & Motion Protocol and related classes from KoboldTouch (http://www.koboldtouch.com). Any controller can register itself as input receiver. All controllers support the multi touch protocol, just implement the methods you need: either receive all touches, or each touch individually, or both!
/** Defines the messages a delegate can implement to handle (multi) touch events.
Simply implement one or more of the KTTouchDelegate protocol messages and register with KTMultiTouchController.
To work with multiple touches iterate over multiTouchEvent.touchEvents. You can also get all touches from uiEvent:
NSSet* touches = [multiTouchEvent.uiEvent allTouches];
*/
@protocol KTMultiTouchProtocol <NSObject>
@optional
/** One or more touches began. The KTMultiTouchEvent contains an array with all active touches. */
-(void) touchesBeganWithEvent:(KTMultiTouchEvent*)multiTouchEvent;
@LearnCocos2D
LearnCocos2D / gist:4569474
Last active December 11, 2015 07:58
KTAction interface with KTMoveAction example from KoboldTouch. Simple, readable code. Actions are reusable. Checks for illegal uses like running the same action on multiple objects and re-running the same action on the same object will automatically restart the action. A specialized variant of actions called "abilities" will be added soon: they …
/** Actions act on (influence, change properties, etc.) a specific model. The defining property of actions is that whatever
they're supposed to do eventually ends, which will remove the action from the model automatically. For example moving the
model to a specific location - upon arrival at the destination the action removes itself from the model and its memory is released.
Note: KoboldTouch actions are quite similar to CCAction* classes. The most notable difference is that they act on KTEntityModel
objects, never on views directly, to conform to the MVC programming model.
Caution: It is illegal to re-run the same action on the same or a different model object while the action is running. You can
however re-run the action after it has been stopped.
*/
@LearnCocos2D
LearnCocos2D / gist:4569409
Created January 18, 2013 22:54
KTMutableNumber interface from www.koboldtouch.com. Like NSNumber but values are mutable and therefor this class is faster than NSNumber in most use cases. It's actually a class cluster for concrete implementation classes like KTFloatNumber and KTInt32Number.
/** Similar to NSNumber, but allows numbers to be modified (hence: mutable). It does not inherit NSNumber, the implementation
is lightweight and encapsulates various classes like KTBoolNumber, KTInt32Number, KTDoubleNumber and so on each containing only
a single property of the given data type. This is what makes NSMutableNumber numbers mutable, they're regular properties of objects
encapsulating integral data types.
Once a concrete subclass of KTMutableNumber has been created using one of the initializers, the type of that number is set and can
not be changed. For example, if you assign a BOOL value to a float number, the BOOL value will be cast to float. Likewise if you
access the charValue property of a number whose type is float, the returned value will be cast from float to char before it is returned.
*/
@interface KTMutableNumber : NSObject <NSCoding>
@LearnCocos2D
LearnCocos2D / gist:4569727
Created January 19, 2013 00:02
Initializer object demo. Instead of initializers with dozens of variants of "initWith…" methods, KoboldTouch makes heavy use of initializer object. These are simple Objective-C classes consisting mainly of properties. They set sensible defaults so you only need to change the properties that have to be set, and those you want to change. Then init…
// set menu options with the initializer object
KTTextMenu* textMenu = [KTTextMenu menuWithTextMenuItems:[NSArray arrayWithObjects:item1, item2, nil]];
textMenu.fontName = @"Arial";
textMenu.fontSize = 48;
textMenu.padding = 16;
// init the menu with the initializer object
KTMenuViewController* menuViewController = [KTMenuViewController menuControllerWithTextMenu:textMenu];
[self addSubController:menuViewController];
bool foo(char* p1, int* p2)
{
// local variable declaration
bool bRet = false; // init all local variables here, assume everything is wrong
int* ptr = NULL;
PROFILER_START();
// check input params
if (p1 && p2)
@LearnCocos2D
LearnCocos2D / gist:5474209
Created April 27, 2013 19:02
ObjC uncrustify config
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.4.1 (229)
#
# Alignment
# ---------
## Alignment
@LearnCocos2D
LearnCocos2D / gist:5513061
Last active December 16, 2015 23:19
KoboldTouch physics collision demo code http://www.koboldtouch.com
//
// PhysicsCollisionSceneViewController.m
// _Feature-Demo-Template_
//
// Created by Steffen Itterheim on 01.05.13.
// Copyright 2013 __MyCompanyName__. All rights reserved.
//
#import "PhysicsCollisionSceneViewController.h"