How can I place admob in Cocos2d android? - cocos2d-android

I am new to Android game development. I am struggling to show Admob in my game. What am I doing wrong?
LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
getWindowManager().getDefaultDisplay().getWidth(),
getWindowManager().getDefaultDisplay().getHeight()
+ getWindowManager().getDefaultDisplay().getHeight()
- 50);
adView = new AdView(CandygrabberActivity.this, AdSize.BANNER,
MY_AD_UNIT_ID);
adRequest = new AdRequest();
adRequest.setTesting(true);
adView.loadAd(adRequest);
CCDirector.sharedDirector().getActivity()
.addContentView(adView, adParams);

https://stackoverflow.com/a/17991961/2026280
Go through this answer. If you need some more help.just ask.
IF it helped you. Upvote the answer.

Related

Mapgraphics library on github. C++/Qt/OpenStreetMap

I have a question regarding this library: https://github.com/raptorswing/MapGraphics. Contact the maker did not work, so I hope for help here, can someone faced with this same problem.
How do I add an object to my map in this library? Tried to do here is so:
MapGraphicsScene *scene = new MapGraphicsScene();
MapGraphicsView *view = new MapGraphicsView(scene);
LineObject line(Position(92.860984, 56.006355), Position(92, 56), 10);
QPainter linePainter;
QColor red(255, 0, 0);
linePainter.setPen(red);
QStyleOptionGraphicsItem itm;
line.paint(&linePainter, &itm, view);
QSharedPointer<OSMTileSource> osmTiles(new OSMTileSource(OSMTileSource::OSMTiles), &QObject::deleteLater);
QSharedPointer<CompositeTileSource> composite(new CompositeTileSource(), &QObject::deleteLater);
composite->addSourceBottom(osmTiles);
view->setTileSource(composite);
But it gave no results. Can you help me? :(
Unfortunately the relevant bit of code isn't in your snippet, but I wonder if it's http vs https access? When you try and download a tile such as this http one it'll now redirect to https. This caught out a number of clients (to my knowledge Java-based and Flash-based ones).
The github project says "It is a Qt map widget that can use tiles from MapQuest, Openstreetmap, or a custom source you define" which suggests it's actually quite old, since Mapquest haven't had their own map tiles for a very long time. Try using a custom source and define https access to OSM tiles.
It is enough to do the following:
MapGraphicsObject *line = new LineObject(Position(92.860984, 56.006355), Position(92, 56), 10);
view->scene().addObject(line);
This should be done with any type of object.

Hide the tabBar in Rubymotion

I am building an iOS app in Rubymotion. I want to create a custom tabBar so I need
to use a real tabBar but hide it. How can I hide the tabBar in Rubymotion?
To hide the tab bar you can use hidesBottomBarWhenPushed.
The Objective C is:
MyController *myController = [[MyController alloc]init];
myController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:myController animated:YES];
[myController release];
Therefore the RubyMotion Code is
#my_controller = MyController.alloc.init
#my_controller.hidesBottomBarWhenPushed = true
self.navigationController.pushViewController(#my_controller, animated:true)
I hope this helps. If you'd like to see more references to tab bars please check:
https://github.com/IconoclastLabs/rubymotion_cookbook/tree/master/ch_2/12_tabbars
Or if you'd like to see basics of navigation controller please check
https://github.com/IconoclastLabs/rubymotion_cookbook/tree/master/ch_2/11_navbarbuttons
I hope this helps!

How do you detect what UIPickerView row has been selected using an if statement

I have made a button so that when it's pressed by the user and a particular row(s) are selected it does something.
So far I have this:
if (pickerView selectedRowInComponent:0) {
[mailComposerTwo setToRecipients:[NSArray arrayWithObjects:#"email#blah.com",nil]];
}
It works on its own. But when I do the if statement multiple times it crashes.
An ways of making it work?
Any help appreciated, thanx.
The problem probably lies with your mail composer, not the picker view. When you show the composer, make sure that you only create it if it hasn't already created.
Also, make sure you release it after you show it:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
...[configure the picker]
[rootContainer presentModalViewController:picker animated:YES];
[picker release];
NSArray *finalList = [[NSArray alloc]init];
//put all your if statements
if (pickerView selectedRowInComponent:0)
{
[finalList arrayByAddingObjectsFromArray:#[#"email#address.com",#"second#address.com",...];
}
if (pickerView selectedRowInComponent:1)
{
[finalList arrayByAddingObjectsFromArray:#[#"another#address.com",#"fourth#address.com",...];
}
//end of if statements
[mailComposerTwo setToRecipients:finalList];
[self presentViewController:yourInitializedMessageController animated:YES completion:^{NSLog(#"message controller is presented");}];
This will do a single method call rather than continually reassigning which for some odd reason is causing your exception. presentModalViewController:animated: has been deprecated as of iOS 6.0? if not 7.0 I believe.
NOTE! Make the message controller a property of the main view controller. It is good practice so that it is not auto-released by iOS if you need to bring it back up. However if you use MFMessageComposer iOS will keep messenger allocated or running in a thread somewhere so initializing a view controller for it is quick.

CCLabelBMFont Label takes long time to load!

I have a game. In game there is a help text. The game menus are transitioned on sliding in and out manner. Like if you click "Help" button on "Main Menu", Main menu slides out and help menu slides in.
Now i got problem while loading "Help Menu". The help menu consists of a scroll view and help texts are loaded in scrollview when it is initialized. The Text in Help Menu are CCLabelBMFont Label. The help text has multiples lines (upto 146) lines. My problem is when I click on Help menu, the sliding In takes up to 10 secs to come up. I know it's due to the long help text that is created using CCLabelBMFont.
Is there any solution of this case. When I decrease the lines of help text to 50, it works fine. I directly created the label with following code in HelpMenuLayer.m
CCLabelBMFont *contentLabel = [[CCLabelBMFont alloc] initWithString:#"Objective:"
"\n........."
.
.
.
fntFile:"fontFile.fnt"];
contentLabel.position = ccp(0.0f, 0.0f);
[scrollview addChild:contentLabel]
[contentLabel release];
Any comments or suggestions are greatly appreciated. Thanks in advance. I really need help :(
I solved the above issue using png image. And wrote down in some steps in following blog of mine. Please visit following link.
http://learninprogram.blogspot.com/2011/06/solution-to-cclabelbmfont-bitmap-fonts.html
Thanks for everyone who tried to help me and helped me actually. Happy sharing!!
Well it is probably UIKit causing any slowness. Cocos2D and UIKit do not play well together in my experience.
Anyway I don't know for sure what is wrong. Here is my usage of CCLabelBMFont (which does not use UIKit but it should be the same):
CCLabelBMFont *multiplierLabel = [CCLabelBMFont labelWithString:[NSString stringWithFormat:#"%i", [player scoreMultiplier]] fntFile:#"projectOneTitle1.fnt"];
multiplierLabel.position = ccp(winSize.width*0.9, winSize.height*0.95);
multiplierLabel.tag = 9845;
[self addChild:multiplierLabel];
That probably won't help, but in the off chance that it does I am posting it. Good luck.

Resizing a QTCaptureView embedded in a Qt app

So, I want to have an app in Mac that will show a live video preview through my iSight while allowing users to take snapshots. Basically, it's similar to the Still Motion Demo, except now I have to make it work under a Qt app. That is, I'm having mm files that are mostly adhering to the c++ structure, with occasional Obj-c messaging.
Currently, I'm having problems with placing the QTCaptureView with the rest of the Qt module.
Right now, I have managed to place it into my Qt gui through QMacCocoaViewContainer, and wanted to resize it to an appropriate size; since we can't use the Interface Builder anymore, I have to code it somehow. I've tried setting it's frame and bounds right after I created it, but it's not making any difference.
CCaptureViewWidget::CCaptureViewWidget(QWidget *parent) :
QMacCocoaViewContainer(0, parent)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSRect kVideoFrame = NSMakeRect( 100.0f, 100.0f, 400.0f, 300.0f );
QTCaptureView *camView = [[QTCaptureView alloc] initWithFrame:kVideoFrame];
[camView setFrame:kVideoFrame];
[camView setBounds:kVideoFrame];
NSRect ourPreviewBounds = [ camView previewBounds ];
NSColor *pFillColor = [ [NSColor colorWithDeviceRed:0.0f green:1.0f blue:0.0f alpha:1.0f] copy];
[camView setFillColor:pFillColor];
[camView setPreservesAspectRatio:YES];
[camView setNeedsDisplay:YES];
setCocoaView( camView );
[camView release];
[pool release];
}
The ourPreviewBounds, as far as I can tell from the debuger in Xcode, has a size of 0x0, even after the setFrame and setBounds call. And just to prove that camView is valid, I did manage to change the fill color of the QTCaptureView.
I read from sources that overriding QTCaptureView's previewBounds might be an option, but I haven't been able to find any working examples of that.
If anyone can give me a hint as to how to resize a QTCaptureView outside of the Interface Builder and inside the code, I will very much appreciate it.
How to set NSView size programmatically?