I have two NSOpenGLViews, named myView1 and myView2. myView2 is a sub view of myView1. Then I use CVDisplayLinkCreateWithCGDisplay to create a display link for the main display. Both myView1 and myView2 will draw something in the main thread(i.e. in drawRect function) using OpenGL. In the display link callback, I'll also draw something for myView1 using OpenGL.
The drawing codes is something like
[self.openGLContext makeCurrentContext];
[self.openGLContext lock];
//draw something ...
[self.openGLContext flushBuffer];
[self.openGLContext unlock];
Everything works well at this moment. But if I add the following code for both myView1 and myView2, it will easily runs into a hang.
[self setWantsLayer:YES];
The call stack is here: enter image description here
It seems that both the main thread and Display Link callback locks in [NSOpenGLContext flushBuffer].
Does anyone know how to solve this problem?
Related
I am having problems with using a camera in OpenGL/freeGLUT. Here is my code:
http://pastebin.com/VCi3Bjq5
(For some reason, when I paste the code into the code feature on this site, it gives extremely weird output.)
As far as I can tell this should rotate the camera when arrow keys are pressed - but it does nothing. It also seems that even the initial camera position is wrong. Any clue why this is?
The display function is only called once. You need to either set an idle function with glutIdleFunc() or tell GLUT that the display function must be called again with glutPostRedisplay().
i have got a probling concerning my animation.Sqeuence.
Only the first Sequence Element is being executed. The 2nd is ignored.
I want the Sprite spell_1 to move to the Hero (hero_x_exact,hero_y_exact), and after that to the destination.
Each element works fine for itself but not in a Sequence.
goog.require('lime.animation.Sequence');
...
var spellmovement = new lime.animation.Sequence(
spell_1.runAction(new lime.animation.MoveTo(hero_x_exact,hero_y_exact).setDuration(1).enableOptimizations()),
spell_1.runAction(new lime.animation.MoveTo(target_coord_x_spell,target_coord_y_spell).setDuration(1).enableOptimizations())
);
What might work better is using a spritesheet with each animation on the spritesheet Then you can build something that loads each animation by name. Obj_Walk001.png, Obj_Walk002.png
Then create a method to read each animation per frame in the scheduling manager.
You can find an example of this code in limejs/lime/demos/test. Then goto run.htm and click on Frame4 this one will show you how limejs is going it.
Can anybody point me in the right direction to how I could use UICollectionViewLayout to create an interface similar to the Pinterest column layout?
I tried searching online, but it looks like there are not many examples out there yet.
The 1000memories "Quilt" view is pinterest-like and open source: http://blog.1000memories.com/168-opensourcing-quilt, and you can dig through that to see how it works.
If you're looking for a more conceptual overview, here's the basic idea of what you're going to want to do. The easiest thing by far, if you just need a Pinterest-style layout, is to subclass UICollectionViewFlowLayout. You get a lot of layout help from this class, and Pinterest style is within its capabilities. You only need to override one method.
Set up a normal UICollectionView using UICollectionViewFlow layout. A quick way to do this is:
Drag a UIViewController onto a storyboard, drop a UICollectionView on that. Set the classes to match your custom classes, etc. You can use a delegate and create a delegate class here but strictly speaking that is not necessary to achieve JUST the Pinterest flow layout (you will almost definitely want to break the selection responsibility stuff into a delegate class in reality though).
Stub out a data source. Implementing the data source protocol for UICollectionView (http://developer.apple.com/library/ios/#documentation/uikit/reference/UICollectionViewDataSource_protocol/Reference/Reference.html) is trivially simple. Make sure you set a reuse identifier on your UICollectionViewCell. You need:
(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
just return 1 for now;
(NSInteteger)collectionView:numberOfItemsInSection:
hardcode a number for now, make it 20.
– (UICollectionViewCell *)collectionView:cellForItemAtIndexPath:
This is one of the places where subclassing the flow layout's gonna do you a favor. All you really need to do here is call dequeueReusableCellWithReuseIdentifier:forIndexPath: with the index path. If you added a UIImageView or some labels to the cell, this would be a great place to actually assign the image, text, etc.
In the viewController's viewDidLoad instantiate a UICollectionViewFlowLayout and set the UICollectionView's datasource to yours and layout to flowlayout. Remember, this class is a subclass of UICollectionViewViewController.
self.collectionView.dataSource = [[YourDataSource alloc] init];
self.collectionView.collectionViewLayout = [[UICollectionViewFlowLayout alloc] init];
Ok. At this point you should be able to run your app and see some stuff on the screen. This is a whirlwind overview. If you need more details about how to set up ViewControllers and so on there's tons of stuff available about that.
Now comes the important part, Pinterest-izing the flow layout.
First, add a new class that is a subclass of UIViewControllerFlowLayout. Change your ViewController's viewDidLoad to instantiate this class and assign as the UICollectionView's collectionViewLayout.
The method you are going to need to implement is - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect.
Here's the thing: The superclass is going to do almost all the work for you. Your code is going to look something like this:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
[attributes enumerateObjectsUsingBlock:^(id attr, NSUInteger idx, BOOL *stop) {
float newYCoord = [calculationMethodYouHaveToWriteFor:attr.frame];
attr.frame = CGRectMake(attr.frame.origin.x, newYCoord, attr.size.width, attr.size.height];
}];
}
Pinterest uses fixed-width columns, all you need to do in your calculation method is figure out what column you are in (`attr.origin.x / _columnWidth), and look up the total height in that column from the ivar you've been saving it in. Don't forget to add it to the new object's height and save it back for the next pass.
The flow layout superclass handles: making cells, determining which cells are visible, figuring out the contents size, figuring out the arrangement of the rows in the x direction, assigning index paths to cells. Lots of junk. And overriding that one method lets you fiddle with the y-pos to your heart's desire.
Heres two from github
https://github.com/jayslu/JSPintDemo
https://github.com/chiahsien/UICollectionViewWaterfallLayout
I've used a modified version of Waterfall in a project now, and I'm investigating JSPint now.
I have created a custom uicollectionviewlayout which is used in my personal project. Here is the link. Hope it helps.
https://github.com/johnny0614/YJZAlbumCollectionViewLayout
You can get anything you want from here:
https://github.com/ParsifalC/CPCollectionViewKit
For example(Both these two layouts are custom UICollectionViewLayout):
i have 8 movie Clips that i stored in an array. i put the movie clips on the stage and i can move them around so everything work fine until now. I made a grid where the mc's can be droped.I saved the grid parts in an array,too.
after that gave names to the mc's and to the grid parts like that:
mc.name= number.toString();
gridpart.name= number.toString();
the movie clips and the grid parts have the same name like: mc1.name=1 and gridpart1.name=1 and so on.
Now I made an if statement to check if the right mc was droped on the right grid part, like that:
if(mc.name==gridpart.name)
{
trace("correct position")
}
But nothing happens. I used "dropTarget", too like that:
if(dropTarget.name==a.target.name)
{
//code
}
I don't know what to try now. I thought to put this code in the callback function of the mouse.CLICK event handler because i want that the mc should not be moved anymore if it is on hir correct position.
I would be happy if you have a better solution for this problem.
I tried to describe my problem so that you can imagine what I am trying to say.
Sorry about my English, I am not a native English speaker.
Thank you for your time
I think you wrong using dropTarget.name. Try dropTarget.parent.name. This why dropTarget is referred to content of the DisplayObject onto which you release your dragged MovieClip.
I hope this will be usefull to you!
I try to draw with libcairo, it draws nothing. I downloaded the diagram sample, it works fine [draw.c], but code example from the site doesn't draw: like http://cairographics.org/samples/fill_and_stroke2/
why?
Thanks!
The code you linked to looks fine. But of course, it's not a complete program. Without seeing what code you've wrapped around the example to make it run, all I can guess is that you may need to call cairo_show_page() and cairo_surface_flush().