Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
modig
Aug 20, 2002
Can somebody show me how to make an NSArray with random integers in it using arc4random()? Or explain what data type I should be using and give me some example code on how to make it?

I tried

code:
NSArray varname = [[NSArray alloc] initWithObjects: arc4random(), arc4random(), nil];

and 

NSInteger a = arc4random()%6;

NSArray varname = [[NSArray alloc] initWithObjects: a, a, nil];
In both cases I get an error about implicit conversion to type id. I know this is a super basic error, I just don't understand typing in objective c at all. The only examples I can find online using NSArray all deal with holding a bunch of string objects. I just want a few numbers to represent dice rolls. I would use a normal c array but I couldn't get that to work and found someone who said that isn't part of objective c. The only other math I'll need after this is comparisons and to be able to sort the array by numerical value.

Adbot
ADBOT LOVES YOU

Kekekela
Oct 28, 2004
I believe you need to convert the NSInteger to an object:
code:
 [NSNumber numberWithInt:a]

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.
Every member of an array must be some kind of NSObject, which int is not and NSInteger also is not. Normal C arrays should work if you want to avoid NSArrays, but you can also wrap your numbers in NSNumber objects like..

int cInt = 324;
NSInteger objCInt = 23444;

NSArray * numArray = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:cInt], [NSNumber numberWithInteger:objCInt], nil];

lord funk
Feb 16, 2004

So I've made a French localized version of Localizable.strings, changed my iPad to French, and the French version of the strings doesn't pop up (it's still clearly using the English file).

I've changed the file encoding to UTF-16, I tried adding a CFBundleLocalizations array to the Info.plist, neither kicked it into French. What am I missing?

I've done this before. :(

Edit: deleting the app from the iPad then reloading did it. Weird.

lord funk fucked around with this message at 01:12 on Nov 28, 2011

Doc Block
Apr 15, 2003
Fun Shoe

modig posted:

Can somebody show me how to make an NSArray with random integers in it using arc4random()? Or explain what data type I should be using and give me some example code on how to make it?

I tried

code:
NSArray varname = [[NSArray alloc] initWithObjects: arc4random(), arc4random(), nil];

and 

NSInteger a = arc4random()%6;

NSArray varname = [[NSArray alloc] initWithObjects: a, a, nil];
In both cases I get an error about implicit conversion to type id. I know this is a super basic error, I just don't understand typing in objective c at all. The only examples I can find online using NSArray all deal with holding a bunch of string objects. I just want a few numbers to represent dice rolls. I would use a normal c array but I couldn't get that to work and found someone who said that isn't part of objective c. The only other math I'll need after this is comparisons and to be able to sort the array by numerical value.

Objective-C is a strict superset of C, so anything that is valid C is also valid Objective-C.

nolen
Apr 4, 2004

butts.
I need some cocos2d help, or maybe just some OpenGL help?

This is just a mockup I whipped up in my photo editor.



Let's say I want to load in an image like the one of the left but alter it at runtime to look like the one on the right.

I know I need to do something along the lines of extending CCNode and overriding the draw method, but beyond that I'm totally lost.


Any suggestions?

Doc Block
Apr 15, 2003
Fun Shoe
Unless Cocos2D has some sort of trapezoidal deformation you can apply to sprites, you're in OpenGL ES territory.

Conceptually it's very easy: you assign the texture coordinates as if the polygons were going to be drawn as a straight-on square like on the left, but when you actually draw them the actual shape of all the polygons is the thing on the right.

Implementing it within Cocos2D probably wouldn't be too hard, if you already know OpenGL ES 1.1. Cocos2D handles pretty much everything for you with regards to setting up the OpenGL context and all that; you just have to render the polygons (and assign texture coordinates, etc.).

edit: just remember that when Cocos2D switches to OpenGL ES 2.0 you'll most likely have to rewrite your custom drawing code.

lord funk
Feb 16, 2004

Speaking of OpenGL, I'm trying to programmatically take a screenshot of my EAGLView, so I found this post over in the dev center about how to do that. I dropped the call to the screenshot function before presentFramebuffer, but the PNG file delivered is completely blank. It's the right size - but it's empty.

code:
- (BOOL)presentFramebuffer {
    BOOL success = FALSE;
    
    if (context) {
        [EAGLContext setCurrentContext:context];
        
        // discard depth buffer whenever possible, to gain more memory bandwidth.
        // this is no necessary for MSAA but helps boost performance even in non-MSAA cases.
        GLenum attachments[] = {GL_DEPTH_ATTACHMENT};
        glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments);
        
        glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, msaaFramebuffer);
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, defaultFramebuffer);
		glResolveMultisampleFramebufferAPPLE();
        
        // need to restore colorRenderbuffer if it's MSAA enabled
        glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
        
        //save snapshot every 500 frames
        static GLint screenshotFrameCounter = 0;
        screenshotFrameCounter++;
        if (screenshotFrameCounter % 500 == 0) {
            NSFileManager *fileManager = [NSFileManager defaultManager];
            UIImage *screenshot = [self takeSnapshot:self];
            NSData *myImageData = UIImagePNGRepresentation(screenshot);
            [fileManager createFileAtPath:[NSString stringWithFormat:@"%@/screenshot.png",DOCUMENTS_FOLDER,screenshotFrameCounter] 
                                 contents:myImageData 
                               attributes:nil];
            NSLog(@"taking screenshot");
        }
        
        [context presentRenderbuffer:GL_RENDERBUFFER];
    }
    
    return success;
}
I'm using OpenGL ES 2.0, so the only thing I changed from - (UIImage*)snapshot:(UIView*)eaglview is changing

glBindRenderbufferOES(GL_RENDERBUFFER_OES, _colorRenderbuffer);
to
glBindRenderbuffer(GL_RENDERBUFFER, _colorRenderbuffer);.

Why would my image be blank?

lord funk
Feb 16, 2004

I thought this might do it: changing kCGImageAlphaPremultipliedLast to kCGImageAlphaNoneSkipLast, since my layer is opaque, but now I get a completely black image.

code:
// Create a CGImage with the pixel data
    // If your OpenGL ES content is opaque, use kCGImageAlphaNoneSkipLast to ignore the alpha channel
    // otherwise, use kCGImageAlphaPremultipliedLast
    CGDataProviderRef ref = CGDataProviderCreateWithData(NULL, data, dataLength, NULL);
    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
    CGImageRef iref = CGImageCreate(width, 
                                    height, 
                                    8, 
                                    32,
                                    width * 4, 
                                    colorspace, 
                                    kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipLast,
                                    ref, NULL, true, kCGRenderingIntentDefault);

lord funk
Feb 16, 2004

Here is the entire EAGLView.m if it helps.

lord funk fucked around with this message at 21:24 on Nov 29, 2011

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.
I've been shocked at the terrible performance of animated CALayers in OSX for 2d stuff. I was told they basically act as abstracted OpenGL objects, but the stuttering I'm seeing moving any image larger than 500x500 or so seems to indicate otherwise. Am I going to have to use OpenGL?

edit: I realized a few of the large images in question have some non-0 and non-1 alpha going on all over the place that may be responsible for destroying performance. Time to spend some time messing around with that.

ManicJason fucked around with this message at 21:45 on Dec 2, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
In Cocos2D, I seem to have an issue with setting a sprites visibility to YES and NOT seeing the results immediately after a method call that hangs everything for a bit. It seems as though a frame draw has to occur, but this doesn't happen because the method call stops everything for a bit which makes it very noticeable. (There is no sprite in sight even though there should be)

Does anyone know how to force a frame draw in Cocos2D? I think this my problem. Calling update (my CCScheduler method) would probably just cause an infinite loop, and maybe there's some way I could circumvent this, but it's just going to get messy. I've also tried making the visibility YES right before the method is called, but that does not make it show up either.

LP0 ON FIRE fucked around with this message at 22:37 on Dec 2, 2011

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.
Taking away the alpha made very little difference.

A coworker suggested an issue with the images being too large for the OpenGL buffer, but there's very little way to investigate that using CALayers, as far as I can tell.


Here's what instruments has to say:

Star War Sex Parrot
Oct 2, 2003

Why didn't anyone tell me CodeRunner is so awesome?! Maybe it was mentioned and I missed it. Regardless, I was dreading my girlfriend taking a C++ class next quarter since they'll certainly teach in Visual Studio Express and she's most likely going to be using Xcode which is a bit overkill for a basic C++ class. I could set up Parallels or Boot Camp, but that's far more effort than I wanted to invest and not very seamless for her. However, CodeRunner looks to have a perfectly minimal interface that won't overwhelm her with buttons and options that she doesn't need (Xcode). It looks perfect for basic programming.



Just an editing pane and an output console, supports Lion full screen and versioning. It's perfect.

Star War Sex Parrot fucked around with this message at 23:58 on Dec 2, 2011

Zhentar
Sep 28, 2003

Brilliant Master Genius

ManicJason posted:

Taking away the alpha made very little difference.

A coworker suggested an issue with the images being too large for the OpenGL buffer, but there's very little way to investigate that using CALayers, as far as I can tell.


Here's what instruments has to say:



http://lmgtfy.com/?q=png_read_filter_row

Doc Block
Apr 15, 2003
Fun Shoe

ManicJason posted:

Taking away the alpha made very little difference.

A coworker suggested an issue with the images being too large for the OpenGL buffer, but there's very little way to investigate that using CALayers, as far as I can tell.


Here's what instruments has to say:



A 500x500 image isn't going to be bigger than your GPU's max texture size (which is going to be at least 4096x4096, probably more like 8192x8192).

Having alpha transparency shouldn't matter either.

There's something else going on.

edit:

Weird, I would think that the image would be uncompressed when you passed it in and would then be transformed into whatever format was most optimal for the hardware.

Doc Block fucked around with this message at 23:47 on Dec 2, 2011

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.

That would help me if I was coding for iOS. If you know of a OSX equivalent, feel free to answer instead of being a dick!

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.
I was finally able to get the PNGs loaded in an uncompressed format by using CGContextDrawImage() and then creating a new CGImage from the context. It had little if any positive effect and increased loading times a ton. It seems that compression isn't my issue.

I think I'm the right track though when I noticed just how much transparency is going on. I have a few transparent layers on top of each other in the background. I'm going to spend some time consolidating them if they don't need to be dynamic, and I'm considering using [CALayer renderInContext:] to obtain a screenshot, pasting that over the entire screen, and animating my temporary effects over that.

klem_johansen
Jul 11, 2002

[be my e-friend]
I know you can force a language at start up, but I can't find anything about changing the language on the fly-- anything that actually works, that is. Any ideas?

better question: should I lose the idea of setting the language inside the app? It seems like using the defined language is the way to go, but I want to make sure the user knows they can switch.

klem_johansen fucked around with this message at 06:07 on Dec 6, 2011

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I'll throw the standard "in general, don't do that" at you and suggest you, at most, point out that the user can change their language and locale settings in the Settings app.

That generally useless advice aside, what I'd do is localize your app like normal. Then, if you want to change the interface language just for your app, you can ask an NSBundle (e.g. your app bundle) what localizations it supports. When the user changes the app's language, you could manually load strings files and update the interface. (You'll probably have to hardcode the paths to the localized strings files, as I don't think NS/CF-Bundle will help you.)

Not speaking from experience, but I'm guessing your life will be made much easier if you avoid localizing nibs and simply make tables of strings. Then, on nib loading (or whenever), you can replace all the labels and such in your nib with whatever from the strings file.

e: This is probably quite a bit of work, and I'm assuming here that you have a compelling reason for your app's interface to be in a language different from the OS and every other app.

pokeyman fucked around with this message at 07:19 on Dec 6, 2011

duck monster
Dec 15, 2004

Yeah its not that hard to cook up your own solution with string replacing. Just create a function like , I dunno TR(@"String") and have it so it does a look up of the string and replaces it as needed. Keep the function name short as possible to minimize RSI or "brain RSI"

klem_johansen
Jul 11, 2002

[be my e-friend]

pokeyman posted:


e: This is probably quite a bit of work, and I'm assuming here that you have a compelling reason for your app's interface to be in a language different from the OS and every other app.

It's a kids' pop-up book, our third such app. The client wants people to be able to choose the language. I think I'll homebrew a localization set that defaults to the device's language setting.

Fate Accomplice
Nov 30, 2006




Does anyone have any links to resources on iOS UI design, besides the official HIG?

I'm at the point where I have a couple apps that need attractive and intuitive UI before I release them, and I want to get some best practices/tips/examples with commentary, etc.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Trying to wrap my head around IKImageBrowserView in conjunction with a foreground CALayer. Say I have a series of images in the browser via a Core Data model. These images will get various properties added to them via the UI. The properties will then be shown on top of the images themselves (via the CALayer) as the user scrolls around, following the images & keeping zoom etc in mind. Also clicking on the shown properties will produce some action.

Any resources that would help with that? I haven't done any Core Animation before.

Carthag Tuek fucked around with this message at 22:08 on Dec 8, 2011

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Malloreon posted:

Does anyone have any links to resources on iOS UI design, besides the official HIG?

I'm at the point where I have a couple apps that need attractive and intuitive UI before I release them, and I want to get some best practices/tips/examples with commentary, etc.

A sense of curiosity while browsing the App Store can take you a long long way.

lmao zebong
Nov 25, 2006

NBA All-Injury First Team
My two friends and I developed a game for Android that ended up being relatively popular and got featured on the Android Market and was used as Amazon's Free App of the Day, and have been working on an iOS port for the last couple months. It finally got approved today and now we have a bit of contention between us on starting price points and wanted to get some outside opinion. One member of our studio really wants to start at .99 in order to increase initial ranking and exposure, while I'm of the mindset that starting at 1.99 is smarter overall because it gives us more flexibility to play with the price and that the difference between number of sales at both points will be negligible.
I tried a quick google search to see if anybody had written about this topic and didn't come up with anything so I figured I'd ask here to see what you guys felt and what your experiences were with deciding starting pricing.

E: I figure I should probably say what our game is. Im not sure if it's live yet on the app store but it is a color based puzzle game a-la Trainyard called 'Refraction' and is based on manipulating colored lasers with mirrors and prisms.

lmao zebong fucked around with this message at 22:03 on Dec 9, 2011

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Seems to me most people will buy anything at .99 without hesitation, but will think twice if it's 1.99 - there appears to be an impulse gap there, at least in my circle.

Don't have any numbers of course, so not sure the difference would make up to be twice the sales at the lower price point.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Yeah honestly if you want maximum exposure, make it free for a week and then start charging.

lord funk
Feb 16, 2004

I'm about to finish my next app (feels strange to say it), and I can't remember: does the project name matter anymore? I have a bundle display name set, and I think you give the App Store name when you create the app in iTunes Connect. Does the Xcode project name matter?

Edit: I guess it doesn't.

lord funk fucked around with this message at 21:06 on Dec 10, 2011

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
It matters about as much as the filename, which is to say not at all.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Can I move or resize an NSButton while my app is running? I was going to make a tab system and was going to just use NSButtons, but it looks like I'm going to have to make my own.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Yes? Just set its frame.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
So I just upgraded to Lion and I didn't realize that doing so would disable my installed version of Xcode. Since the app store won't let me update it (says my copy of OSX is too new) how do I do this right? Just download the free version of 4.2.1 from the store and install it? Will that overwrite my current install or do I have to uninstall my current version of Xcode somehow?

The official documents say I'm supposed to run an upgrade tool through Xcode itself but I can't even launch the application to do so.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Grab any old SDKs you need from /Developer, then yeah, grab the free Xcode 4 from the App Store. Toss any old SDKs back where they came from.

Note that I've never bothered keeping old SDKs around so those instructions might be a bit off.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
Yeah it looks like the new version I downloaded from the app store was actually some kind of installer instead of installing straight from the app store like the first iteration of Xcode 4.

Man all that poo poo makes me nervous. After the first time my computer got wiped, watching Lion take 10 hours to download and install + updates and Xcode I was really worried.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

pokeyman posted:

Yes? Just set its frame.

Derp. That was simple. Didn't see it on the NSButton reference and haven't worked with views enough to realize it would inherit that method.

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.

Yodzilla posted:

Yeah it looks like the new version I downloaded from the app store was actually some kind of installer instead of installing straight from the app store like the first iteration of Xcode 4..
Yeah, all the updates are like that now. You have to manually run the installer they leave in Applications.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
^^ ah gotcha


Did the newer version of Xcode change a lot of basic things like the way TextViews and ScrollViews are rendered? I just opened a project from July and noticed some xib files were really screwy looking. Elements were resized and moved around but even stranger the TextViews no longer acknowledge line breaks. It's keeping ones that are already there but if I remove a line break and then try to add it back in using the visual editor by pressing control+enter it's not reflected in the view. The line breaks are being saved in the raw data but for some reason aren't represented visually.

Scroll views seem to now be cutting off the bottom of many pages as well. Very odd. I didn't convert the project to be base iOS version 5 for fear of things like this but I guess just updating Xcode was enough to mess little things up.

atomic johnson
Dec 7, 2000

peeping-tom techie with x-ray eyes

Star War Sex Parrot posted:

Why didn't anyone tell me CodeRunner is so awesome?!

This is pretty cool. Worth five bucks to me, anyway. I just wish it supported command line arguments and multiple files - at least the multiple files might bite someone who was taking a C++ class since submitted homework would probably want to have the headers and implementation separate.

At that point it might just become an underpowered IDE, though...

Adbot
ADBOT LOVES YOU

klem_johansen
Jul 11, 2002

[be my e-friend]
When adding a new subview with a page curl:

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]

in landscape mode, I have the issue where the curls look weird when the device is upside down. I tried alternative between curlUp & curlDown based on orientation, but it still doesn't look right.

I know i can set a container frame to flip everything in a block animation, but it doesn't seem to work in this form. It seems like there must be a simpler way. Is there?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply