Cocos2D Sprite Animation Batch Node Troubles - animation

I get the following error: 'CCSprite is not using the same texture id'
This is what I'm doing:
.h file
#interface GameplayLayer : CCLayer <GameplayLayerDelegate> {
CCSpriteBatchNode* pointbb;
}
.m file
pointbb = [CCSpriteBatchNode batchNodeWithFile:#"pointsbb.png"];
[self addChild:pointbb];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"pointsbb.plist"];
CCSprite* spa = [CCSprite spriteWithSpriteFrameName:#"poi2500001.png"];
[pointbb addChild:spa];
The exact syntax worked for other animations but this one. What should be my correct course of action?

If you are adding a CCSprite as a child of CCBatchNode.. use textures from batchnode..
Use this method..
[CCSprite spriteWithBatchNode: rect:]
In case you add your sprite to layer like [self addChild:] .. Your code will perfectly..
Hope this helps. :)

Related

Where do I put the code for changing the nav bar color in xcode 4.3

Ok, it's 3 am atm and I haven't a clue where I put this:
[navigationController.navigationBar setTintColor:[UIColor redColor];
If you would please post the whole .m/.h files that would be great. Also, do I connect anything using segues or outlets? And when you create the .h/.m files do I need UINavigationController or similar selected or just the normal UIViewController? Thanks.
Update: Nevermind I got it, thanks though. Below is the code for others having my issue.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UINavigationBar *bar = [self.navigationController navigationBar];
[bar setTintColor:[UIColor lightGrayColor]];
}
Basically just add on to what's already there.
I feel stupid lol.
You can set that value right after you init your UINavigationController, i.e:
UINavigationController *controller = [[UINabvigationController alloc] initWithRoot...
[controller.navigationBar setTintColor:[UIColor redColor]];

Cannot add category to CPView Cappuccino

I am trying to add this category to CPView but XCodeCapp gives an error and I get unrecognized selector sent to instance error when I try to use this method.
#import <AppKit/CPView.j>
#implementation CPView (Custom)
- (void) addSomething
{
var bounds = [self bounds];
var context = [[CPGraphicsContext currentContext] graphicsPort];
CGContextSetFillColor(context, [CPColor blueColor]);
CGContextFillRect(context, CGRectMake(100,100,100,100));
}
#end
The syntax is correct as far as I can tell, the file name I am using is CPView_Custom.j
EDIT
I am also using IB to connect a CPView ivar to a custom view in the XIB/NIB file. Not sure if this makes a difference or not.
XCodeCapp will always throw errors regarding Categories because the objj CLI cannot understand them as a single file.
You should ignore your categories by adding some entries in .xcodecapp-ignore.

CALayer is not type-casted to CATiledLayer

I am new to iPhone programming. I want to use CATiledLayer to load an image.
I am creating the subclass of UIVIew class and in the init method of that class, I am writing,
CATiledLayer *tiledLayer = (CATiledLayer *)[self layer];
But when I am writing
tiledLayer.levelsOfDetail = 4;
It gives me the error that
[CALayer setLevelsOfDetail:]: unrecognized selector sent to instance 0xcd04450
So to check the class-type of tiledLayer,I am writing following statements :
NSString *pqr = [[NSString alloc]initWithFormat:#"%#", [tiledLayer class]];
NSLog(pqr);
But it prints CALayer instead of CATiledLayer. Why is it so?? What am I missing??
Now I am stuck here. :(
Applying a typecast to a pointer in Objective-C has no effect at runtime (it does have some effect during compile time, so this syntax is still used at times).
So, your "typecast" is not actually doing a typecast. It's just informing the compiler (in that one line of code only) that this is a CATiledLayer and not a CALayer as it has been declared. The actual object is really still a CATiledLayer.
In order to change the class of self.layer, you define a static method to return the class:
#implementation MyView
+ (Class)layerClass
{
return [CATiledLayer class];
}
#end
And now, when the layer for any MyView instance is created, it will be a CATiledLayer instead of a CALayer.

Why I can't seem to modify my window properties when not using default XCode4 code structure?

Well, first of all, I hope I stated my problem correctly.
I am using Xcode4, but not using the default code structure.
I am aiming at creating a transparent window here. Now, it's very easy by just adding initialization code here :
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
[[self window] setAlphaValue:0.9];
[[self window] setOpaque: NO];
}
But, because I change the WindowAppDelegate into this :
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSLog(#"delegate: init main window");
mainWindow = [[MainWindowController alloc] initWithWindowNibName:#"MainWindow"];
[[mainWindow window] makeKeyAndOrderFront:self];
[[mainWindow window] setAlphaValue:0.8];
[[mainWindow window] setTitle:#"Fool"];
}
It won't work. I mean the code of setAlphaValue didn't had any effect, nor other method call such as setTitle.
I guess this is because of me didn't wire things correctly in the NIB...
But, what is it anyway?
Thanks in advance
#bavarious. This is his answer "Have you connected the window outlet in File’s Owner (which should be of type MainWindowController) to the actual window? – Bavarious Oct 30 at 7:37"
I will accept in in two days as the answer for my question.
Thanks #bavarious!

Control instances of specific CCSprites with separate class file in Cocos2d

I have just started working on my first cocos2d ios app.
I am very used to creating games in Game Maker, in which everything is simpler, and would like some help on creating separate .m/.h class files that contains functions that will affect all instances of a specific CCSprite. Obviously different class files for different CCSprites are needed.
In game maker, objects have code applied to them, and when i want something to happen when an instance is created its pretty easy, by just adding code to the create event.
In xcode i can't think how to do this.
One way to go would be to subclass CCSprite. Check out this guide for more info:
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:sprites
Separate classes may also not be necessary, consider just having different initiators. Here is an example of a CCSprite subclass that can make both minions and evil rabbits:
BadGuySprite *minion = [[BadGuySprite alloc] initAMinion];
BadGuySprite *evilRabbit = [[BadGuySprite alloc] initAEvilRabbit];
BadGuySprite.h
#import "cocosd.h"
#interface BadGuySprite: CCSprite
{
int lifebar;
}
+(id) initAMinion;
+(id) initAEvilRabbit;
#end
BadGuySprite.m
#import "BadGuySprite.h"
#implementation BadGuySprite
- (id)initAMinion{
self = [CCSprite spriteWithFile:#"minion.png"];
lifebar = 1000;
return self;
}
- (id)initAEvilRabbit{
self = [CCSprite spriteWithFile:#"rabbit.png"];
lifebar = 1;
return self;
}
#end

Resources