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
Doc Block
Apr 15, 2003
Fun Shoe
I don't think SKLabelNode is meant to be used like you're trying to, it's intentionally very simple. If memory serves, they said right in the WWDC 2013 SpriteKit session video that you should use UILabel and only use SKLabelNode for simple text that doesn't change often. The impression that I got is that it's literally doing behind the scenes what you're doing.

SpriteKit seems nice at first, and then you try to actually use it and notice some glaring omissions and welp, back to Cocos2D.

edit: I've got it working in a UIView with plain old Core Graphics. Take out the line where you set the fill color, and make sure the line where you're setting the color in the text attributes is actually getting run.

edit 2: here, a working demo. Written in Objective-C instead of Swift, and doesn't do any of the SpriteKit stuff. It just draws colored text into a CGContext

Doc Block fucked around with this message at 09:29 on Jul 21, 2014

Adbot
ADBOT LOVES YOU

JakeLiebenow
Apr 21, 2013
I remember trying to learn Objective C once, ages ago. Tried to make an app with it, tried to learn everything on my own via Ray Wenderlich tutorials, and I had barely finished learning C. About a year's worth of coding experience.

Christ, that sucked. Might come back to it now though.

lord funk
Feb 16, 2004

JakeLiebenow posted:

I remember trying to learn Objective C once, ages ago. Tried to make an app with it, tried to learn everything on my own via Ray Wenderlich tutorials, and I had barely finished learning C. About a year's worth of coding experience.

Christ, that sucked. Might come back to it now though.

Took me until the third time through to get it. Learning how to make BankPayroll.app for the nth time made me want to die.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Axiem posted:

If you want multiline text, you either have to hack a container that actually creates an SKLabelNode per line and groups them together

This is what I did and I hate it.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice
Why can't you just whip up a UIView with a transparent background and layout whatever you want, then render that to an image? It can be offscreen and just re-used whenever the text changes. Would the performance be horrible? I have some code for that lying around if you need it.

For that matter, I haven't used SpriteKit so I have no idea if you can later UIKit over it directly or what.

Doc Block
Apr 15, 2003
Fun Shoe
Yes, that's what you're supposed to do with SpriteKit: use UIKit for the game's UI.

SKLabelNode just renders the text to a texture and then uses that as a sprite, which is why Apple cautions against using it for anything that changes: every change means it has to recreate the texture. Use UILabel if you want styled, multi-line text.

Or see my edit to my previous post for how to do text drawing with Core Graphics.

Toady
Jan 12, 2009

If you'd like to display multiline text, see DSMultilineLabelNode. There are other multiline implementations out there as well.

Axiem
Oct 19, 2005

I want to leave my mind blank, but I'm terrified of what will happen if I do
I'm not at a computer with Xcode at the moment, so I'll have to check out that UIKit code later. However, it's sounding more and more like perhaps SpriteKit isn't the right way to do my game. A lot of the game is going to be dealing with menus and text, as opposed to doing things with physics. I had originally done SpriteKit because well, game, and also because when I do transition things to being actual images for the buttons and such, I figured SpriteKit would handle that efficiently.

But if I end up needing to do custom UIView logic to get something as simple as a bit of text on the screen, I might as well transition the entire thing to UIViews (/UIKit in general).

Or is that also a bad idea when it comes to building a lot of custom stuff for a game aesthetic?

Doctor w-rw-rw-
Jun 24, 2008

Axiem posted:

Or is that also a bad idea when it comes to building a lot of custom stuff for a game aesthetic?

Core Graphics happens on the CPU, but CALayers will generally transform stuff on the GPU (such as transform, bounds, position). If you're doing more manipulation than redrawing, then you can probably get pretty far with those, but deep and complex UIView hierarchies get bogged down a lot sooner than CALayer hierarchies.

Axiem
Oct 19, 2005

I want to leave my mind blank, but I'm terrified of what will happen if I do

Doctor w-rw-rw- posted:

Core Graphics happens on the CPU, but CALayers will generally transform stuff on the GPU (such as transform, bounds, position). If you're doing more manipulation than redrawing, then you can probably get pretty far with those, but deep and complex UIView hierarchies get bogged down a lot sooner than CALayer hierarchies.

And SpriteKit uses CALayer while UIKit uses Core Graphics, I take it? (View stuff has never been my strong suit in any language)

At least with the way I've architected things so far, I should be able to transition some things to using UIKit (in particular, in the places where I intend on having text from a UI perspective), and can figure out how performance is going down the road. I want to avoid premature optimization for things I have no idea of the efficiency of.

Doctor w-rw-rw-
Jun 24, 2008

Axiem posted:

And SpriteKit uses CALayer while UIKit uses Core Graphics, I take it? (View stuff has never been my strong suit in any language)

At least with the way I've architected things so far, I should be able to transition some things to using UIKit (in particular, in the places where I intend on having text from a UI perspective), and can figure out how performance is going down the road. I want to avoid premature optimization for things I have no idea of the efficiency of.

SpriteKit is just a wrapper around an open-source game engine. Probably uses OpenGL or something. Core Graphics is just an API for drawing to a drawing context that's abstracted out, and being able to output it to vector graphics to PDF, or PNG, or whatever.

UIKit as I understand it is basically UIViews (CALayers + event handling) + a whole lotta keyboard/text plumbing, and integration with UIViewControllers and more advanced constructs that need the capabilities of UIViews.

No idea what your goals or ultimate ideas are but just do what you're comfortable with or think you can plausibly learn.

(E: clarity. also vvv is better-stated)

Doctor w-rw-rw- fucked around with this message at 18:23 on Jul 21, 2014

Doc Block
Apr 15, 2003
Fun Shoe
Just use Cocos2D. SpriteKit's API was heavily "inspired" by Cocos2D, but Cocos2D is a lot more mature, doesn't have the glaring omissions that SpriteKit does, and you can do everything in Cocos2D instead of a weird SpriteKit/UIKit hybrid (even custom drawing).

Also, Cocos2D V3 has very good integration with Chipmunk2D, which IMHO is a better and faster 2D physics engine than Box2D (which is what SpriteKit uses under the hood). And you can use SpriteHelper (or whatever it's called), which is like Interface Builder but for Cocos2D, and it also helps you build animations and physics.

Edit: Cocos2D uses OpenGL, so all drawing happens on the GPU.

UIKit uses Core Graphics and Core Text to draw the individual views on the CPU into CALayers (which cache the result), with Core Animation drawing and compositing the CALayers on the GPU.

SpriteKit probably uses OpenGL.

Doc Block fucked around with this message at 18:24 on Jul 21, 2014

Axiem
Oct 19, 2005

I want to leave my mind blank, but I'm terrified of what will happen if I do
Probably a better way to phrase what I mean is this: I'm going to migrate to just doing a UIKit interface for now, while I focus on making the gameplay and gameloop better. Once I get that into a better state, I can evaluate my options a little more for e.g. Cocos2D and such (and maybe find an artist willing to help out, because I'm terrible at art). Part of the advantage to a true MVC/MVP architecture is that so long as I have a clearly defined interface for my view, I can relatively easily switch it out down the line.

Doing a switch to UIKit will give me a chance to re-evaluate that interface and make sure it's doing the right thing.

Besides, learning a little more about UIKit can't particularly hurt with knowledge for future apps.

Ultimately, while I want to make a game, I'm also having fun just digging in and learning Swift, design patterns, and Cocoa Touch.

Thanks for the advice and knowledge. It's definitely helpful.

The thing that baffles me is that it doesn't look like a whole lot of work was done in the past year to cover up the glaring omissions that say, Cocos2D covers.

Toady
Jan 12, 2009

Doctor w-rw-rw- posted:

SpriteKit is just a wrapper around an open-source game engine.

What engine is it?

Doctor w-rw-rw-
Jun 24, 2008

Nipplebox posted:

What engine is it?

AFAIK - and I don't do games programming, so my knowledge is very superficial - it either has an API borrowed from or an API wrapping Cocos2D's. But I have spent literally zero time reading through docs for either project so I could be totally off base here, as I'm just recalling something that another developer told me.

E: vvvv UIKit Dynamics uses Box2D under the hood, but with regards to Cocos2D, you're probably right in that it's similar because it borrowed the same ideas to solve the same problems.

Doctor w-rw-rw- fucked around with this message at 01:40 on Jul 22, 2014

haveblue
Aug 15, 2005



Toilet Rascal
What I've seen of the API is extremely similar to cocos2d but they solve the exact same problem so that was inevitable whether it was their goal or not.

It's under the MIT license anyway so no one can get mad even if they did use it.

Toady
Jan 12, 2009

It definitely draws ideas from Cocos2D, but this is the first I've heard of it being a wrapper around Cocos2D. My understanding is that, at most, it uses Box2D.

Doc Block
Apr 15, 2003
Fun Shoe
Yeah, it's just a case of the SpriteKit API being similar to Cocos2D's.

There are enough differences and shortcomings in SpriteKit that it probably isn't a mere wrapper.

LP0 ON FIRE
Jan 25, 2006

beep boop
I can't believe I'm asking this, but where are the Provision Profiles listed on the Settings screen? I never had trouble finding these, or maybe it has disappeared somehow. Xcode is saying that it can't find any on the device, but if they expired I remembered them still being listed. Kinda stumped how this all happened.

Update - Looks like it doesn't show up as a section in General if you don't have any valid non-expired profiles!

LP0 ON FIRE fucked around with this message at 14:57 on Jul 23, 2014

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
When your application is in background, background tasks can run for about 60 seconds. When your application is in foreground, background tasks can run for 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368 seconds

(it's DBL_MAX)

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Is iTunes Connect broken / not working for anyone else? The website is in endless "your session has expired" cycles, and none of my apps in development can connect to game center. I have 3 accounts and they all are having the same issues. Apple's system status thing says everything is fine... :iiam:

Froist
Jun 6, 2004

Lumpy posted:

Is iTunes Connect broken / not working for anyone else? The website is in endless "your session has expired" cycles, and none of my apps in development can connect to game center. I have 3 accounts and they all are having the same issues. Apple's system status thing says everything is fine... :iiam:

I'm seeing the same, as is one of my colleagues. It's working fine for the guy in between us.

Hughlander
May 11, 2005

First question when I hear of things like this: did you try it with Safari?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Yes, after it wasn't working in chrome. Safari didn't help. Then suddenly it started working again.

Once again, posting in a thread magically fixes things!

dupersaurus
Aug 1, 2012

Futurism was an art movement where dudes were all 'CARS ARE COOL AND THE PAST IS FOR CHUMPS. LET'S DRAW SOME CARS.'
So I've been teaching myself this stuff as-needed for work and personal projects, but I'm thinking I should start thinking of this as a career option. Are there any primers on things that I should know, but might not pick up on my own? Obj-c-specific good practices, design principles, nooks and crannies, etc?

Ninja Rope
Oct 22, 2005

Wee.
I'm making a stupid screensaver that draws rects with NSBezierPath, however when I draw rects on top of each other they don't always cover up the rect underneath. Sometimes drawing a black rect over a red one will leave the 4 corner pixels still visible. Sometimes it does nothing at all. It seems to be related to the current screen resolution (if it's scaled or not), and it works fine on my rmpb screen at the highest scaled resolution. Since it's a screensaver I don't set up the window I'm drawing into at all, I just start doing this in the AnimateOneFrame method:

code:
path = [NSBezierPath bezierPathWithRect:rect];
color = [NSColor blackColor];
[color set];
[path fill];
Any suggestions on how to troubleshoot? I'm not sure it's the drawing code because the exact same binary behaves differently depending on the screen resolution (ie, scaled or not, external display or internal), and if I have two displays connected they will look different.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Ninja Rope posted:

I'm making a stupid screensaver that draws rects with NSBezierPath, however when I draw rects on top of each other they don't always cover up the rect underneath. Sometimes drawing a black rect over a red one will leave the 4 corner pixels still visible. Sometimes it does nothing at all. It seems to be related to the current screen resolution (if it's scaled or not), and it works fine on my rmpb screen at the highest scaled resolution. Since it's a screensaver I don't set up the window I'm drawing into at all, I just start doing this in the AnimateOneFrame method:

code:
path = [NSBezierPath bezierPathWithRect:rect];
color = [NSColor blackColor];
[color set];
[path fill];
Any suggestions on how to troubleshoot? I'm not sure it's the drawing code because the exact same binary behaves differently depending on the screen resolution (ie, scaled or not, external display or internal), and if I have two displays connected they will look different.

Are you drawing to the center point of each pixel (x+0.5) or directly on it? My first guess is maybe interpolation artifacts.

Another wild guess, but you could also try drawing to your own backing buffer of fixed resolution then scaling for display to get deterministic behavior. If the display is scaled, are you doing the scaling or is the OS? I wonder if the draw commands are being scaled before drawing (rather than scaling the resulting bitmap). In theory scaling the draw commands would yield better results but I can see that producing some jitter if you're trying to do sub-pixel precise overdraw.

I'm not an expert on this stuff though, so YMMV.

PiCroft
Jun 11, 2010

I'm sorry, did I break all your shit? I didn't know it was yours

I'm learning Objective C blocks and while I generally understand how to use them, I'm struggling to figure out how to use a block that takes parameters.

code:
#import <Foundation/Foundation.h>

typedef void (^TestBlock)(int *, int *);

@interface TestClass:NSObject

-(void)performWithBlock:(TestBlock)testBlock;
@end

@implementation TestClass

-(void)performWithBlock:(TestBlock)testBlock{
    
}

@end

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        
        int a = 10;
        int b = 20;
        
        TestClass *tClass = [[TestClass alloc]init];
        [tClass performWithBlock:^{
            
        }];

        
    }
    return 0;
}
In this case, I'm getting compiler error on the line [tClass performWithBlock:^{ because I haven't specified the two in arguments but I don't know how to pass them to this block. Can someone explain how?

haveblue
Aug 15, 2005



Toilet Rascal

PiCroft posted:

I'm learning Objective C blocks and while I generally understand how to use them, I'm struggling to figure out how to use a block that takes parameters.

code:
#import <Foundation/Foundation.h>

typedef void (^TestBlock)(int *, int *);

@interface TestClass:NSObject

-(void)performWithBlock:(TestBlock)testBlock;
@end

@implementation TestClass

-(void)performWithBlock:(TestBlock)testBlock{
    
}

@end

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        
        int a = 10;
        int b = 20;
        
        TestClass *tClass = [[TestClass alloc]init];
        [tClass performWithBlock:^{
            
        }];

        
    }
    return 0;
}
In this case, I'm getting compiler error on the line [tClass performWithBlock:^{ because I haven't specified the two in arguments but I don't know how to pass them to this block. Can someone explain how?

http://fuckingblocksyntax.com

e: Parameters go in parentheses between ^ and { when calling a block

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Objective-C code:
int a, b;
[tClass performWithBlock:^(int *blockA, int *blockB){
    // do stuff with blockA and blockB
    // read a and b from the outer scope
    // if you want to set the outer scope's a or b,
    // add the __block storage specifier
}];

PiCroft
Jun 11, 2010

I'm sorry, did I break all your shit? I didn't know it was yours

Thanks guys that makes sense.

Here's my completed code:

code:
#import <Foundation/Foundation.h>

typedef void (^TestBlock)(int *, int *);

@interface TestClass:NSObject

-(void)performWithBlock:(int*)num1 andNum2:(int*)num2 andBlock:(TestBlock)testBlock;
@end

@implementation TestClass

-(void)performWithBlock:(int*)num1 andNum2:(int*)num2 andBlock:(TestBlock)testBlock{
    NSLog(@"performWithBlock");
    NSLog(@"a: %i",*num1);
    NSLog(@"b: %i",*num2);
    testBlock(num1,num2);
}

@end

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        
        int a = 10;
        int b = 20;
        
        TestClass *tClass = [[TestClass alloc]init];
        [tClass performWithBlock:&a andNum2:&b andBlock:^(int * _a, int* _b) {
            NSLog(@"After testblock");
            NSLog(@"a: %i",a);
            NSLog(@"b: %i",b);
        }];

        
    }
    return 0;
}
with the output being:

code:
2014-07-27 17:22:27.114 ObjCTestbox[1278:303] performWithBlock
2014-07-27 17:22:27.116 ObjCTestbox[1278:303] a: 10
2014-07-27 17:22:27.116 ObjCTestbox[1278:303] b: 20
2014-07-27 17:22:27.116 ObjCTestbox[1278:303] After testblock
2014-07-27 17:22:27.116 ObjCTestbox[1278:303] a: 10
2014-07-27 17:22:27.117 ObjCTestbox[1278:303] b: 20
I really like blocks, they allow really nice callback systems, but I always struggle with passing parameters because of the bizarre bracket-heavy syntax.

Doc Block
Apr 15, 2003
Fun Shoe
What are you expecting to happen?

edit: in your block, you're printing a and b instead of _a and _b. So the block captures the main() function's a and b variables, and prints them out when called instead of the _a and _b variables that are passed to it.

edit 2: your method name is non standard and kinda confusing. If you have a method named -performWithBlock then the first parameter should be the block. Like this:
code:
- (void)performWithBlock:(TestBlock)testBlock num1:(int *)num1 num2:(int *)num2;

Doc Block fucked around with this message at 18:18 on Jul 27, 2014

PiCroft
Jun 11, 2010

I'm sorry, did I break all your shit? I didn't know it was yours

Doc Block posted:

What are you expecting to happen?

In this case, nothing except for the log to output the messages in the correct order, which is the message in the performWithBlock(), then the message in the block itself. If I had forgotten to add the block call (which I did at first) then it would print the message in peformWithBlock but the block would be ignored.

e: per your edit, yeah I missed that. Thanks for pointing it out.

e2: I read on stack exchange (can't find the topic anymore) that you should put block parameters last in the list. I can't remember if they said it was a requirement or just a convention but that's why I put the block last and the ints first.

PiCroft fucked around with this message at 18:24 on Jul 27, 2014

Doc Block
Apr 15, 2003
Fun Shoe
See both of my edits.

If you're just printing the numbers, there's no need to pass them as pointers.

code:
#import <Foundation/Foundation.h>

typedef void (^TestBlock)(int, int);

@interface TestClass : NSObject

- (void)performWithBlock:(TestBlock)testBlock num1:(int)num1 num2:(int)num2;

@end

@implementation TestClass

- (void)performWithBlock:(TestBlock)testBlock num1:(int)num1 num2:(int)num2
{
	NSLog(@"%s", __FUNCTION__);
	NSLog(@"a: %d", num1);
	NSLog(@"b: %d", num2);
	testBlock(num1 + 1, num2 + 1);
}

@end

int main(int argc, char **argv)
{
	@autoreleasepool {

		int a = 10;
		int b = 20;

		TestClass *test = [[TestClass alloc] init];
		[test performWithBlock:^(int _a, int _b) {
			NSLog(@"%s", __FUNCTION__);
			NSLog(@"_a: %d", _a);
			NSLog(@"_b: %d", _b);
		}
		num1:a num2:b];
	}

	return EXIT_SUCCESS;
}

Doc Block fucked around with this message at 18:31 on Jul 27, 2014

Doc Block
Apr 15, 2003
Fun Shoe

PiCroft posted:

e2: I read on stack exchange (can't find the topic anymore) that you should put block parameters last in the list. I can't remember if they said it was a requirement or just a convention but that's why I put the block last and the ints first.

It's not required, just that it can make the method call cleaner.

But then you should rename the method. Maybe -performTestWithNum1:(int)num1 num2:(num2) testBlock:(TestBlock)testBlock

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

PiCroft posted:

e2: I read on stack exchange (can't find the topic anymore) that you should put block parameters last in the list. I can't remember if they said it was a requirement or just a convention but that's why I put the block last and the ints first.

Passing block-typed parameters at the end is just a convention. Swift has a bit of syntactic sugar for "trailing blocks" that makes this nicer, but in general the idea of putting a block parameter at the end is that it's more aesthetic when the block itself is inline with the call.

PiCroft
Jun 11, 2010

I'm sorry, did I break all your shit? I didn't know it was yours

I understand guys, thanks for the help :)

duck pond
Sep 13, 2007

hiya folks, i'm stumbling in the dark here and there's a lot of conflicting information out around -

i was wondering if somebody could perhaps give me the straight dope on how to programmatically add constraints to a view so as to make it always match the frame of its parent view?

duck pond
Sep 13, 2007

Also, did the interactive transitions api just change in iOS 8 β 4? I can't get my transitions working again for the life of me...

Adbot
ADBOT LOVES YOU

Doctor w-rw-rw-
Jun 24, 2008
Can someone confirm that with C11 (not C++11, but C11) enabled*, that this code errors with "Documentation error!"?

C code:
#if __has_extension(c_generic_selections)
    #if __has_feature(c_generic_selections)
        #error Documentation error!
    #endif
#else
    #error Not supported
#endif
It would seem to me that the Clang documentation erroneously assumes that "__has_feature(c_generic_selections)" works.

*Xcode project settings: C Language Dialect, select c11 or gnu11

EDIT: Nope, build system just refused to pass along the build flag that enabled gnu11 for some reason, ignore me.

Doctor w-rw-rw- fucked around with this message at 22:45 on Jul 30, 2014

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