0

I've looked all over and I can't find how to properly place a uiprogressview programmatically on a scene in Xcode using cocos2d. Obviously cocos2d doesn't use interface builder so I'm basically building everything blind, but I can't figure out a way to do something like [self add child:progressbar]; or progressbar.position = cgrectmake(100,100,50,10);. How can I add a uiprogressview to my scene? Thanks for the help!

Seany242
  • 373
  • 7
  • 20
  • You could just use regular UIKit calls from Cocos2D and it will show up on the top layer. This is something I do in my app. – SimplyKiwi May 24 '12 at 00:13
  • I'm not sure I understand. Are you saying add a subview? – Seany242 May 24 '12 at 03:15
  • I'm sure cocos2D has their own UIProgressView but it depends on your needs. – SimplyKiwi May 24 '12 at 04:06
  • Cocos2d doesn't have a built-in progress view. CCProgressTimer comes closest but cocos2d 2.0 only supports radial progress. Scaling a solid-color sprite in X direction would also make a decent progress bar. – CodeSmile May 24 '12 at 09:36

2 Answers2

0

You can use a CCProgressTimer. You can read about it here.

http://www.cocos2d-iphone.org/api-ref/0.99.3/interface_c_c_progress_timer.html

There are also actions you can use to animate it. http://www.cocos2d-iphone.org/api-ref/0.99.5/interface_c_c_progress_from_to.html

If you actually want to place the UIKit progress bar you can do it by adding a subview to the cocos2d view. It is much easier if you are using Cocos2d 2.0. Remember when setting the position that UIKit starts from top left where as Cocos2d starts from the bottom left.

Ben Trengrove
  • 8,191
  • 3
  • 40
  • 58
0
[[CCDirector sharedDirector].openGLView addSubview:progressbar];

If you're using cocos2d 2.0 the openGLView property is just called view.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • I tried implementing this: `UIImage * progressIm = [UIImage imageWithContentsOfFile:@"load.png"];` `UIImage * trackIm = [UIImage imageWithContentsOfFile:@"track.png"];` `[progressBar setProgressImage:progressIm];` `[progressBar setTrackImage:trackIm];` `[[CCDirector sharedDirector].openGLView addSubview:progressBar];` But it didn't do anything. Still an empty scene. – Seany242 May 24 '12 at 22:05