Skip to content

Instantly share code, notes, and snippets.

@talentless
talentless / gist:3129443
Created July 17, 2012 13:39
sprite + particle example
@interface SparkleSprite : CCSprite {
CCParticleSystemQuad * fairyDustTail_;
}
// you can either use a setter (or a property)
-(void) setFairyDustTail: (CCParticleSystemQuad*)fairDustTail;
// or you can create it internally, but in this case you need to call this method after
// the node has already been added to its parent so you can do:
// [self.parent addChild:fairDustTail_]
@talentless
talentless / control.py
Created May 11, 2012 01:40
op dpad psuedocode
# magic numbers
scalePad = 1.5
dragAfterDistance = 60
recenterDelay = 1.2
velocityMultiplier = 9
cornerBuffer = 50
# scheduled method
def step(deltaTime):
timeSinceRecenter = timeSinceRecenter + deltaTime
// quick ugly hack to get touches working on the prototype
if (type === "touchstart" || type === "touchmove" || type === "touchend") {
pos=Crafty.DOM.translate(e.touches[0].clientX, e.touches[0].clientY);
e.x = e.touches[0].clientX;
e.y = e.touches[0].clientY;
}
if (type === "touchstart") type = "mousedown";
else if (type === "touchmove") type = "mousemove";
else if (type === "touchend") type = "mouseup";
if (type === "touchstart") type = "mousedown";
else if (type === "touchmove") type = "mousemove";
else if (type === "touchend") type = "mouseup";
// something similar to this
var lt = Date.now();
var step = function() { var nt = Date.now(); var dt = nt-lt; lt = nt; Crafty.trigger("Step", dt/1000); }
Crafty.bind("EnterFrame", step);
Crafty.bind("Step", function(dt) { /* Do Stuff Here */ });
Crafty.c("Tag", {init: function() { this.requires("2D"); this._defineGetterSetter_setter(); this._defineGetterSetter_defineProperty(); this._tag = 0; },
_tag: 0,
_defineGetterSetter_setter: function() {
this.__defineSetter__('tag', function (v) { this._attr('_tag', v); });
this.__defineGetter__('tag', function () { return this._tag; });
},
_defineGetterSetter_defineProperty: function() {
Object.defineProperty(this, 'tag', {
set: function (v) { this._attr('_tag', v); }
, get: function () { return this._tag; }
Crafty.c("Flippable", {init: function() { this.requires("2D"); },
flipX: function(flipped) { this["_flipX"] = flipped; this.trigger("Changed"); },
flipY: function(flipped) { this["_flipY"] = flipped; this.trigger("Changed"); }
});
Crafty.c("AnchorPoint", {init: function() { this.requires("2D"); this._anchorPoint = [0.5,0.5]; this._defineGetterSetter_setter(); this._defineGetterSetter_defineProperty(); },
_anchorPoint: [0.5,0.5],
_defineGetterSetter_setter: function() {
//create getters and setters using __defineSetter__ and __defineGetter__
this.__defineSetter__('x', function (v) { this._attr('_x', v - this._anchorPoint[0] * this._w); });
this.__defineSetter__('y', function (v) { this._attr('_y', v - this._anchorPoint[1] * this._h); });
this.__defineSetter__('w', function (v) { this._attr('_w', v); this._origin.x=this._anchorPoint[0]*this._w; this.x = this.x; });
this.__defineSetter__('h', function (v) { this._attr('_h', v); this._origin.y=this._anchorPoint[1]*this._h; this.y = this.y;});
NSString *ccRemoveHDSuffixFromFile( NSString *path )
{
#if CC_IS_RETINA_DISPLAY_SUPPORTED
if( CC_CONTENT_SCALE_FACTOR() >= 2 ) {
NSString *name = [path lastPathComponent];
// check if path already has the suffix.
if( [name rangeOfString:CC_RETINA_IPAD_DISPLAY_FILENAME_SUFFIX].location != NSNotFound ) {
CGFloat scaleFactor = (__ccPointScaleFactor == 1) ? __ccContentScaleFactor : (__ccContentScaleFactor / __ccPointScaleFactor);