Home > Cocos2dx > Cocos2dx Extensions: CCValue

Cocos2dx Extensions: CCValue

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");

}

  1. July 14, 2012 at 4:03 pm

    Thank you so much for this!!!!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: