How to use a UIView with a CCLayer cocos2d? - uiview

I am playing a short video with CCVideoPlayer in cocos2d and at the end of it I am capturing the very last frame of the video and I am showing it on the screen using a UIView because trying to draw it on a CCLayer makes the image show up with slightly different colors. I would imagine that is because the way that things are drawn in cocos2d is different than the way they are drawn on a UIView. So I need some way to keep the image on the screen Using the UIView, and I need to be able to draw sprites etc... on top of this view. So my question is, Is there a way to make a CCLayer transparent so that the UIView containing the image can still be seen and then draw on top of the image using a CCLayer?
(P.S I am using cocos2d v1.1.0-beta2b)

Related

How does an imageView appears in layers?

example
I'm looking for help developing a UIImageView that appears like the imageviews in photo. It will include several images. I want it to be appears in layers.
I think you're best off making a custom class (UIView) which accepts a few images. Then in that custom class, draw those images in UIImageView. Every time you're drawing that image make sure you're rotating the UIImageView a few degrees using transform. You could do something with a white border, too. This will intensify the 'polaroid photo' effect.

How to change border of this image

I am making a game using this function:
if (CGRectIntersectsRect(object.frame, object2.frame)) {
[self GameOver];
}
Both objects are square however the image of object #2 is not. Therefore when the borders collide (but not the actual pictures) the game ends. Is there a way I can have the border "fit" to the image, so that the game only ends when the actual pictures collide.
Thanks :)
**my image is a shark and therefore a rectangle cannot be used
A view's frame is always a CGRect, which is a rectangle. You can use UIKit Dynamics for collision detection with views, but that only support rectangles too.
As #jammycoder mentioned, try out SpriteKit or other game engines, if you need to detect custom shape bounds.

How to create a non-rectangular UIImageView

I'm trying to make a ViewController that presents info from a webpage like this:
However, I'm confused on one thing. How did they get the imageView to display an image that's cut off at the corner, i.e. not rectangular? Do you think they created that player card in Photoshop and used it as the background for the imageView image, or did they create it programmatically?
I wonder because the image is behind the picture of the bear, so I imagine if they created the background in Photoshop, how would they get the image behind the bear head? They can't have just created the card with the player's picture as part of it, then loaded the whole image because if they traded the player, because I'm sure they pull the player info and picture from the web so they can have a card for all players, even if they trade or acquire a new player mid-season, without having to update the app (and add the finished image to images.xcassets).
This can be composed from two CALayers at runtime. Put the picture on the bottom layer; the picture can come from anywhere - the web, the bundle, etc. the image source could be dynamic.
Put another CALayer on top, with the frame rendered with opaque colors, and a transparent cut-out for the picture in the middle:
There are a bunch of ways to do this. A simple and flexible way to do it is to create a CAShapeLayer that's the same size as the image view, with it's origin at 0,0, and add it as the UIImageView's layer's mask.
You'd create a filled UIBezierPath that maps out the part of the image you want to show, and install the bezier path's CGPath into the mask layer's path property.
The result would be that the image view is cropped so that only the part inside the shape is drawn.

Possible to ignore pan gestures on transparent parts of UIImageViews?

I'm working on an app that lets the user stack graphics on top of each other.
The graphics are instantiated as a UIImageView, and is transparent outside of the actual graphic. I'm also using pan gestures to let the user drag them around the screen.
So when you have a bunch of graphics of different sizes and shapes on top of one another, you may have the illusion that you are touching a sub-indexed view, but you're actually touching the top one because some transparent part of it its hovering over your touch point.
I was wondering if anyone had ideas on how we could accomplish ONLY listening to the pan gesture on the solid part of the imageview. Or something that would tighten up the user experience so that whatever they touched was what they select. Thanks
Create your own subclass of UIImageView. In your subclass, override the pointInside:withEvent: method to return NO if the point is in a transparent part of the image.
Of course, you need to determine if a point is in a transparent part. :)
If you happen to have a CGPath or UIBezierPath that outlines the opaque parts of your image, you can do it easily using CGPathContainsPoint or -[UIBezierPath containsPoint:].
If you don't have a handy path, you will have to examine the image's pixel data. There are many answers on stackoverflow.com already that explain how to do that. Search for get pixel CGImage or get pixel UIImage.

How Can I Animate The Significant Blurring of a Sprite

I am using Cocos2d on the iPad to create a small game. I would like to, purposely, significantly blur a sprite, and then fade it out.
Particularly, I was hoping to make a sprite containing text get blurry (like the ink was fading or soaking into the paper) and then ultimately disappear, as if by magic.
I know how to animate the fade process using Cocos2D actions.
How can I animate the process of a sprite becoming super blurry?
I do not think it is possible to do a blur effect with the default cocos2d actions/functions.
you might want to try this custom gaussian blur class out instead
http://www.cocos2d-iphone.org/forum/topic/6315
the code is in the middle of the thread
or a more troublesome alternative is to create the blur effect using frame by frame animation

Resources