cocos2d v2.0 upgrade & RootViewController - cocos2d-iphone

I'm currently upgrading my cocos2d app from 0.99 to 2.0. The app uses ZBarSDK for QR code scanning and the integration was done like that:
// present and release the controller
[[RootViewController sharedInstance] presentModalViewController: reader animated: YES];
However that doesn't work with the new version of cocos2d. What should I change to make it work with cocos2d 2.0 ?

Use this code:
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController presentModalViewController: reader animated:YES];

Related

Is open OpenGL completely broken after iOS 12.4?

I have an open source MS-DOS emulator for iOS here:
https://github.com/MattAndrzejczuk/MSDOS-for-iOS
This app runs well when using my older iOS devices such as the old iPhone 5S. but right after iOS 13.0 was released, the app delegate has trouble rendering SDL due to NOT calling UIKit methods on the main thread, but I'm not quite sure if this crash is due to OpenGL being completely deprecated, or, if maybe the newer SceneDelegate and AppDelegate changes which seemed to have been overhauled in iOS 13 are the cause of this issue. Just for some context, I've noticed that I cannot create a new Xcode project with a basic hello world label and build it directly for iOS 12 devices without doing this:
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
// ADD THIS TO DEFAULT APPDELEGATE.H:
#property (strong, nonatomic) UIWindow *window;
#end
This solution below, only somewhat fixed the problem:
Sources/dospad/Shared/DosEmuThread.m
#import "DosEmuThread.h"
extern int SDL_main(int argc, char *argv[]);
#implementation DosEmuThread
#synthesize started;
- (void)start
{
if (started) {
NSLog(#"DosEmuThread %p already started", self);
return;
}
NSLog(#"Start dosbox in new thread");
started = YES;
[NSThread detachNewThreadSelector:#selector(run) toTarget:self withObject:nil];
}
- (void) run {
#autoreleasepool {
/// UNCOMMENTING THIS SOMEWHAT FIXES THE ISSUE:
//dispatch_async(dispatch_get_main_queue(), ^{
char *argv[1] = {"dosbox"};
SDL_main(1, argv);
self.started = NO;
//});
}
}
#end
This fixes the app, in that I can reach the DOS prompt, but once I try to open something like this:
C:\ cd WAR2A
C:\ WAR2.EXE
I just get stuck at a blank screen, so obviously the quick fix of putting the dos thread on the main thread will break once SDL tries to run a full screen EXE app.
I'd really like to have the ability to emulate an x86 machine to run classic DOS games and even support Windows 95 for iOS, if there are alternative git repos out there that can do something similar, please let me know.

Cocos2d crash when using dictation (microphone button) with CCTextField

I get a permanent crash when tapping on microphone button during the input in CCTextField. There's no crash on iPhone 4s iOS8, but the game is crashed on iPhone 5s iOS9 and iPhone 6+ iOS9. This issue seems to be the same as described here http://discuss.cocos2d-x.org/t/engine-crash-on-ios7/9129/10 and there's a solution for cocos2d-x there. Can someone provide a solution for cocos2d-objc ?
Okay, here's the workaround for cocos2d-objc:
- (void) update:(CCTime)delta{
CCGLView *ccglView = (CCGLView *)[[CCDirector sharedDirector] view];
[EAGLContext setCurrentContext:ccglView.context];
}

How to open Soomla storefront in Spritebuilder?

I have a Spritebuilder project that i want to use with Soomla In App Purchase framework. In Spritebuilder, i have a button with "store" as selector for cccontrol. In Soomla documentation, the code that opens storefront is this:
[[StorefrontController getInstance] openStoreWithParentViewController:self]; // 'self' is the calling UIViewController
Normally in Xcode, i will do this:
- (void)store {
CCScene *storeAssets = [CCBReader loadAsScene:#"StoreAssets"];
[[CCDirector sharedDirector]replaceScene:storeAssets];
}
For this case, how do i integrate the Soomla code into Spritebuilder since it don't use UIViewController?
- (void)store {
//Soomla code
}

How to use accelerometer in cocos2d 3.0?

I am programming with Cocos2d 3.0 now, In Cocos2d 2.0, we can use the following code to add accelerometer to app, but this example was based on class CCLayer which has deprecate in Cocos2d 3.0, and UIAccelerometer also replaced by CMMotionManager in IOS 5.0, so I am wondering how to do this in Cocos2d 3.0? I googled for a while, didn't find anything useful.
-(id) init
{
if ((self = [super init]))
{
// ...
self.isAccelerometerEnabled = YES;
// ...
}
}
-(void) accelerometer:(UIAccelerometer *)accelerometer
didAccelerate:(UIAcceleration *)acceleration
{
// ...
}
===
We've written a tutorial on exactly this: https://www.makegameswith.us/gamernews/371/accelerometer-with-cocos2d-30-and-ios-7
You need to use the CoreMotion framework.
Well, there are two problems in the tutorial example given above.
Single instance of CMMotionManager.
Acceleration data become +Ve or -Ve according to the orientation of the device. You also need to add Scene as observer of device orientation change notification.
If you don't want handle these overheads, you can use CCAccelerometer class. It solves both the problems.
HOW TO USE
Add CoreMotion Framework in your project from Build Phases.
Copy CCAccelerometer.h and CCAccelerometer.m files in your project.
Import CCAccelerometer.h file in the Prefix.pch.
Implement the <CCSharedAccelerometerDelegate> in the CCScene where you want to use the accelerometer.
Create shared instance in init method by simply calling [CCAcceleroMeter sharedAccelerometer];
Start accelerometer in -(void)onEnterTransitionDidFinish by calling [CCAcceleroMeter sharedAccelerometer]startUpdateForScene:self];
Define delegate method -(void)acceleroMeterDidAccelerate:(CMAccelerometerData*)accelerometerData in your scene.
Stop accelerometer in -(void)onExitTransitionDidStart by calling [CCAcceleroMeter sharedAccelerometer]stopUpdateForScene:self];
You can find out the example project in GitHub.
Here is example:
Device::setAccelerometerEnabled(true);
auto accelerometerListener = EventListenerAcceleration::create([this](Acceleration* acc, Event* event)
{
});
getEventDispatcher()->addEventListenerWithSceneGraphPriority(accelerometerListener, this);
Also video tutorial https://www.youtube.com/watch?v=Xk6lXK6trxU

sharedScheduler is deprecated?

So, I want to create a slow motion effect, and I am using this method:
[[CCScheduler sharedScheduler] setTimeScale:0.5];
However, sharedScheduler is deprecated.
What is the equivalent method of creating a slow motion effect?
All answers and advice are appreciated!
You have to use [CCDirector scheduler].
CCActionManager, CCScheduler, CCTouchDispathcer (iOS) and
CCEventDispatcher (Mac) are NO LONGER singletons. Instead, they are
properties of CCDirector.
Link to documentation:
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:migrate_to_v2.0
--
If I understand what you mean by slow motion effect correctly, you can also use actions as follows (am dry coding here so might require cleanup):
CCNode *obj = //some object;
[obj runAction:[CCSequence actions:
[CCDelayTime actionWithDuration:0.5],
[CCCallFunc actionWithTarget:self selector:#selector(YOURFUNCTION)],nil]];
Try replacing:
[[CCScheduler sharedScheduler] setTimeScale:0.5];
with:
[[[CCDirector sharedDirector] scheduler] setTimeScale:0.5];