Skip to content

Instantly share code, notes, and snippets.

View LearnCocos2D's full-sized avatar

Steffen Itterheim LearnCocos2D

View GitHub Profile
@LearnCocos2D
LearnCocos2D / gist:6498646
Last active December 22, 2015 16:19
getting SK opengl context (in viewDidAppear or later)
#if TARGET_OS_IPHONE
id context = [EAGLContext currentContext];
#else
id context = [NSOpenGLContext currentContext];
#endif
-(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:77f0ced228292676689f
Last active February 4, 2026 02:02
Overview of Entity Component System (ECS) variations with pseudo-code

For background and further references see: Entity Component Systems on Wikipedia

ECS by Scott Bilas (GDC 2002)

Entity->Components->Update
  • entity = class: no logic + no data OR at most small set of frequently used data (ie position)
  • component = class: logic + data
foreach entity in allEntities do
    foreach component in entity.components do
@LearnCocos2D
LearnCocos2D / gist:d541d9905d1320ad6d2e
Last active December 16, 2016 18:14
Entity Component Systems compared with pseudo-code (variants: GameplayKit, Adam Martin, Scott Bilas)
@LearnCocos2D
LearnCocos2D / gist:4acd1eb6733192aab180
Last active May 31, 2017 17:55
GKMinmaxStrategist stub classes implementing the GKGameModel* protocols for Swift 2.0
/*
Swift classes implementing the GKMinmaxStrategizer protocols, without any logic.
You can use these as a template, copy & paste them into your project and start working. ;)
This gist is provided by http://tilemapkit.com and released into public domain.
Here's my tutorial about GKMinmaxStrategist: http://tilemapkit.com/2015/07/gkminmaxstrategist-build-tictactoe-ai/
*/
class TheGameModel: NSObject, NSCopying, GKGameModel {