Is it possible to run a cocos2d action like [CCScaleTo actionWithDuration:.3 scale:1.1] on a UIView? I know it's possible to wrap a UIView into a CCNode so you can add it as a child to a layer, but I have no idea as to how. Could anyone shed some light here? Thanks!
Edit: I've looked at CCUIViewWrapper but have had a few issues with it, namely that a) running actions on a wrapped UIView causes it to disappear and b) buttons lose their 'pushable' functionality; they're selectors aren't fired and their highlighted state isn't shown. But other than that it's great :D
Have a look at CCUIViewWrapper
http://www.cocos2d-iphone.org/forum/topic/22898
I eventually had to just use the Core Graphics equivalents to the Cocos animations when animating the UIView, and it worked well enough for me.
Related
I want to make a vertical scrolling view for the level selector on my SpriteKit game, I don't know if I have to use UIScrollView or make it using the SpriteKit framework. Please if anyone knows the best way to do it and how let me know. Thanks.
You have several options here.
It is possible to integrate UI elements into SpriteKit, but instead of adding children to self (your scene), you would add subviews to self.view. You would of course, work with the view now instead of a scene so theres a different way of positioning elements which you would have to work out. Theres quite a few examples of how to do this, here's one that might help you.
An alternative is using something like Scroll Kit, which helps you integrate a UIScrollView into SpriteKit very conveniently!
Also check out this question which might be exactly what you're looking for. Hope this helps!
So I'm trying to do exactly this:
http://blog.typpz.com/2013/12/09/ios-sdk-create-a-pop-up-window/
But since I am not using SpriteKit i can't use this exact method.
I imagine that there should be a way to create this same pop up window effect using sprite builders layer option maybe? Then animating it using some of the CCAction methods that exist. Im not sure though and don't really know how to go about figuring out.
Any help is appreciated.
A simple way to do this would be to create a CCLayer, as you said, and animate it.
Once you've created a CCLayer to the size of the "popup" you want, and then added whatever you want to put in it, you can then start animating it.
If you want to get a similar effect to the animation in the tutorial you linked, the best way would be to use a combination of CCActionFadeIn and CCActionScaleTo. Conveniently, Spritebuilder's animation set has both of these for use, and you can easily set up an keyframe animation from within Spritebuilder without too much code. (Make sure to name the animation sequence to something you can easily remember since you'll need to refer back to it when you start coding - I'd call it "PopupAnimation", or something like that.)
Once you've finished doing that, all you have to do is call the animation from your code. For example, if I have a CCButton whose selector is "showPopup", I would do:
func showPopup() {
self.animationManager.runAnimationsForSequenceNamed("PopupAnimation")
}
Assuming you've done everything right, the popup will now appear! But now you're stuck with the popup on the screen, and with no way out.
To fix this, make another animation sequence (I'll call this "RemovePopup") which will remove the popup from the screen. Add a button to your CCLayer, and set its selector to "hidePopup". From your code, you can then run:
func hidePopup() {
self.animationManager.runAnimationsForSequenceNamed("RemovePopup")
}
And now you have a "popup" window that you can animate!
Hey guys i have another problem.
I'm using a custom UIView class with the method drawRect.
No i have build a design in PaintCode and i call the method for drawing it in a drawRect method. The problem i have is that the drawRect only get's called once.
The thing i made in paintcode looks like a speedometer and the value of changes so i need to redraw it every time.
I have no idea on how to do this?
I have tried to use:
[PCView setNeedsDisplay:YES];
But that doesn't seem to work for me.
Can you guys help me out, big thanks.
I currently need to create a custom scroll view without using UIKit's scrollview in cocos2d.
The best way, I think, is to create a separate layer and then add all my sprites to that layer. But I'm not sure how to receive touch events for all of the sprites. Is there a best way to do this? Thanks!
Have you seen CCScrollLayer? It might not be suitable for you but maybe you can copy the way that it is picking up touches.
https://github.com/cocos2d/cocos2d-iphone-extensions/tree/develop/Extensions/CCScrollLayer
http://www.cocos2d-iphone.org/forum/topic/17118
There's another one here as well, not sure if it's a fork or an independent one:
https://github.com/jerrodputman/CCKit
But I didn't have much success with any of these. The bounce and other parts of the experience never feel right, so I go back to using UIScrollView to handle the touches.
I've been facing the same issue and I found the SWScrollView here:
https://github.com/saim80/Cocos2D-Extensions
met my needs better than CCScrollView. It acts more like the UIScrollView where as CCScrollView is more for paging from what I've seen.
There is a nice framework called CMMSimpleFramework.
http://www.cocos2d-iphone.org/forum/topic/39018
http://www.cocos2d-iphone.org/forum/topic/60354
There are some sample videos, and the link to the repo is on those pages.
One of the classes is a scrolling layer that might do what you need.
To get the sample project to run, I had to comment out some game center authentication handler code that has changed, but after I did that the demo worked fine.
I never developed in Cocos2D. However, this animated app is not easy to make with regular UIView animation and CAAnimation.
I want a number of UIImageView's (from 1 to 30) to float around the screen with the certain path and I want them to be responsive for touch (they would do some animation when touched). I also need them to go back and forth the screen (new path would be calculated) when they are touched or reach the edge of screen. It's important to retrieve X and Y position of each element whenever needed.
Question is: what Cocos2D classes are best looking at (for a beginner) to make that happen? I've tried UIView animation and CAAnimation but I came across some difficulties so I have a feeling Cocos2D may bring better results. Thank you.
Yes, cocos2d makes it much easier. You want to create a CCSprite with the initWithFile: method. Example:
CCSprite *mySprite = [CCSprite initWithFile:#"fire.png"];
[self addChild:mySprite];
Where fire.png has been added to the project and self is the scene instance.