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?













-->

2011년 8월 20일 토요일

[IPhone Dev] 2 Button Alertview example.


Try the following~

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Title"message:message delegate:self cancelButtonTitle:@"Cancel"otherButtonTitles:@"OK", nil];
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 0)   //NO
    {
        
    }
    else    //OK
    {
        
    }
}



That's all~

2011년 8월 17일 수요일

[Game Center] How to post a score to the Game Center? Here is is!


For using game center, your app should be on the Itunesconnect and enable Game Cener.

If you did that, here is what you have to do now.

It is very simple. Try the following codes.



GKScore* score = [[[GKScore alloc] initWithCategory:@"game category name"]autorelease];
            score.value = totalTime*100;
            
            [score reportScoreWithCompletionHandler:^(NSError* error)
             {
                 if(error != NULL)
                 {
                 }
             }];



It it very easy to post your score but... not much players want to even create account on GameCenter;;

I myself in My App am using both GameCenter and Cocoslive leader boards.

Result?

2000 people in cocoslive leader board.

and 

2 people in GameCenter leader board including me.


Have a good day~ :p

[Cocoslive] How to get a score from Cocoslive? Here it is!


I was gonna post it tomorrow but i decided to post it right now. why?

cause i dont have anything to do right now :p

Get to the point!


#import "CLScoreServerPost.h"

-(void) requestGlobalScore
{

    CLScoreServerRequest *request = [[CLScoreServerRequest alloc]initWithGameName:@"Mayday Timeattack" delegate:self];
  
    
    [request requestScores:kQueryAllTime limit:10 offset:currentScoreflags:kQueryFlagIgnore];

    [request release];
}
 
-(void) scoreRequestOk: (id) sender
{
    NSArray *scores = [sender parseScores]; 
    NSMutableArray * serverScore = [NSMutableArray arrayWithArray:scores];
}
 
 

Try the above lines then you will be find. 

If you have any questions, reply~

[Cocoslive] How to Post score to the cocoslive server

Try the following then you will find no problem with it!

Have fun~ :p

#import "CLScoreServerPost.h"

 

-(void) postScore:(NSString*)userName{
    CLScoreServerPost *server = [[CLScoreServerPost alloc]initWithGameName:@"Mayday Timeattack" gameKey:@"game key from cocoslive"delegate:self];
    
NSMutableDictionary *dict = [NSMutableDictionarydictionaryWithCapacity:3];
[dict setObject: [NSNumber numberWithInt:(int)(totalTime*100)]forKey:@"cc_score"];
[dict setObject:userName forKey:@"cc_playername"];
    
[server updateScore:dict];
}

-(void) scorePostOk: (id) sender
{

}

-(void) scorePostFail: (id) sender
{

}

2011년 8월 16일 화요일

[IPhone Dev] How to create a .plist file for Frame Sheet Animation

http://zwoptexapp.com/flashversion

go to the above site and try below~


1. File - Import Images 
2. Arragne - By Name & Height
3. File - Export Coordinates


Pretty easy huh?



Mayday Timeattack - Free on Appstore


[IPhone Dev] NSMutableArray Bad Access -while NSMutableArray reading

nonatomic


That's the one we have to know.


Im not describe what it is because that is not you wanna know :p


So i just get to the point.


if you get bad access error when you read a NSMutableArray, you may wanna use the array in @property way.


make it as a property then use like this


self.dotArray




@property (nonatomic, retain) NSMutableArray *dotArray;
  



Mayday Timeattack - Free on Appstore


[IPhone Dev] CGPoint in NSMutableArray

Cannot use NSMutableArray with CGPoint.


In .net we use like this


List<CGPoint> list;


but since we don't have that in objective-c, we use this.


NSMutableArray * pointArray = [NSMutableArray array];
        
[pointArray addObject:[NSValue valueWithCGPoint:location]];
[pointArray addObject:[NSValue valueWithCGPoint:lastPoint]];
        
CGPoint retrievedPoint = [[pointArray objectAtIndex:0] CGPointValue];
 
no more words to say.


That's all~



Mayday Timeattack - Free on Appstore


[IPhone Dev] How to CGPoint compare? Here it is!

CGPoint a, b;
if(a == b)



The above codes does not work;; Ah~~~ no~~~


so you have to use below.



if (CGPointEqualToPoint(location, lastPoint)) {


    }

 



Mayday Timeattack - Free on Appstore


[IPhone Dev] Get point from touch

 Getting location for touch!
 
Get the position!

-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:touch.view]; 
}



Mayday Timeattack - Free on Appstore