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
LP0 ON FIRE
Jan 25, 2006

beep boop
I've been asked to check out different game engines out there that would make porting to different platforms not such a hard task. We'd be starting out making something for iOS. Any suggestions for either 2D or 3D? So far I've looked at Big World Technology, Panda 3D, and Esenthel.

Adbot
ADBOT LOVES YOU

LP0 ON FIRE
Jan 25, 2006

beep boop

wdarkk posted:

Unity seems popular.

Thanks that definitely looks dependable. Can't really use Unity Pro and for iOS unless we pay the $3,000 fee right? Unity free I don't even believe you're allowed to publish anything to the app store.

LP0 ON FIRE
Jan 25, 2006

beep boop
Cocos2D question.. I'm still learning and discovering all the great things about it. I'm very curious about a method of collision detection in conjunction with being used with Tiled. I noticed that you could give layers properties just like you can with tiles.

I was following a tutorial a while ago that showed a method of detecting a collision by looking up the properties of a certain tile: http://www.raywenderlich.com/1186/collisions-and-collectables-how-to-make-a-tile-based-game-with-cocos2d-part-2

But I'd like to also have a way of testing a player colliding into ANY tile on a particular layer in Tiled. In other words, I just want to make a property of that layer in tiled and see if I'm colliding with any of the tiles, but only on that layer.

Inside a method I have this code:
code:
CGPoint tileCoord = [self tileCoordForPosition:position];

int tileGid = [invisiblePropertiesLayer tileGIDAt:tileCoord];

if(tileGid){
    NSDictionary *properties = [theMap propertiesForGID:tileGid];

    if(properties){
        NSString *collision = [properties valueForKey:@"collidable"];
        if(collision && [collision compare:@"true"] == NSOrderedSame) {
            return;
        }
    }
}
Can I just make some small changes to that to do what I want? Thanks.

LP0 ON FIRE
Jan 25, 2006

beep boop
Thanks pokeyman. It looks like I can ONLY travel to these tiles on the collidable layer, but it's probably something on my end messing that up. This should still help, thanks!

edit: It just had to be the opposite. if(tileGid)

LP0 ON FIRE fucked around with this message at 16:55 on Apr 7, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
Cocos2D iPhone question:

Say if you wanted to have a sprite move to a touch location, but on it's way there are obstacles that should block the player. On it's way doing this action, is there anyway to check for obstacles to stop the action without timers that constantly check collision?

On the bottom post on this forum, it looks like it's the way this guy does it: http://www.cocos2d-iphone.org/forum/topic/12373

e:Please let me know if there's a better way, but I think this might have to do something with making some kind of pre-check along the path that the sprite is going to move to see if there's any obstacles on the way. I was just hoping there was something built in..

LP0 ON FIRE fucked around with this message at 19:18 on Apr 8, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
Thanks... I know this will be simple to a lot of people but I'm sure this will break my brain once I get into moving objects!

LP0 ON FIRE
Jan 25, 2006

beep boop

sevenflow posted:

There's some useful information on the web (http://stackoverflow.com/questions/1354472/detect-if-line-segment-intersects-square should work in Objective-C), but basically you just need to check if a line (representing the path) intersects a rectangle (representing the obstacle) before you start moving. It's a little more complicated if the objects move but the basic idea is the same.

Thanks for your help. I did some thinking about this over the weekend before I ever went ahead and started coding, and I think (at least in my case) it will be a little bit different than this process even for still objects. My player sprite is 3 blocks wide and 2 high. So more than a line will need to test for collision.



Say if the red blocks are my player, the blue block was a block that the player could collide with and the bottom left corner of the green checkerboard is the touch location. If a line was drawn diagonally from the center point of the player to the bottom left of the green checkerboard block, it would never cross over the blue block that it should collide with, right? So this means that part of the player could cross over the blue block which shouldn't happen. The player has smooth movement and can stop on any pixel, and not rounded to the nearest block. So I'm thinking the test needs to be checking a path the size of the player, checking every square along the way if there's any collidable blocks. Thats for still tiles that are obstacles only. You think I'm on the right track with that?

edit: Even better... I think CGRectIntersectsRect will solve the issue even more. Still just thinking it out but for some reason I think this will be a smart choice.

LP0 ON FIRE fucked around with this message at 21:20 on Apr 11, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop

Gordon Cole posted:

So this isn't specific to Apple development, but I'm working on a music-related app that renders a musical score. That of course means I need to draw lots of musical symbols, so I've been looking into music fonts. There's one called Petrucci that seems to have been originally created long ago to be the default font for Finale. I'd love to use it, but I'm totally clueless about licensing issues.

I wouldn't risk it. You should take a look into MusiQwik fonts. Will these work for you? Check out the OFL License on this link below. I'm pretty sure you would freely be able to use this in commercially sold software.

http://cg.scs.carleton.ca/~luc/allgeyer/allgeyer.html

LP0 ON FIRE
Jan 25, 2006

beep boop

sevenflow posted:

The only issue with this is that you won't be able to really project before hand, you'll have to test on every frame. Which is fine, it's a really cheap operation.

I don't understand why I'd need to test every frame? Can't I just use a for loop before the player starts moving? I'd much rather use timers in a lot of cases, but yeah I didn't know how much that would slow down things.

Here I do a test of where the rects would be by overriding the draw method in cocos2D:



There, they are 32 pixels apart from their centers, but I may want to do as little as 8 to get rid of those hard edges and make it more accurate. I might figure out a way to avoid redundant checking. But yes, this has all been very daunting and I think I'd just like to check per frame. This also means that anything else that needs to check for collision (such as enemies hitting walls) would need to check every frame.

xzzy posted:

Wouldn't that be a preferred design anyway? It saves a lot of re-writing if the game ever has to test for collisions against objects that are moving.

Exactly. Again the only thing I've been afraid of is retaining speed.

sevenflow posted:

You could also go with something like Box2D for collision detection, even if you're not using it for physics simulation. It has a lot of nice functionality built in for testing these types of things (eg. it'll let you project the path of an object and let you know all the objects it will collide with on the way.)

That's nice to know, but how much would it slow it down compared to checking per frame?

So I guess what I'd really like to get peoples opinions on is what should I use:

-A path of rects to precheck collision before movement
-Check collision per frame (I think I'd prefer this, but speed? Also could I get some idea of how this is done)
-Use Box 2D (Unnecessary?)

LP0 ON FIRE
Jan 25, 2006

beep boop
Thanks. I'm going to see how a per-frame basis works out and how much I can push it.

Does anyone know if ccTime checks on a per frame? Even after looking it up on the Cocos2D site, I can't really find out much info about it.

Just calling this in init: [self schedule:@selector(update:)];

And this as a method

code:
- (void)update:(ccTime)dt {
	NSLog(@"test");
}

LP0 ON FIRE
Jan 25, 2006

beep boop
So how can you have a method checked every frame?

edit: Also found a really extensive tutorial on box2D that I'm going to read up on.
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone

LP0 ON FIRE fucked around with this message at 20:33 on Apr 15, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
In Flash, you can normalize a velocity by using this: vel.normalize(speed). But in Objective C or Cocos2d, what is built in? I know of ccpNormalize(vel), but I don't understand how I can make it work like the Flash one. I guess if I knew more about normalization I'd just do the math, but is there anything built in?

edit: I get it now I think according to this http://www.cocos2d-iphone.org/forum/topic/759

LP0 ON FIRE fucked around with this message at 20:34 on Apr 19, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
That's what was stumping me, I thought I was doing that and it resulted in acting crazy.
I ended up doing this:

code:
//get a direction
CGPoint dir = ccpNormalize(heroVelocity);
		
//then use ccpMult to the direction with a speed
heroVelocity = ccpMult(dir, heroSpeed);

LP0 ON FIRE
Jan 25, 2006

beep boop
I want an NSMutableArray as a property made in a class to use in another class, is this okay?

.h
code:
@interface HeroClass : CCLayer {
	NSMutableArray *_heroCollisPushPoints;
}

@property(nonatomic, assign) NSMutableArray *heroCollisPushPoints; // notice i assign not retain
.m
code:
#import "HeroClass.h"

@implementation HeroClass

@synthesize heroCollisPushPoints = _heroCollisPushPoints;

-(id) init{
    self = [super init];
    if (!self) {
        return nil;
    }
		
	_heroCollisPushPoints = [[NSMutableArray alloc] init]; //alloc it here
	
	[_heroCollisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( 16, 16)] atIndex:0];
	[_heroCollisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( 16,  0)] atIndex:1];
	[_heroCollisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( 16,-16)] atIndex:2];
	[_heroCollisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( 0,  16)] atIndex:3];
	[_heroCollisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake(-16, 16)] atIndex:4];
	return self;
}

- (void) dealloc{
	[_heroCollisPushPoints release]; //release it here
	[super dealloc];
}

@end

LP0 ON FIRE
Jan 25, 2006

beep boop

samiamwork posted:

I'm not really sure what you mean by that, but that code won't work. If you assign a new value to the heroCollisPushPoints property you'll leak your original array and when you dealloc the object you'll crash when you over-release the second array you were given. If you don't want to allow other objects to give heroCollisPushPoints a new value then you probably want readonly.

Thanks for your insight. So if I'm making the right sense out of what you're saying, I should set that property to readonly instead of assign and get rid of the dealloc method since my other class will be deallocing the class object, which should dealloc that mutable array along with it.

LP0 ON FIRE fucked around with this message at 06:56 on May 1, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop

samiamwork posted:

It depends on what you're trying to do, but if both objects need it then both should retain it (unless it would cause a retain cycle). So keep the dealloc but also make sure your other object retains the array and releases it when it's done with it.

I've put back the dealloc in the other class of my hero thats used in my level class. It makes sense now because the array is alloc'd.

In my level class my hero class object initialized like this: hero = [[HeroClass alloc] init];
It's later deallocated, but I never allocated the array in the level class. I just reference it like this:

NSValue *val = [hero.heroCollisPushPoints objectAtIndex:i];

Which seems to be working okay. I can actually change this array with replaceObjectAtIndex without any noticeable issues. When HeroClass is deallocated, heroCollisPushPoints should be dealt with too right?

LP0 ON FIRE
Jan 25, 2006

beep boop

kitten smoothie posted:

I've made about $350 on a very niche app since releasing it 3 months ago. Honestly I'm really surprised it's made that much, and I continue to get a download or two a day usually. For what basically amounted to a weekend project, that doesn't seem like a terribly bad return on my time.

I have a few more ideas with wider appeal, so I hope I will have better results later this summer when I time to get those out the door.

Congratulations! It's inspiring to hear this.

That said, I'm trying to learn more about key-value coding. I've been wanting to accomplish a specific idea I have, but I don't know if it's the best approach or even possible.

Take this method call from another class for instance:
int blocksCollidableGID = [debugZoneLayer getGID:tileCoord forKey:@"blocksCollidable"];

Is it possible to take the key when that method is called, and have it equal the name of a Cocos2D CCTMXLayer? What would the method look like?

So to be more specific, when the method is called, it would know that I'm trying to get the tile coordinate of CCTMXLayer blocksCollidable.

LP0 ON FIRE fucked around with this message at 17:51 on May 4, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop

pokeyman posted:

I'm sure you've had a look at the Key-Value Coding Programming Guide. Specifically, I mean the part where it discusses resolving key paths to values. If a method with the same name as the key is implemented, it gets called and its return value is the value for the key path. Otherwise, if an instance variable with the same name exists, its value is returned.

So if you want [layer valueForKey:@"collidableCoordinate"] to give you tile coordinates, implement -collidableCoordinate on the class of layer. If it's not a class you control, implement it in a category (with a prefix, like -nog_collidableCoordinate). Also keep in mind that the return value from -valueForKey: will be boxed (i.e. an NSValue or subclass as opposed to an int/float/struct), so you'll likely need to unbox it first.

Thanks pokeyman. I still haven't got to this stage yet because I gave up on subclassing my sprite methods for a bit to make progress in other places, but this will help so much and makes a ton of sense to use it.



I have yet another problem if anyone wants to help. Right now I can't get it to run on my device without immediately crashing. It worked with a much older version. I made a question on Stack Overflow if anyone wants to see more details: http://stackoverflow.com/questions/6049827/cocos2d-crashing-on-iphone-immediately-but-not-in-simulator

But basically on the simulator, I get a message in the console "CCSpriteFrameCache: Trying to use file 'heroTestSheet.png' as texture" but everything seems to work fine. Putting it on to a device just gives me a white screen until it crashes and the console gives me a report. I saw this a lot of time has to do with filenames in my resources verses my code have different capital letters, but I've looked over all of them and even revealed them in the Finder to make sure. :confused:

Starting to think it has to do with how I'm coding the sprite class and I did something wrong.

LP0 ON FIRE fucked around with this message at 18:36 on May 19, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop

Doc Block posted:

In the Cocos2D debug output it says that it couldn't find one of the frames you specified. Open the plist in a plist editor and see what is actually in there.

Also, what are you using to generate the sprite atlases in the first place?

In the plist there is heroFrame1.png and heroFrame2.png. Which means it's using the plist to make those from the texture heroTestSheet.png, right?

Here's a shot:


I'm using Zwoptex.

edit: I just wanted to add that I also put this in my zone class that adds the map and the sprite in init:

hero = [[HeroClass alloc] init];
[self addChild:hero.heroSpriteSheet];

I didn't do addChild to anything else for the hero class which I hope is okay and makes sense.

LP0 ON FIRE fucked around with this message at 19:37 on May 19, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop

ynohtna posted:

Stick a breakpoint on the line which calls [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"heroTestSheet.plist"];

Then run your App on the device and step into the code line by line verifying that everything is working as you'd expect until you find the point at which Cocos is giving up on loading/creating the texture. That'll give you (and us) a big hint as to what's failing.

Cocos isn't a particularly fat framework and is pretty well structured & commented so you shouldn't be afraid to delve into its code to discover just what it's doing when expectations are being confounded.

Thanks for the suggestion. So it stopped on CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:texturePath]; in the addSpriteFramesWithFile:(NSString*)plist method in CCSpriteFrameCache.m. Is a .png a valid texture? Still don't get what's wrong, but I guess it can't get the correct path or something?

LP0 ON FIRE
Jan 25, 2006

beep boop
Figured it out.. it's so stupid, but it was just the heroTestSheet.png it was trying to use was somehow invalid. I exported in an older photoshop, but I'm not really positive what settings it had. I exported it again from a newer photoshop without any color mange settings, and now it works fine! I stepped through the Cocos2D methods when I was debugging, and getting the message "CCSpriteFrameCache: Trying to use file 'heroTestSheet.png' as texture" in the console is totally fine, it's just saying it's doing something different to assign the filename.

LP0 ON FIRE
Jan 25, 2006

beep boop

Doc Block posted:

Wait... why are you putting together a sprite sheet in Zwoptex and then messing with it in Photoshop? Glad you figured it out at least.

The sprite sheet was already one graphic. I just want the plist. This way I can still go back into photoshop and make any changes I need. That's okay, right? Maybe that doesn't make sense, I don't know. Probably doesn't, but I'll learn.

Anyway, I'm trying to make this run fast on older iPhone models, 3G and prior. It runs at a full 60 fps on iPhone 4, but around 30 on 3G. I've seen an automatic way to ignore tile rendering outside of a screen area, but I can't find the page that showed how to do this. Does anyone know what I'm referring to?

LP0 ON FIRE
Jan 25, 2006

beep boop

Doc Block posted:

I don't know if Zwoptex does, but TextureTool can be called from the command line, and you can make a custom build step in Xcode that will call TextureTool to assemble the sprite sheet as part of the app's build process. I don't recommend opening up the sprite sheet and modifying it directly.

Also, keep in mind that pre-3GS devices have a max texture size of 1024x1024 and only have 128MB RAM. They also make up a pretty small segment of the iOS market.

Thanks for the info. So a work flow of making a sprite sheet with an automated plist, is usually making separate files for each sprite, and then assembling them together in sprite sheet tool like Zwoptex to make the sheet? The only thing that catches me off guard about this is now someone is making graphics in a bunch of separate files, which seems disorganized and confusing. Maybe I'm just crazy, but is this the way it's usually done? I'll definitely look into TextureTool TexturePacker since a lot of people are using that.

Right now all I'm using is a test player sprite sheet thats 128x64 and split up into two 64x64's, and a texture atlas for the tiles that's only 320x320, that's split up into 16x16's. My background is just a gradient background rendered from code. I should have mentioned, but I'm also testing this on iPad 1 and 2 which are displaying a lot more tiles. On the iPad 1, it runs 30 fps, much like the iPhone 3G. On the iPad 2, it runs 60 fps, much like the iPhone 4.

It's good to know there's very little market for pre 3GS devices, but I'm curious if there was something I could do to give a significant boost in performance, or if that's what usually happens to pre-3GS devices and Cocos2D.

LP0 ON FIRE fucked around with this message at 06:22 on May 24, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
So I've successfully displayed a 100+ CCSprites using Cocos2D running around 60fps on an iPad 2, all with independent behaviors, but all created from the same sprite class. Though it's running nicely, I can't check with leaks if it is leaking because it doesn't run when I try to use it. It just loads for about 10 seconds with the white screen and then quits out. Otherwise, without leaks in the simulator it works fine. Eventually I'll have to figure out how to fix this, but until then, I want to know if the way I'm coding this is okay in terms of not leaking, etc.

First off, in my main CCLayer class that makes the zone and places the sprites, I import my sprite class in the header, pointers to arrays, and stuff:

code:
#import "HummingClass.h"
@class HummingClass;

@interface DebugZoneLayer : CCLayer {
	
	HeroControl *heroControl;
	
	HeroClass *hero;
	
	NSMutableArray *hummingBirds;
	NSMutableArray *hummingBirdLabels;
	
	CCLabelTTF *label;
	
	CCTMXTiledMap *theMap;
	CCTMXLayer *blocksCollidable;
	CCTMXLayer *blocksCollidable2;
	CCTMXLayer *invisiblePropertiesLayer;	
}

@property(nonatomic, retain) NSMutableArray *hummingBirds;
@property(nonatomic, retain) NSMutableArray *hummingBirdLabels;
*Note that there's other properties defined, but I'm really just concerned with the humming birds in this post.

In .m I synthesize hummingBirds and hummingBirdLabels. What I'm doing in init I think is the more major thing that I'm concerned with, because I don't know if it's okay. And I know it looks weird, partly because this is just a test and I haven't made the bridge yet between this and Tiled so it can count and pass the locations of all these sprites. Right now, it's just using one location and shifting the x coordinate for each sprite. I changed up the code a bit because it did display a rectangular matrix of sprites to test how many I could use on screen at once, but I didn't want to make this post even more confusing. Sorry I'm not using code tags here, just want to show the important stuff in bold:


hummingBirds = [[NSMutableArray alloc] initWithCapacity: hummingBirdsMax];
hummingBirdLabels = [[NSMutableArray alloc] initWithCapacity: hummingBirdsMax];


for(int i=0; i<hummingBirdsMax; ++i){

HummingClass *humming = [[HummingClass alloc] init];

[hummingBirds insertObject:humming.hummingSprite atIndex:i];



startPoint = [objects objectNamed:@"HummingStart"];
x = [[startPoint valueForKey:@"x"] intValue];
y = [[startPoint valueForKey:@"y"] intValue];


CCSprite *tempSp;

tempSp = [hummingBirds objectAtIndex:i];


tempSp.position = ccp(x+(i*100),y);

[self addChild:humming.hummingSpriteSheet];


CCLabelTTF *hummingBirdLabel;

hummingBirdLabel = [CCLabelTTF labelWithString:@" " fontName:@"Arial" fontSize:15];
hummingBirdLabel.color = ccc3(0,0,0);
hummingBirdLabel.position = ccp(tempSp.position.x, tempSp.position.y+26);
[self addChild:hummingBirdLabel z:10];

[hummingBirdLabels insertObject:hummingBirdLabel atIndex:i];

deactivateLabelToggle[i] = 0;

deactivateLabelCounter[i] = 0;

[humming release];

}



I expect to get a ton of grief for this, but unfortunately I'm still a tremendous newbie with this kind of stuff. In the loop, I'm allocating humming over and over but releasing it each time. I put each humming bird into an array index. This is how I reference it later by making temporary pointer to a CCSprite and then making that equal an array index. I release the arrays in dealloc. So I'm wondering if thats okay.

The other thing I'm wondering about is that I'm doing [self addChild:humming.hummingSpriteSheet]; every time in the loop which I found was necessary to see each one of these.

LP0 ON FIRE
Jan 25, 2006

beep boop
edit: never mind

LP0 ON FIRE fucked around with this message at 09:16 on Jun 17, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
I hate warnings, and I have this one that's been bugging me on a conditional in a class that's subclassed:

if( [[point child] isEqual:node] ) {

"No '-child' method found"

Any easy way to get rid of it?

LP0 ON FIRE
Jan 25, 2006

beep boop

Carthag posted:

Are you including the subclass headers where you're using -child?

I'm including the header of the subclass in the class I'm using it with if that's what you're asking.

LP0 ON FIRE
Jan 25, 2006

beep boop

rjmccall posted:

Is point a Superclass* with the child method only declared on a subclass? Because you need to cast down to the subclass to make that type-check.

I'm using Cocos2D, and I just found out it's apparently unavoidable, unless you edit the extensions in some way. Quoted from another forum, if this makes any sense "Cocos2d defines CGPointObject in CCParallaxNode.m, and although we're extending that class there's no handy way to let the compiler know about CGPointObject in our file."

LP0 ON FIRE
Jan 25, 2006

beep boop
There's a pretty cool blog post about how to format phone numbers and that are local aware here: http://the-lost-beauty.blogspot.com/2010/01/locale-sensitive-phone-number.html

Parentheses and dashes are not allowed in NSNumberFormatter, so I don't think that would help you.

LP0 ON FIRE fucked around with this message at 18:38 on Jun 21, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
Kind of urgent.. I had an iPad enterprise application come back to haunt me from 6 months ago, exactly to this day. One of their iPads no longer launches the application because the provision expired, which according to what I thought, it shouldn't. The other devices are working fine, so something must have happened wrong along the way.

Since they're overseas, and they need it for a presentation tomorrow, I decided to make an online link download with a plist and application file in hopes it will work. I have an iPad here to test it on. This iPad however is not added to their device list on their development account, so I don't expect it to work. Yet, I DO expect it to download. After touching the link on iPad's Safari, and hitting OK on the confirmation box, the app looks like it's going to install, but it's just stuck on "Loading..."

It's been like this well over 10 minutes. So even though the app is 1.5 GB, I'd expect it to start showing a progress bar by now. I'm afraid it's something wrong with my plist, but everything looks correct. Maybe I left out a required field?

Over seas, this same exact thing is happening to their iPad when I gave them the download link.

*got rid of code to save you all some vertical space*

edit: Okay, I finally saw it jump to 1 pixels in width in the progress bar, and then 10 minutes later, 2 pixels, so it's doing something. But it still says "Loading..."

edit 2: Boss just emailed me... success. I was just freaking out. Still don't know how their provision expired, but oh well.

LP0 ON FIRE fucked around with this message at 03:35 on Sep 17, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
I have a very curious question: When should I NOT use isEqualToString? I think I've been having intermittent issues when comparing an NSString with another NSString using isEqualToString, so I've stopped doing that and now use just a simple comparison like:

code:
NSString *teh = @"this";

NSString *whatev = @"this";

if(teh == whatev){
//stuff
}
It's now making me think I should only use isEqualToString I'm comparing an NSString with something that is not an NSString, but just some sort of string.

LP0 ON FIRE
Jan 25, 2006

beep boop

Carthag posted:

I think the reason why the former might work in some cases is an effect of the Cocoa implementation of NSString, that is, immutable NSStrings with the same contents aren't allocated multiple times will be the same instance behind the scenes. This is not something you should count on.

Oh god. :psyduck: I've been changing the NSString values over the course of the program, and they are immutable? THAT'S the problem I think I'm having. Can I use NSMutableString with isEqualToString and everything should be okay, assuming my program is written correctly?


Toady posted:

What intermittent issues are you having? You use -isEqualToString: when you know both objects are strings. As the documentation states, it's a little faster than -isEqual:, perhaps due to lack of type-checking.

You compare pointers when you want to know if they point to the same instance (i.e., an identity comparison). You use equality methods to compare the values of the objects, which may not be the same instance but still be considered equal. The difference between identity and equality in Cocoa is like a pair of dollar bills. They're equal in that they both represent $1 in currency, but they are not identical, because they have unique serial numbers.

I set game character "states" in a way that makes it easy to identify what state they are in English, at a glance. If I just thought about this a little more than I'd realize I'm just comparing pointers. The intermittent problems I would have would be the character states would never change even though it was calling the methods that should do it when an event triggers a state change.

LP0 ON FIRE
Jan 25, 2006

beep boop

Carthag posted:

Well that depends on what you mean by changing the strings. Since they're immutable (and thus unchangeable), I assume you're having the pointers point to new strings? That would work, for instance if they're @properties on some object, and you go object.property = @"newstring"; then that will indeed change the property and have the string be the new string object, so next time you check object.property, you will get @"newstring" back as expected.

NSMutableString (which can indeed use isEqualToString, it's a subclass of NSString after all) is for when you want to change a string, but maintain the same instance. NSString is for when you just discard the old string and replace it with a new one.

You should probably read through the Cocoa Core Competencies: http://developer.apple.com/library/ios/#DOCUMENTATION/General/Conceptual/DevPedia-CocoaCore/ObjectMutability.html

Thanks for everyone's input. I stayed late last night and went through my entire project, replacing some NSStrings to NSMutableStrings, and changing every string comparison to isEqualToString. Works flawlessly so far.

I'll check out that documentation, since I don't seem to know everything about mutability.

LP0 ON FIRE
Jan 25, 2006

beep boop
Wow.. quite a discussion about isEqualToString we've got going here. I'll check back to see if everyone finally comes to an agreement to what is, and what is not. Most of it is over my head to debate anything, but it is interesting.

Is anyone familiar with Cocos2D for iOS, particularly passing parameters when calling methods with actions? I've done it with NSNumber and retaining the value and releasing it when the method is called, but I'm totally confused on how to go about doing this when passing a CGPoint.

Just with guessing, this is what I currently have:

code:
	CGPoint spriteCoord = saveStation.sprite.position;

	NSLog(@"spriteCoord x = %f", spriteCoord.x);
	NSLog(@"spriteCoord y = %f", spriteCoord.y);

        // if NSLogging here, spriteCoord looks good
		


	id a1=[CCMoveTo actionWithDuration:.4 position:ccp(saveStation.sprite.position.x,saveStation.sprite.position.y)];

	id actionSaveStationReaction = [CCCallFuncND actionWithTarget:self selector:@selector(saveStationReaction : data:) data:&spriteCoord];
		
	[hero.heroSprite runAction:[CCSequence actions:a1, actionSaveStationReaction, nil]];

The method:

code:
-(void) saveStationReaction:(id)sender data:(CGPoint)data {
	
	CGPoint spriteCoord = data;
	
	NSLog(@"spriteCoord x = %f", spriteCoord.x);
	NSLog(@"spriteCoord y = %f", spriteCoord.y);

        // spriteCoord x and y are 0.. ???
	
}
When I called saveStationReaction, the CGPoint does not seem to pass.

edit: I just noticed I wouldn't even have to pass the spriteCoord, because I can always get the value from saveStation.sprite.position anywhere, :downs: but I'm still curious on how to do this.

LP0 ON FIRE fucked around with this message at 19:12 on Sep 27, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
For some reason I cannot read new values written into a plist file. I'm just doing a simple NSLog. I deleted an int value from the plist that I could NSLog just fine, and even though I saved the plist I can still have it show up in the log. It seems to me the plist is simply not saving correctly, or I'm doing something wrong I'm not realizing. Can anyone help me out with this? Thanks.

edit: I simply renamed the plist file and put a "2" at the end and changed the filename in the code as well, and everything is working fine, but it sort of freaks me out. Some kind of compiler bug?

edit 2: Still having plist problems I guess. Even though I know I changed a value in this file, and that is reflected in the game, I take a look a look at the plist even after closing it and it shows nothing has changed. What gives? Actually I'm going nuts, doesn't work like this, and don't know why I thought it did.

LP0 ON FIRE fucked around with this message at 23:03 on Oct 11, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
I've been trying to add a new enterprise build to an iPad from Xcode for testing, and I'm getting a CodSign error that's driving me crazy from wasting hours on this: "code signing is required for product type 'Application' in SDK 'iOS 5.0'"

I've set all my code signing identities to the name of the certificate downloaded from the portal. The provision is associated with it. I deleted the provision on the device and resynced and build but I'm still getting the error. On the portal it says under certificates "We are performing maintenance on the WWDR Certification Authority. All certificate requests will remain in pending status until maintenance is complete, at which time all pending requests will be automatically processed." which I'm not sure if that's causing the problem.

In my info.plist i changed the bundle identifier to what is shown in the portal in App ID's under the description column with the * symbol.

LP0 ON FIRE
Jan 25, 2006

beep boop
Using Cocos2D, does anyone know a good approach to moving a CCParticleSystem emitter along with a moving layer? For instance, may game may scroll while an emitter is positioned to a specific location, but how do you access X number of emitters to scroll with the rest of the game? It would be nice to just to access the entire CCParticleSystem and change the x & y coords when the layer moves.

I place a particle emitter like this:

code:
       
CCParticleSystem *emitter = [CCParticleSystemQuad particleWithFile:@"ringExplosion.plist"];
[emitter setPosition:ccp(tempSp.position.x, tempSp.position.y)];
[self addChild:emitter z:11];
emitter.autoRemoveOnFinish = YES;
I move the entire layer like this:

self.position = [ScreenPos setCenterOfScreen:hero.heroSprite.position withMapWidth:theMap.mapSize.width withMapHeight:theMap.mapSize.height withTileWidth:theMap.tileSize.width withTileHeight:theMap.tileSize.height];

edit: I was stuck on this forever, so I felt I needed to post this, then I found out about positionType! Needed to add emitter.positionType = kCCPositionTypeRelative;

LP0 ON FIRE fucked around with this message at 22:18 on Nov 8, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
I have a mixed objective-c/html5/javascript issue if anyone cares to check out. I wanted to view an html file with a canvas element and javascript in a UIWebView, which I have done, but can't seem to get any touch interaction to occur with body.onmousedown = function (event). I pulled an example from http://html5demos.com/canvas-grad (see source) and changed onmousemove to onmousedown. The file by itself works on my computer in Safari but not on the iPad simulator. I can see it in the simulator, but touching it does nothing.

Inside the UIWebView, I checked to see if other sites worked to see if touches were being ignored entirely, but it that wasn't the case.

Just in case, I'll paste what I have inside my viewDidLoad for my UIWebView:

code:
    NSURL * resourcePathURL = [[NSBundle mainBundle] resourceURL];
    if(resourcePathURL)
    {
        NSURL * urlToLoad = [resourcePathURL URLByAppendingPathComponent: @"radialGradient.html"];
        if(urlToLoad)
        {
            NSURLRequest * req = [NSURLRequest requestWithURL: urlToLoad];
            [webView loadRequest: req];
        }
    }

LP0 ON FIRE fucked around with this message at 22:10 on Nov 14, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop

pokeyman posted:

Hit up the Safari Web Content Guide for some info on events in iOS. I'm guessing that your onmousemove event isn't firing. You can try to make it work, or look into handling the touch events.

I understand why onmousemove wouldn't fire with a touch device, and that's why I changed it to onmousedown. Thanks for the link, I'll check it out!

edit: Someone found the answer for me on stackoverflow. I had to use canvas.onmousedown instead of body.onmousedown.

edit 2: Actually, learning about the iOS touch events for Javascript really made a huge difference. I didn't suspect they made anything for this, and was kind of strange to see at first. I also had to capture what touch I wanted to get the coordinates from. Pretty nifty to see it in the Javascript.

code:
            canvas.ontouchmove = function (event) {
                event.preventDefault(); // prevent page from scrolling with drag
                
                if(event.touches.length == 1){
                    var touch = event.touches[0]; //only get first touch if there's one touch
                }
                
                x = touch.pageX;
                y = touch.pageY;

                //and so on...

            };

LP0 ON FIRE fucked around with this message at 20:21 on Nov 17, 2011

Adbot
ADBOT LOVES YOU

LP0 ON FIRE
Jan 25, 2006

beep boop
With a game I'm working on I'm not positive how much NSMutableArray's I'll have in the end. I'm trying to keep it simple, and performance is key. I just wanted to get some advice on how vital it is to use initWithCapacity. Is it something that could really give you a lot of overhead in the end, knowing how long these arrays should be?

I know it sounds very elementary, but why would someone do this, unless they're using some ancient computer? Maybe I just don't understand the reasoning behind it.

LP0 ON FIRE fucked around with this message at 22:30 on Nov 17, 2011

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