LevelHelper collision not working - iphone

This problem has stumped me for two nights now, I cannot simply have two LHSprites collide with each other using level helper collision. I have checked the docs multiple times to check if I was missing something, but i cannot see it.
In the console of xCode, it logs:
LevelHelper WARNING: Please call useLevelHelperCollisionHandling after addObjectsToWorld
2013-04-24 20:33:04.537 Monkeys2D[1322:c07]
LevelHelper WARNING: Please call registerPostCollisionCallbackBetweenTagA after useLevelHelperCollisionHandling
But as you can see in my code below, I am correctly doing what it is warning me that I am not.
-(id) init
{
if( (self=[super init])) {
self.isTouchEnabled = YES;
loader = [[LevelHelperLoader alloc]initWithContentOfFile:#"Level1"];
[loader addObjectsToWorld:world cocos2dLayer:self];
[loader useLevelHelperCollisionHandling];
[loader registerPostCollisionCallbackBetweenTagA:MONKEY andTagB:SINGLEBANANA idListener:self selListener:#selector(collision)];
}
return self;
}
My problem is that the collision will NOT register, it acts as if nothing is even happening when the MONKEY and the SINGLEBANANA collide.
Any help would be greatly appreciated!

Turns out i needed to add an update method and implement some other box2d stuff, visit the level helper docs & forum to see.

Related

Deleting CCSprites stored in NSMutableArray not working right

Here is what I've tried.
In my init method I initialized the array:
deleteSprites = [[NSMutableArray alloc] initWithCapacity:500];
This is how I added them to the array:
CCSprite *SpriteSave;
SpriteSave = [CCSprite spriteWithBatchNode:Batch rect:CGRectMake(0,0,6,6)];
[Batch addChild:SpriteSave];
[deleteSprites addObject:SpriteSave];
This is how I attempt to remove the sprites:
delCount = 0;
while (delCount < [deleteSprites count])
CCSprite *delSprite = (CCSprite *) [deleteSprites objectAtIndex:delCount];
[delSprite.parent removeChild:delSprite cleanup:YES];
delCount++;
}
[deleteSprites removeAllObjects];
This causes some of the sprites to flip, but they still appear on screen and none are deleted. I've already researched everywhere and although I made my code very similar to others that got it to work, it still won't work for me. I've also already read through the memory management documents and I still don't see what I'm doing wrong. Also I've tried adding the sprites to the userdata of the fixtures they're supposed to be representing and when the fixture is destroyed I once again try to remove the sprite but the same thing happens. Please Help!.
I figured out what it was. I was making a logical error in a few of my if statements and accidentally added the sprites twice. Sorry about that everyone.

Game Center Multiplayer using GKMatch but seems can't be connected

Hi I'm a new bie in Game Center for iOS. I'm trying to add the multiplayer feature using matches to my game and following the documentation.
So far I reached a point where 2 of my clients can successfully get a match, i.e. the matchmakerViewController:didFindMatch callback is called and a GKMatch object is delivered.
However after that I seems to be stuck there forever, because according to the documentation, I'll have to wait until all the players (2 in my case) are actually connected before starting my game. But it seems the match:player:didChangeState callback is never called to indicate a successful connection. Well, I'm sure my clients are all in the same wifi network ( or is it a must?) Could any one enlighten me on this case? Do I have to do any extra things to make the clients to connect? Thanks a lot for the help!
So I was running into this and the solution (for me) was somewhat embarrasing. I had copied and pasted a bunch of the code from the Apple docs..and they left out an obvious step. They never actually set the match's delegate!
My code now is:
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match {
[self dismissModalViewControllerAnimated:YES];
self.myMatch = match; // Use a retaining property to retain the match.
self.myMatch.delegate = self; // THIS LINE WAS MISSING IN THE APPLE DOCS. DOH.
// Start the game using the match.
NSLog(#"Match started! Expected Player Count:%d %#",match.expectedPlayerCount, match.playerIDs);}
Once I actually set the match delegate, the functions get called. Doh.
When you get the GKMatch object, be sure to check the expectedPlayerCount property. It is possible that the other player is already connected, and thus you will not get a match:player:didChangeState on the delegate.
I have had the same problem with a friend. The solution was quite strange but it works afterwards. On all devices you have to enable the Notifications (Sounds/Alerts/Badges) for the Game Center inside the Settings/Notifications options. Afterwards we could establish a connection and did receive a match object
Inside your callback matchmakerViewController:didFindMatch
Add this code then you'll see the callback "match:player:didChangeState" being called by GC
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
[[GKMatchmaker sharedMatchmaker] addPlayersToMatch:match matchRequest:request completionHandler:^(NSError* error) {
if(error)
NSLog(#"Error adding player: %#", [error localizedDescription]);
}];
It was working all along. The only difference is that... when you use invites the event "didChangeState" doensn't get called. You're connected without notice and you can start to receive data. I never tried to send/receive data... cuz i was expecting the event first, but i did send something by mistake one time, and it worked. :)
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *) match {
//Dismiss window
[self dismissModalViewControllerAnimated:YES];
//Retain match
self.myMatch = match;
//Delegate
myMatch.delegate = self;
//Flag
matchStarted = TRUE;
//Other stuff
}
- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state {
//This code gets called only on auto-match
}
The above code works as expected.
Make sure that you've set your class as the delegate for GKSession. The class will need to implement the GKSessionDelegate protocol... otherwise, it'll never receive this callback. Here's the protocol reference. Hope this helps!

How do I remove a child later? (cocos2d)

I added a child like this inside of a CCLayer:
[self addChild:object1];
Later on I want to remove that object from the children. Ummm so how do I do that? Thanks.
Your question leads me to believe you don't know the cocos2d API reference:
http://www.cocos2d-iphone.org/api-ref/
To remove object1 simply use this:
[self removeChild:object1 cleanup:YES];
If you don't keep a reference of object1 around you can remove it by tag, which means you'll have to give it a tag first:
object1.tag = 123; // just any arbitrary number
[self addChild:object1];
To remove it:
[self removeChildByTag:123 cleanup:YES];
I've added this Q&A to my cocos2d FAQ, please find more details to this answer here:
http://www.learn-cocos2d.com/knowledge-base/cocos2d-iphone-faq/learn-cocos2d-public-content/manual/cocos2d-general/14824-how-to-remove-a-child-from-the-nodescenelayer
Try the removeChild method?

Cocos2D iPhone Effect

trying to play around with the Cocos2d effects and created to methods to display and stop the Liquid action. My application however drops from 60fps down to 30fps when the effect is applied but the fps doesnt increase again when the scheduled stop action is called.
I originally thought that while the action has been completed the effect is still being rendered but after reading through the EffectsTest.h/.m in the Cocos2D 0.8 zip I cant find any reference to how this is achieved. Can anyone shed some light on this issue?
// effects
-(void)enableLiquidEffect
{
id liquid = [Liquid actionWithWaves:6 amplitude:20 grid:ccg(15, 10) duration:3];
[self schedule:#selector(disableLiquidEffect) interval:(3.0)];
[self runAction:liquid];
}
-(void)disableLiquidEffect
{
[self unschedule:#selector(disableLiquidEffect)];
[self stopAllActions];
}
Cheers,
AntonMills
Just a little tip here i know this was asked years ago, but someone might still come here
the code is a little bit overkill, here's how to do it:
// effects
-(void)enableLiquidEffect
{
id liquid = [Liquid actionWithWaves:6 amplitude:20 grid:ccg(15, 10) duration:3];
//No need to unschedule after 3 seconds since you already set duration-^ to 3 seconds.
[self runAction:liquid];
}
-(void)disableLiquidEffect
{
[self stopAllActions];
}
besides that the code is perfect
Just a guess but since the item will still have a transform set to liquid that it is still trying to apply a more complex transform then needed after its done. Save off your transform prior to starting and then when it stops set it back. You could try just setting it to nil.

Heeelp! Debugger says "out of scope"!

I just cannot imagine what the hell the problem could be.
I made a pretty app, and decided to use only CALayers to "render".
When I saw that the changes in the position property gets animated, decided to implement a custom getter-setter "abstract" property called tanCenter to set the position without animating.
-(void) setTanCenter: (CGPoint) sentCenter
{
//Remove any transactions.
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
//Set position.
self.position = sentCenter;
[CATransaction commit];
//Set value.
tanCenter = sentCenter;
}
-(CGPoint) tanCenter { return tanCenter; }
Since I merged this into the project, it crashes without any "understandable" (for me) error message. I can see only those "out of scope"-s. I cant even get this tanCenter property NSLog-ged without crash.
Help me, Obi-Wan Kenobi; you're my only hope.
If you run in the debugger (Command-Y) and make sure you have global breakpoints enabled, the debugger should stop at the place where the crash occurred giving you an idea of what is nil or over-released.
hey I had the same problem till now. Finally I have found my bug after investigating 2 weeks of bug tracking (it really sucks)
maybe my problem helps you:
I started with a TableView that opens on click another view. So I created in:
-(void)tableView:didSelectRowAtIndexPath:
first the controller for the other view and set the value for a global variable:
SomeView *dtview = [[SomeView alloc] initWithNibName:#"SomeView" bundle:nil];
dtview.lblTitle = cl.textLabel.text; // cl is the cell
[self presentModalViewController:dtview animated:NO];
[dtview release];
So opened the other view and done much functions with much memory usage :)
When I after that close the other view and go back to the table and scroll some times the App terminates with the message "out of scope"
I searched really, really long to find out what was the effect. It seems that when the other view is released also the text of the first table is released.
After putting a copy to the call it worked for me:
dtview.lblTitle = [cl.textLabel.text copy];
For int and bool the first solutions works fine, because these aren't objects but for NSObject's you should copy the values to another view.