Archive

Posts Tagged ‘Cocoa’

Cocos2dx Extensions: CCValue

March 25, 2012 1 comment

Hey guys,

i added another small extensions to my github. It is a template class which can be used like the NSValue class from the Cocoa library so basically speaking it allows you to store structs like CCRect/CCPoint in CCArray and CCDictionary which can be incredible useful sometimes.

Clone it here: https://github.com/MarkusPfundstein/Cocos2DX-Extensions

Some example code:


CCRect t1;

t1.size = CCSizeMake(100, 200);

t1.origin = CCPointMake(10, 33);


CCValue<CCRect> *value = CCValue<CCRect>::valueWithValue(t1);


CCArray *array = CCArray::arrayWithCapacity(2);

array->addObject(value);


CCRect t2;

t2.size = CCSizeMake(100, 200);

t2.origin = CCPointMake(10, 33);


CCValue<CCRect> *v2 = CCValue<CCRect>::valueWithValue(t2);


CCValue<CCRect> *v3 = static_cast<CCValue<CCRect> *>(array->objectAtIndex(0));


CCValue<CCRect> *v4 = CCValue<CCRect>::valueWithValue(v3);

CCRect rectv4 = v4->getValue();

rectv4.size = CCSizeMake(10,10);


if (v3->isEqualToValue(v2))

{

    CCLog("Equal");

}


if (v3->isEqualToValue(v4))

{

    CCLog("still equal");

}