2014년 7월 10일 목요일

Cocos2d-x [Touch Listener] addListener instead of SetTouchEnabled(true)

SetTouchEnabled is deprecated.
It still works. But you do not want another warning.
Here is the key to avoid the warning.


auto listener = cocos2d::EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    
    listener->onTouchBegan = [&](cocos2d::Touch* touch, cocos2d::Event* event)
    {
        Point p = touch->getLocation();
        cocos2d::Rect rect = this->getBoundingBox();
        
        if(rect.containsPoint(p))
        {
            this->onTouchBegan(touch, event);
            return true; // to indicate that we have consumed it.
        }
        
        return false; // we did not consume this event, pass thru.
    };
    
    listener->onTouchEnded = [=](cocos2d::Touch* touch, cocos2d::Event* event)
    {
        this->onTouchEnded(touch, event);
    };
    

    cocos2d::Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(listener, 30);


Check my game.
Mr Boss




Cocos2d-x Few Test Result

1. CCArray is replaced with Vector<T>.
Vector is clearly faster than CCArray. No need to cast type and preserve the data. Easy to manipulate with overriding functions.

2. std::string + operator
int index = 23;
std::string name = "testSprite" + Value(index).asString() + ".png";
Sprite* spt = Sprite::create(name.c_str());
This works fine on iOS. But it crashes 1 out of 20 times on Android.

3. setUserData
You don't want to cast something to (Void*). It takes too long to cast. The performance will be very lowered. And few more problems will occur like Vector not recognizes it.

4. MotionStreak
It still takes some CPU resources. Don't use it too much.



5. Check my game.
Mr Boss
https://play.google.com/store/apps/details?id=com.magmon.MrBoss




cocos2d-x [Tile Map] How to load tmx tile map. TMXTileMap, Value, ValueMap and GID

TMXTileMap* tileMap = TMXTileMap::create("LegendDary_1_1.tmx");

int tileGID = 0;

Value properties = tileMap->getPropertiesForGID(tileGID);
ValueMap map = properties.asValueMap();

std::string name = map.at("Enemy").asString();

if(name.compare("Wolf") == 0){
     CCLOG("Wolf loaded");
}



Check out my game :p

Mr Boss

https://play.google.com/store/apps/details?id=com.magmon.MrBoss

cocos2d-x 3.0 [Map] How to use Map instead of CCDictionary


auto sp0 = Sprite::create();

Map<std::string, Sprite*> map0;
std::string mapKey0 = "firstSprite";
map0.insert(mapKey0, sp0);
Sprite* spt = map0.at("firstSprite");



Check out my game :p

Mr Boss

https://play.google.com/store/apps/details?id=com.magmon.MrBoss


Cocos2d-x 3.0 [Vector] How to use Vector instead of CCArray

Cocos2d-x 3.0 has changed CCArray class to Vector<T>. It's basically from the std::vector<T>. But more familiar and easy to use.

Vector is not a pointer so you have to use '.' instead of '->'

cocos2d-x 2.0 uses CCArray which was easy but low performance. Vector clearly shows higher performance.

Below is simple example about how to use the vector in cocos2d-x 3.0.

Have fun coding with cocos2d-x and vector.


Vector<Sprite*> spriteArray;

spriteArray.pushBack(Sprite::create("LegendDary.png"));

int index = 0;
Sprite* sptFromVector = spriteArray.at(index);

spriteArray.eraseObject(sptFromVector);

for(int i = 0;i < spriteArray.size(); i++){
   Sprite* spt = spriteArray.at(i);
}

for(auto spt: spriteArray){
    Point pos = spt->getPosition();
}




Check out my game :p

Mr Boss

https://play.google.com/store/apps/details?id=com.magmon.MrBoss


2012년 9월 12일 수요일

Cocktail Memo: A deadly quick memo taking app



Cocktail memo is an app that take a deadly quick memo.

I made it because I want it.
At first, I thought hand drawing is more faster than typing. But I realized that with more than 15 letters typing is faster than handwriting. 
So I made a really quick memo taking app.

I'm proudly present the Cocktail Memo.




App Description:

Cocktail Memo is 


1. A one-line-memo application. 

2. Quick, I mean REALLY quick. 

3. Very Simple. 
4. Beautiful. 
5. Has 5 themes. 



To use Cocktail Memo you can 



1. Pull down to add an item. 

2. Swipe from right to left to delete an item. 

3. Swipe from left to right to bring an item to the top. 



You can change the theme with the bottom line. I do not think a description is necessary. It is that simple. 



Don't you think this is what you want?













-->