EzDevInfo.com

cocos2d-iphone interview questions

Top cocos2d-iphone frequently asked interview questions

How can I disable the touch detection?

How can I disable the touch detection within the action that running, because I don't want the character flying in the sky like a superman if the player clicking and clicking within the action, the character will never land if they keep clicking. I found the method "isDone", is that relate to this method?? player click -> action(cannot click within the action) -> action finish -> click again..... that's what i want~


Source: (StackOverflow)

Texture coordinate Cocos3d [closed]

Here is how I put my texture on my object :

_obj = (CC3MeshNode *)[_world getNodeNamed:@"s0"];
_obj.material.texture = [CC3Texture textureFromFile:@"objTextureLayout.png"];

My object is loaded from 3DMAX and I don't understand why my texture coordinate (from 3DMax) is lost...

An other problem, I don't understand why my normals is flipped on a simple polygon. What could I've forgotten ?

Any suggestion ? I can post some screenshot or even the model with texture for a best comprehension for anybody who can help me.


Source: (StackOverflow)

Advertisements

What is the alternative method for the "self.isTouchEnabled " in Cocos2d 2.0?

When I use the

self.isTouchEnabled = YES

in Cocos2d v2.0 for the layer could be touched,the Xcode give me a tip:

setIsTouchEnabled: is deprecated

Now, I just want to know alternative method for isTouchEnabled.


Source: (StackOverflow)

Should I subclass CCSprite, CCNode, or NSObject?

I see that certain texts always seem to subclass CCSprite. I read somewhere that it is not good to do that and that it is better to start with something basic. I wanted to find out what the pro game developers do in terms of game structure. That is subclass CCSprite or add CCSprite in a NSObject class ETC.

I hope my question makes sense.


Source: (StackOverflow)

duplicate symbol _OBJC_METACLASS_$_ClassName

I am trying to run my cocos2d application and facing this error, as I have recently upgraded my sdk to 4.2 and my cocos2d to 0.99.5.

I tried to clean my project even change the Target ios Deployment but error remains the same. Also rename the className aswell in order to avoid duplication from Library classes names of cocos2d.

ld: duplicate symbol _OBJC_METACLASS_$_MenuSceneNew in /Users/umaidsaleem/Desktop/functionalityTest/build/Debug-iphonesimulator/libcocos2d libraries.a(MenuScene.o) and /Users/umaidsaleem/Desktop/functionalityTest/build/functionalityTest.build/Debug-iphonesimulator/functionalityTest.build/Objects-normal/i386/MenuScene.o


Source: (StackOverflow)

Cocos2d for iPhone vs. Cocos2d-x [closed]

I have worked some with Cocos2d for iPhone and find it delightful. I am starting another project, and have stumbled across Cocos2d-x, a C++ port. I'm tempted by the notion of being able to (with consideration) build for multiple platforms at once. I'm equally comfortable with Obj-C and C++, and am not looking for comparisons between the two languages unless it's specifically related to working with Cocos2d.

Has anyone worked with both versions of the engine, and can you comment on specific pros and cons of the two? Is Cocos2d-x "finished"? Reliable?


Source: (StackOverflow)

Choose a destination with a supported architecture in order to run on this device [closed]

enter image description here

my Xcode is Version 4.4.1

The project worked perfect before updating to this newer version, but now it stopped working


Source: (StackOverflow)

How to draw a solid circle with cocos2d for iPhone

Is it possible to draw a filled circle with cocos2d ? An outlined circle can be done using the drawCircle() function, but is there a way to fill it in a certain color? Perhaps by using pure OpenGL?


Source: (StackOverflow)

Cannot find protocol declaration for CCTargetTouchDelegate/CCStandardTouchDelegate

I have upgraded my project to the latest beta of cocos2d 2.1 and I am now receiving the errors,

Cannot find protocol declaration for CCTargetTouchDelegate

and

Cannot find protocol declaration for CCStandardTouchDelegate

How do I fix this?


Source: (StackOverflow)

Building a simple bridge between objc and lua?

I have integrated Lua with my ObjC code (iphone game). The setup was pretty easy, but now, I have a little problem with the bridging. I have googled for results, etc... and it seems there isn't anything that could work without modifications. I mean, I have checked luaobjc bridge (it seems pretty old and dicontinued), I heard about LuaCocoa but it seems not to work on iphone, and wax is too thick.

My needs are pretty spare, I just need to be able to call objc methods from lua and don't mind having to do extra work to make it work (I don't need a totally authomatic bridging system).

So, I have decided to build a little bridge myself based on this page http://anti-alias.me/?p=36. It has key information about how to accomplish what I need, but the tutorial is not completed and I have some doubts about how to deal with method overloading when called from lua, etc...

Do anybody know if there exist any working bridge between objc and lua on the iphone or if it could be so hard to complete the bridge the above site offers?

Any information will be welcomed.


Source: (StackOverflow)

where to start for game development? UIKit vs Core Animation vs QuartzCore vs OpenGL vs cocos2D

If I was interested in getting across game development on the iPhone/iPAD any suggestions on which technology(s) to start looking into? In fact just a simple bullet on each of these technologies that highlight how it fits into typical game development would be great, as the reason for this question was me not understanding how these fit together. So in this case it's where do these roughly fit in here:

  • UIKit
  • Core Animation
  • QuartzCore
  • OpenGL
  • cocos2D

I was getting the impression that cocos2D would be the way to go, and it seems to be a simpler wrapper for OpenGL? Not sure where that leaves UIKit vs Core Animation vs QuartzCore then?


Source: (StackOverflow)

iOS. Cannot run a project after updating cocos2d library inside this project

It cannot compile sources and writes:

Undefined symbols for architecture i386:
"_CTFontManagerRegisterFontsForURL", referenced from: -[CCLabelTTF getFontName:] in CCLabelTTF.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

but when I replace all the code in the following function in CCLabelTTF with "return nil":

- (NSString*) getFontName:(NSString*)fontName
{
    // Custom .ttf file ?
    if ([[fontName lowercaseString] hasSuffix:@".ttf"])
    {
        // This is a file, register font with font manager
        NSString* fontFile = [[CCFileUtils sharedFileUtils] fullPathForFilename:fontName];
        NSURL* fontURL = [NSURL fileURLWithPath:fontFile];
        CTFontManagerRegisterFontsForURL((CFURLRef)fontURL, kCTFontManagerScopeProcess, NULL);

        return [[fontFile lastPathComponent] stringByDeletingPathExtension];
    }

    return fontName;
}

then I can compile my code but I cannot use labels.

So how to solve this without creating of a new project and copying all the sources to it?

EDITED

Previous version is 2.x, now I have the last rc2 version.

I have deleted all the files of the old library, copied the files from the new library into the project folder and added them to project via xcode. xcode can create projects with a new library files, so I took them from this new project. Then I made some changes to remove warnings.


Source: (StackOverflow)

Create layer mask with custom-shaped hole

I've spent too much time trying to figure this out and simply cannot find a workable solution.

Situation: 1. A picture of 'something' is displayed on the phone. 2. A semi-transparent (e.g. blue) layer is placed on top of the image, completely covering it. 3. A 'hole' in this layer exists where that part of the layer is fully transparent and is movable.

An example could be a zoom effect where you move this 'hole' around the image. Inside the hole you can see the image normally, while outside it's covered by the semi-transparent layer. NOTE: I'm implementing this in a cocos2d layer, where the image is represented by a CCSprite. It shouldn't matter though, if no cocos is used.

Problem: I've tried using CAShapeLayer and bitmaps as masks, but nothing is working (see code snippets below). With the CAShapeLayer, I create a UIBezierPath for the 'hole' and apply it to the colored layer. However, only the hole shows the color, while the rest is transparent. With an image, the mask is simply not working (I have no idea why). I've even tried masking masks to see if that would work. I've also tried swapping colors around...from white to black to clear for fill and background.

A simple solution, if it existed, would be to invert the area of the UIBezierPath. I've tried clipping, as well, using the path...but no luck.

I'm hoping that it's something simple-stupid that I'm simply overlooking. Perhaps one of you will see this. The moving part I'm not, yet, concerned with. I need to get the actual mask working first. The sample code is ignoring the y-axis differences between iPhone SDK and openGL.

CAShapeLayer Example:

CGSize winSize = [[CCDirector sharedDirector] winSize];
UIImage* img = [UIImage imageNamed:@"zebra.png"];
CCSprite* spr = [CCSprite spriteWithCGImage:img.CGImage key:@"img"];
spr.position = ccp( winSize.width / 2, winSize.width / 2 );
[self addSprite:spr];

UIBezierPath* path = [UIBezierPath bezierPathWithRect:rectHole];
CAShapeLayer* maskLayer = [CAShapeLayer layer];
maskLayer.bounds = [spr boundingBox];
maskLayer.position = spr.position;
maskLayer.fillColor = [UIColor whiteColor].CGColor;
maskLayer.backgroundColor = [UIColor clearColor].CGColor;
maskLayer.path = path.CGPath;

CALayer* colorLayer = [CALayer layer];
colorLayer.bounds = [spr boundingBox];
colorLayer.position = maskLayer.position;
[colorLayer setMask:maskLayer];

[[[[CCDirector sharedDirector] openGLView] layer] addSublayer:colorLayer];

Multiple Layer Mask Example:

CGSize winSize = [[CCDirector sharedDirector] winSize];
UIImage* img = [UIImage imageNamed:@"zebra.png"];
CCSprite* spr = [CCSprite spriteWithCGImage:img.CGImage key:@"img"];
spr.position = ccp( winSize.width / 2, winSize.width / 2 );
[self addSprite:spr];

UIBezierPath* path = [UIBezierPath bezierPathWithRect:rectHole];
CAShapeLayer* maskLayer = [CAShapeLayer layer];
maskLayer.bounds = [spr boundingBox];
maskLayer.position = spr.position;
maskLayer.fillColor = [UIColor whiteColor].CGColor;
maskLayer.backgroundColor = [UIColor clearColor].CGColor;
maskLayer.path = path.CGPath;

UIBezierPath* pathOuter = [UIBezierPath bezierPathWithRect:img.frame];
CAShapeLayer* outerLayer = [CAShapeLayer layer];
outerLayer.bounds = [spr boundingBox];
outerLayer.position = spr.position;
outerLayer.fillColor = [UIColor blackColor].CGColor;
outerLayer.backgroundColor = [UIColor whiteColor].CGColor;
outerLayer = pathOuter.CGPath;
[outerLayer setMask:maskLayer];

CALayer* colorLayer = [CALayer layer];
colorLayer.bounds = [spr boundingBox];
colorLayer.position = outerLayer.position;
[colorLayer setMask:outerLayer];

[[[[CCDirector sharedDirector] openGLView] layer] addSublayer:colorLayer];

Image Mask Example:

CGSize winSize = [[CCDirector sharedDirector] winSize];
UIImage* img = [UIImage imageNamed:@"zebra.png"];
CCSprite* spr = [CCSprite spriteWithCGImage:img.CGImage key:@"img"];
spr.position = ccp( winSize.width / 2, winSize.width / 2 );
[self addSprite:spr];

CGRect r = [spr boundingBox];
CGSize sz = CGSizeMake( r.size.width, r.size.height );
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef context = CGBitmapContextCreate( NULL, w, h, 8, 0, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaNone );
CGColorSpaceRelease( colorSpace );
CGContextSetFillColorWithColor( context, [UIColor whiteColor].CGColor );
CGContextFillRect( context, r );
CGContextSetFillColorWithColor( context, [UIColor blackColor].CGColor );
CGContextFillRect( context, rectHole );
CGImageRef ref = CGBitmapContextCreateImage( context );
CGContextRelease( context );

CALayer* maskLayer = [CALayer layer];
maskLayer.bounds = [spr boundingBox];
maskLayer.position = spr.position;
[maskLayer setContents:(id)ref];

CALayer* colorLayer = [CALayer layer];
colorLayer.bounds = [spr boundingBox];
colorLayer.position = maskLayer.position;
[colorLayer setMask:maskLayer];

[[[[CCDirector sharedDirector] openGLView] layer] addSublayer:colorLayer];
CGImageRelease( ref );

Source: (StackOverflow)

iOS and finding Tomorrow

How can I check to see if a date is inheritantly TOMORROW?

I don't want to add hours or anything to a date like today, because if today is already 22:59, adding too much will overkill, and adding too little if the time is 12:00 will miss tomorrow.

How can I check two NSDates and ensure that one is the equivalent of tomorrow for the other?


Source: (StackOverflow)

how can I use animation in cocos2d?

I am trying to develop a Roulette game for iPhone. How can I animation (spin) the Roulette board?


Source: (StackOverflow)