problem: menu does not show in cocos2d layer - menu

I am trying to add menu to a layer in cocos2d but it just does not appear. Here's the code which is written in init method of a layer
CCMenuItem *aButton = [CCMenuItemImage itemFromNormalImage:#"btnImg.png" selectedImage:#"btnImgSel.png" target:self selector:#selector(buttonPressed:)];
aButton.position = ccp(60.0,30.0);
CCMenu *aMenu = [CCMenu menuWithItems:aButton, nil];
aMenu.position = ccp(500.0,20);
[self addChild:aMenu];
Nothing is overlapping the position i specified for menu. Is anything wrong in the code?

Try like these:-
CCLayer *menuLayer1 = [[[CCLayer alloc] init]autorelease];
[self addChild:menuLayer1];
CCMenuItemImage *startButton1 = [CCMenuItemImage
itemFromNormalImage:#"Play.png"
selectedImage:#"Play.png"
target:self
selector:#selector(Play:)];
CCMenu *menu1 = [CCMenu menuWithItems: startButton1,nil];
menu1.position = ccp(157,157 );
[menu1 alignItemsVertically ];
[menuLayer1 addChild: menu1];

For those who are facing an irritating situation where the code is right but menu items are not showing then check the image file. I was using .png images and they were refusing to be displayed. There was something internally wrong with the file, so I replaced that file and it solved the problem :)

Is the iPad your target platform? If so the "menu" should appear at the bottom of the screen. To display the Menu on iPhone adjust the "a.Menu.position" to anything lower than 480 in the first attribute of ccp

Related

iOS13 Beta-8 SKVideoNode+AVPlayer show black screen

my app is a AR app to play h.264 video.
We created SKVideoNode by AVPlayer and set the SKVideoNode to SKScene, and then create SCNNode to involve this SKScene.
- Sample Code
AVPlayer *avPlayer = [self getMoviePlayer:path];
SKVideoNode *videoNode = [[SKVideoNode alloc]initWithAVPlayer: avPlayer];
CGSize videoSize = CGSizeMake(100, 50);
videoNode.size = videoSize;
videoNode.position = CGPointMake(50, 50);
videoNode.yScale = -1.0;
SKScene *skScene = [[SKScene alloc] initWithSize:videoSize];
skScene.scaleMode = SKSceneScaleModeAspectFit;
[skScene addChild:videoNode];
SCNNode *planeNode = [[SCNNode alloc] init];
planeNode.geometry = [[SCNPlane alloc] init];
SCNMaterial *material;
material = [[SCNMaterial alloc] init];
material.diffuse.contents = skScene;
planeNode.geometry.firstMaterial = material;
========================
we use this SCNNode to play videos.
it works fine until iOS12.4 but when I test it on iOS13-beta device, it shows black screen while sound is heard.
I had a very similar issue. I also thought it might be an iOS13 bug. But I couldn't reproduce the issue in a test project that was isolating the particular SKVideNode code.
It turned out the root cause of my issue with this problem was in my info.plist file I had PrefersOpenGL set to YES. Changing it to NO (or deleting it) fixed my problem with it not displaying the video in my SKVideoNode iOS 13. It also looks like that change works fine back to iOS 12.4 and 11.4 as well.
I had the same problem. I solved it with replace:
[myViewController.layer addSublayer:playerViewController.view.layer];
by:
[myViewController addSubview:playerViewController.view];
If it can help you.

How to overlay MKPolyline on top of different maps

So I draw a MKPolyline with the users updated CLLocationCoordinates as per usual. When my quits and starts again, all of the past points are loaded onto the mapview to be displayed with
routeLine = [MKPolyline polylineWithCoordinates:clCoordinates count:numberOfSteps];
[_mapView addOverlay:routeLine];
and in MKOverlayRenderer method I have
if ([overlay isKindOfClass:[MKPolyline class]])
{
MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithPolyline:overlay];
renderer.strokeColor = [[UIColor whiteColor] colorWithAlphaComponent:0.7];
renderer.lineWidth = 3;
return renderer;
}
This all works a treat, but problems arise when I change the type of map with
[self resetMapViewAndRasterOverlayDefaults];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
_rasterOverlay = [[MBXRasterTileOverlay alloc] initWithMapID:#"jonobolitho.j834jdml"];
_rasterOverlay.delegate = self;
[_mapView addOverlay:_rasterOverlay];
Note, I have the resetMapViewAndRasterOverlayDefaults helper method
// Reset the MKMapView to some reasonable defaults.
//
_mapView.mapType = MKMapTypeStandard;
_mapView.zoomEnabled = YES;
[_mapView removeAnnotations:_rasterOverlay.markers];
[_mapView removeOverlay:_rasterOverlay];
[_rasterOverlay invalidateAndCancel];
I am using MBXMapKit to display the maps. The maps display correctly, but the polyline isn't shown on top of the map. The map just loads over the top of my polyline (routeLine). I know this because in between the tiles of the new map I can see the routeLine underneath.
So basically is there a way to load the MKPolyline but always keep it on the top layer of the map, even if it changes?
Instead of:
[_mapView addOverlay:_rasterOverlay];
You want:
[_mapView insertOverlay:_rasterOverlay belowOverlay:routeLine];
Or something similar. Overlays have an order.

Cocos2d: is there a way to access to a CCMenu child?

I am using the following code:
CCMenuItemFont *controllerItem = [CCMenuItemFont itemFromString:#"Analog" target:self selector:#selector(controllerToggle)];
CCMenu *controllerTypeMenu = [CCMenu menuWithItems:controllerItem, nil];
[controllerTypeMenu alignItemsVerticallyWithPadding:30.0f];
controllerTypeMenu.position = CGPointMake(160.0f, 240.0f);
[self addChild:controllerTypeMenu z:0 tag:ControllerMenu];
}
-(void) controllerToggle
{
CCMenuItemFont *controllerItem = [self getChildByTag:888];
NSString * text = [NSString stringWithFormat: #"switching.. %f", CCRANDOM_0_1()];
[controllerItem setString:text];
}
In controllerToggle I would like to access to controllerItem and change the String to another value. Is this possible? I checked and CCMenu adds as child the CCMenuItems based the array order. But that's not an elegant solution. For the same reason I cannot add the CCMenuItem to the Scene as it will give me "child already added error". So I feel I should write my own "switch" button but I wonder if there is already something out there..
Any help?? Thanks!
you can declare needed menu item as class member. In this way you will be able to get access to it whenever you want
There is already CCMenuItemToogle which is used to switching the title or image of any menuitem on click event.Instead of taking CCMenuItem you can use CCMenuItemToggle..
Here is a sample code
CCmenuItemToggle *cam=[CCMenuItemToggle itemWithTarget:self selector:#selector(openCameraController) items:cameraOn,cameraOff, nil];
where cameraOn and cameraOff are two simple CCMenuItemImage which is added in CCMenuItemToggle and further this CCmenuItemToggle is added in a menu.
Now on every click of CCMenuItemToggle there will be a cameraOn and cameraOff state for same menuitem.
Hope this will help...

Why do navigation appear 20 pixels below status bar in the view? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
UIWebView on iPad size
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationController *naviController = [[UINavigationController alloc]init];
[self.view addSubview:naviController.view];
}
If I add navigation controller in the view, it appears about 20 pixels below status bar.
I want it appears just below status bar. How do I fix this?
I've experienced this same issue.
This discussion was helpful: UIWebView on iPad size
Tony's answer helped me discover this trick:
naviController.view.frame = self.view.bounds;
Turns out setting the view height fixes this problem. You can do it in the nib (xib) file or progammatically when creating the view setting the view.frame = CGRect(0, 0, 320.0 460.0); or whatever it's supposed to be (in your case it looks like it should be 460.0 since you have the status bar on).
The main point is that if the view size is smaller than the height of the screen, there are no guarantees where your controls will show up.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGRect frame = CGRectMake(0, 0, 320.0, 480.0);
viewController.view.frame = frame;
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
I changed like above. It works. So far so good. If height was 460, there would have been blank line at the bottom. View's absolute coordinate is (0, 20). So, Navigation bar's coordinate is (0, 40). I think that was the problem. I will encounter another problem.
Maybe there is way to change coordinate before displaying navigation view. Thank you.

iPhone - button within cell to push a new view onto screen

Hey guys, I appear to have run into a problem. I have an application (View-based) that has a UITableView displayed on the bottom half of the screen, with the selection of a cell then bringing up a custom cell taking up the bottom of the screen. I have a "more info" button on the bottom right of this cell, and and when it is selected, I wish for it to open a new NIB file, however the only thing I can manage to do is remove the tableView from the screen..I am not sure of what to use before the "addSubview" because it is not self.view which I thought it would be.
- (void)moreInfoButton:(id)selector{
NSLog(#"Button Pressed");
MoreInfo *mivc = [[MoreInfo alloc] initWithNibName:#"MoreInfo" bundle:nil];
[self.tableview removeFromSuperview];
//[self.view addSubview:(UIView *)mivc];
[self.navigationController pushViewController:mivc animated:YES];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"List of Events" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
[mivc release];
}
Also, the (UIView *) doesn't do the trick either. Any suggestions?
P.S. The UITableView does not use a navigationController at all, it is just the table, would this be the problem?
Also, what if I chose to just push a new view, and not use the navigationViewController for this view, is this possible?
I can't answer your navigation controller question without seeing more of your program. To answer your other question, without using a navigation controller you can just add a new view with:
newViewVC = [[NewViewVC alloc]initWithNibName:#"NewViewVC" bundle:nil];
[self.view addSubview:newViewVC.view];
Typically newViewVC is declared in your .h so you can release it later.
I have found an easy way: pushing it as a modal.
- (void)moreInfoButton:(id)selector{
NSLog(#"Button Pressed");
MoreInfo *mi= [[MoreInfo alloc] initWithNibName:#"MoreInfo" bundle:nil];
[self presentModalViewController:mi animated:YES];
}
All that is needed is a back button in the new nib file.

Resources