Create new project from opengl template via xcode4, you will see one color square moving.
I want to put two more small views to show the same thing. What I did is to add two
EAGLView *glView1;
EAGLView *glView2;
Then set up with property/systhesize etc, and same coding with self.view like these
[(EAGLView *)self.view setContext:context];
[(EAGLView *)self.view setFramebuffer];
if (!glView2) {
glView2 = [[EAGLView alloc] init];
}
[self.glView2 setContext:context2];
[self.glView2 setFramebuffer];
if (!glView1) {
glView1 = [[EAGLView alloc] init];
}
[self.glView1 setContext:context];
[self.glView1 setFramebuffer];
Do same thing for other place which self.view did. Also do the right thing to link within interface builder. (xcode4)
But the result show
I found that the last draw order in drawFrame will decide which window will show
[self.glView1 setFramebuffer];
[self.glView2 setFramebuffer]; // these will not show , but if put last, it will show
[(EAGLView *)self.view setFramebuffer]; // this will work
Does that make sense to explain my purpose and issues ?
Thanks very much for point out the root cause and help me go through this.
You need to read about OpenGL ES 2.0 ("OGLES2.0") . You shouldn't be using multiple EAGLView instances. You need only one, and you use OGLES2.0 commands to draw on it.
OpenGL is not easy to learn, and you will have to invest many hours of your time before you can achieve even simple renders with it. You should seek an external library like cocos2D to help you achieve what you want. Read the tutorials and documentation there carefully, and experiment. It will still take you a lot of time to achieve pleasing results, but far less than if you were using OGLES directly yourselfe
Related
Question:
Are there ways to animate anything within the LaunchScreen.xib file of an Xcode 6 Project targeted to deploy for iOS 8.1+ ?
Context:
I'm looking to make simple animations to convey activity or serve as a distraction to the user while they wait...
Examples:
A Loading Bar
Activity Indicator
Animated GIF
Move a UIImage across the Screen
Rotate an Image
Nope.
The Launch Image is shown only during the time period between when the user chooses to launch your app and when your app has actually started running. During this period, your app can't take any actions such as performing an animation — it's not running yet. The Launch Image is just a static image that, when well designed, helps give the user the impression that your app is ready quickly.
(Some developers ignore the HIG and use the launch image to provide a splash screen, sometimes with an animated presentation. But in those cases, the launch screen is still a static image, and the animation happens once the app begins running — it's just that the first frame of animation drawn by the running app matches the appearance of the static launch image.)
This behavior didn't change with the LaunchScreen.xib feature in iOS 8 — it still appears only before your app is actually running, so it's still a static image. What the LaunchScreen.xib feature gets you is the ability to adaptively produce a launch image for many different device sizes and styles without having to separately design, render, and ship in your app bundle different images for each size/orientation/etc.
If your app isn't actually ready to use by the time it gains control, think about whether the "loading" tasks you're doing at that time really need to be done immediately, or if you can let the user start doing some things right away and do more setup work on a background thread or defer it until it's actually needed.
I don’t use splash screens often but when I do, I want them to open like a book.
In all truth, I’m not a big fan of splash screens and even Apple recommends using a default.png that shows the controls (with no text) of the application:
Display a launch image that closely resembles the first screen of the application. This practice decreases the perceived launch time of your application.
Avoid displaying an About window or a splash screen. In general, try to avoid providing any type of startup experience that prevents people from using your application immediately.
from HIG Guidelines
However, some people love them and one app in particular has a nice implementation splash screen — Path 2.0. When you open Path, you’re greeted with their logo on a red version of the Apple linen texture that animates open like a book (or journal as that’s what Path considers themselves to be).
You can get the source for this project here: https://github.com/jaysonlane/OpenBook
Before we begin, let me preface this with a disclaimer: I am very new to animations in Cocoa so bear with me. If you spot unnecessary or inefficient code, please leave a comment and I’ll tidy it up.
If you haven’t seen the animation, hop on the app store and pick up a copy to see what we’re trying to accomplish. I’ve created a default png that we can use cleverly titled Math (like a Math book that opens, right?) You can download that here (retina) and here.
To get started, let me explain “the trickery” behind what we’ll be doing: we’re going to use the normal default splash system in place to display our default.png. In the App Delegate, once the application has finished launching, we’re going to create a UIImageView on top of our view of that same default.png. We’ll then animate that UIImageView, to rotate open to reveal our view.
So let’s go:
Create a new project, I created one using the single view template but this will work with whatever. Go ahead and set your default.png and default#2x.png to the images supplied. You can do this by clicking the project in the navigation pane on the left, click the Target and scroll down to launch images:
Open your AppDelegate.m and add the following code to your application didFinishLaunching or application didFinishLaunchingWithOptions function:
//1. add the image to the front of the view...
UIImageView *splashImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[splashImage setImage: [UIImage imageNamed:#"Default"]];
[self.window addSubview:splashImage];
[self.window bringSubviewToFront:splashImage];
//2. set an anchor point on the image view so it opens from the left
splashImage.layer.anchorPoint = CGPointMake(0, 0.5);
//reset the image view frame
splashImage.frame = CGRectMake(0, 0, 320, 480);
//3. animate the open
[UIView animateWithDuration:1.0
delay:0.6
options:(UIViewAnimationCurveEaseOut)
animations:^{
splashImage.layer.transform = CATransform3DRotate(CATransform3DIdentity, -M_PI_2, 0, 1, 0);
} completion:^(BOOL finished){
//remove that imageview from the view
[splashImage removeFromSuperview];
}];
Three things are happening here…
1) We create a new UIImageView and add it to the top of the view
2) We set an anchor point on the left side of the image to make it open from the left and then reset the frame to the full size of the view
3) We animate the UIImageView and remove it from the view on completion
That’s it, it’s that simple.
Source: http://jaysonlane.net/tech-blog/2012/03/path-2-0-style-animated-splash-screen-default-png/
You can create the LaunchScreen.xib and then create a perfect replica that you can put code on and have a class like LaunchScreenAnimator that you can call form your delegate and that has a delegate to tell you when the animation is over
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
LaunchScreenAnimator *la=[LaunchScreenAnimator createWithDelegate:self];
self.window.rootViewController=la;
[self.window makeKeyAndVisible];
[la startAnimation];
return YES;
}
-(void) splashAnimationFinished:(LaunchScreenAnimator*)view
{
[self startWithDashboardWindow]; // replace the current rootViewController with whatever you want
}
I've worked with Xcode and iOS on a few personal projects and have always used non-object-oriented designs for everything... just because I've been doing mostly learning/experimenting with things.
Now I've been trying to implement some object oriented design into one game I've made previously. The idea is, I have a space ship that can shoot bullets. In the past I basically added the UIImageView to the storyboard and then connected it to the .h file and from there did things on it like move it around or whatever (using CGPointMake).
The idea now is to make a method (and a whole other class soon) that will create a UIImageView programmatically, allocate it, add it to the superview etc... I've got this working so far, easy stuff, but the next part is a bit harder. Where do I store this local variable "bullet"? I've been saving it to an NSMutableArray and doing the following:
(actually here are the methods that I have)
-(void)movement {
for (int i = 0; i < [array1 count]; i ++) {
UIImageView *a = [array1 objectAtIndex:i];
a.center = CGPointMake(a.center.x + 2, a.center.y);
if (a.center.x > 500) {
[array1 removeObjectAtIndex:i];
[a removeFromSuperview];
}
}
}
-(void)getBullet {
UIImageView *bullet = [[UIImageView alloc] initWithFrame:CGRectMake(ship.center.x + 20, ship.center.y - 2, 15, 3)];
bullet.image = [UIImage imageNamed:#"bullet2.png"];
bullet.hidden = NO;
[self.view addSubview:bullet];
[array1 addObject:bullet];
}
(by the way, array1 is declared in the .h file)
and theres a timer that controls the movement method
timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(movement) userInfo:nil repeats:YES];
first question is: what is the correct way of doing this? Storing a bullet for example until it is removed from the superview, should I store it another way?
and another question is, when I remove a UIImageView from the superview, does that remove it from memory so its not using up system resources?
Thank you for the help!
(will update if I Think of other questions
UPDATE
I would like to point out that currently this is not functioning correctly. When I click on a "shoot" button that I have created (which basically calls the getBullet method) the bullet appears but does not move.. not sure why. This is part of why I'm asking this question as well.
I offer you a totally different solution. Instead of using the built in UIKit to perform graphics calculation and move things around the screen, try using an external framework other than UIKit. The UIKit framework is really good at its intended job, which is more oriented around a touch based user interface than game development. The following is pulled from the UIKit documentation from Apple.The UIKit framework provides the classes needed to construct and manage an application’s user interface for iOS. It provides an application object, event handling, drawing model, windows, views, and controls specifically designed for a touch screen interface.As you can see, UIKit was made for the purposes of slick user interfaces, not animating sprites (spaceships, bullets) around the screen.
The best alternative is to look down another path. The first thing to go to would be SpriteKit. Made by Apple and already included in Xcode, SpriteKit is the perfect tool for your job. Made specifically for game development, it has the ability to seamlessly animate many sprites on screen at a time (bullets in your case) and has a built in physics engine. It is very easy to learn, and has the potential to turn you idea into a great game.
The link to the SpriteKit documentation can be found here.
I work on an app, which scans an image and shows you a 3D-Object or a video on top of the image target. Normal AR-App. For that AR stuff I usw the Vuforia SDK. The problem is, that the Vuforia SDK don't support animated 3D-Objects and for that I use cocos3d.
So I created a basic cocos3d app and included my vuforia stuff for the AR. This works good and the app displays normal 3D-Objects and videos. This was the background, now the problem.
The first view I have is my camera view, which scans the images. If I scan now a specified target, I want to show an animated 3D-Object. For that, I display the cocos3d view on top of the AR-View. The cocos3d view is transparent and is displayed on top of the AR-View (tested this with a simple button in the cocos3d view).
The problem is, that I'am not able to display a animated 3D-Object. I tested some options but none of them worked because I don't really have an idea how to do that. My current code:
CCDirector *director = CCDirector.sharedDirector;
EAGLViewCC *glView = [EAGLViewCC viewWithFrame:[window bounds] pixelFormat:kEAGLColorFormatRGBA8 depthFormat:GL_DEPTH_COMPONENT16_OES];
[director setOpenGLView:glView];
[window addSubview:director.openGLView];
After that I have a layer and add the test scene to my layer (Standard from the example). But than I don't know how to display it. It tried this:
[director pushScene:scene];
but no luck. In the example, they use this code to show the object (viewController is of type "CC3DeviceCameraOverlayUIViewController").
[viewController runSceneOnNode: mainLayer];
Why don't I use the viewController? Because I couldn't get the view transparent. So how do I get the 3D-Object displayed in my view? What do I have to do? Am I completely wrong?
Hopefully my question will make sense. Just started with Qt so bear with me.
I have an app in Objective-C (for iOS) and I'm trying to add a piece of code in Qt into it.
Most of the UI is in Objective-C (meaning I got UIViews, UIViewControllers, ...) and only a part of it should be handle in Qt.
To create a UI element in Qt, I guess I need to create something that inherits from QWidget.
But how would I set the parent of this QWidget to one of my UIView element?
I understand it would be easier to do everything in Qt, but that is just to much work so that is why I am hoping I can keep part of my UI in Objective-C and the other part in Qt.
Thanks for your help
--
Edit
Well I was following the example from here. Even if it is for Mac OS.
QWidget * qWidget = new QWidget();
qWidget->move(0, 0);
qWidget->setPalette(QPalette(Qt::red));
qWidget->setAutoFillBackground(true);
QVBoxLayout *layout = new QVBoxLayout();
QPushButton *pushButton = new QPushButton("An Embedded Qt Button!", qWidget);
pushButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
layout->addWidget(pushButton);
qWidget->setLayout(layout);
// Adjust Cocoa layouts
UIView *uiWidgetView = (__bridge UIView *)((void*)qWidget->winId()); // Fancy cast for ARC
// Add the widget
[self.view addSubview:uiWidgetView];
qWidget->show();
pushButton->show();
But it does not seem to work for iOS...
I have two messages:
- This plugin does not support propagateSizeHints()
Do not know how to fix that one
- QIOSBackingStore needs to have the same size as its window
This one is referenced here. Does not seem to be fixed yet.
Note: Adding a simple uiview (like a uilabel) to my current view works fine. Just this one that does not seem to render for some reason... :s
I have pretty much made my app to about 90% using UIKit code since it is my first app and wanted to keep it simple. Now I learned that I needed to use Cocos 2D in one of my views, my play view. So I have coded half of the functionality in the view using UIKit. Is there any way to use Cocos 2D in that view for the actual game part? Are there any easy tutorials or links someone can point me to, to do this?
Thanks!
I think the link Brad noted is a great reference. More immediately something like....
EAGLView *glview = [EAGLView viewWithFrame:CGRectMake(0, 0, 250,350)];
[yourView addSubview:glview];
CCDirector *director = [CCDirector sharedDirector];
[director setOpenGLView:glview];
Should work for you. Create the OpenGL view for the CCDirector to use. Attach that view as a subview of the view where you want it placed. Attach the CCDirector to your OpenGL view.
Additionally the Cocos2D website and wiki have some great resources that may help...
Cococs2D Wiki - http://www.cocos2d-iphone.org/wiki/doku.php/
Cocos2D Forums - http://www.cocos2d-iphone.org/forum/