So, that's an in-development shot. That's the desktop version, running at its full-resolution.
I ran into an issue that I hadn't expected to be as difficult as it ended up being: scoreboards. The goal counts were easy, because I just wrote the value to a string and used is a filename, like so:
NSString *goalString = [NSString StringWithFormat:@"%d.png", goalCount];
CCSprite *goalGraphic = [CCSprite SpriteWithFile:@"0.png"];
// and then, to update with 2 current goals scored
goalGraphic.texture = [[CCTextureCache sharedTextureCache] addImage:goalString];
As you can see, I create a number to hold the amount of goals scored. And then, I write the value to a string and follow it with ".png". The string, in entirety, is now "2.png". All of my numbers are simply 0.png to 9.png, so it allows me to update via code and run it live.
The biggest piece of useful information here to any newbie cocos2d programmer is this: in order to update a sprite's actual graphics you have to change the texture, not the sprite. So, for instance, you cannot update the sprite to show two goals scored like this:
goalGraphic = [CCSprite SpriteWithFile:@"2.png"]; //WRONG
Maybe it's obvious to others, but this was something I fought with until I looked it up and found a few answers at Stack Overflow.
However, that wasn't the real asshat issue I was dealing with. The biggie was the scoreboard counting dings and dents on trucks.
Because I'm working with bitmaps instead of an actual font, I had to find a way to read individual numbers from my integer containing scoring data.
// updatePrize takes the score, turns it into readable piaces, and updates the scoring images -(void) updatePrize { prizeString = [NSString stringWithFormat:@"%d", score]; // the string containing the score in characters vs. numbers char fileName; // a char for the filename, as I'll be grabbing individual characters from the string int lacking = 5 - (int)prizeString.length; // the tricky piece that "pushes" the numbers rightward // the work begins for (int i = 0; i < (int)prizeString.length; i++) { NSLog(@"%@", prizeString); // simply used as a check to make sure I'm actually pulling the data, tb deleted // the next two lines are clear, we grab the number stored as a character and then assign a texture name fileName = [prizeString characterAtIndex:i]; goalString = [NSString stringWithFormat:@"%c.png", fileName]; // now, using 'lacking' we pad the zeroes and then start reassigning textures prizeBoard[i + lacking].texture = [[CCTextureCache sharedTextureCache] addImage:goalString]; [prizeBoard[i + lacking].texture setAliasTexParameters]; } }
So, there's a bit going on in that mess. I added a bunch of comments to give a picture of what's happening here. Anyway, my problem came down to:
Dividing the score into readable numbers
Padding for zeroes, until the number gets large enough
With the first, I couldn't find a way to easily split an integer. So, I'd already started writing my goals as strings, I decided to do the same with the score. After this, I needed a way to split it, and I just started grabbing individual characters off of the string.
You'll notice I have string called "goalString" that I'm using in the scoring update, I reused it from when I worked with the goals, so as to not create another string. Yeah, I'll probably change some stuff later, but ... I'm over it.
As for padding zeroes, I knew that I wanted the score to follow proper numerical denotation: meaning, I wanted it to appear on the right side of the scoreboard and go leftward as the number grew.
So, you can see a variable in the mess called 'lacking'. What this guy did, is allowed me to figure out, when used with the length of the string, how many leading zeroes I had.
And after that, it all worked out.
Holy cats. What a mess it was, figuring it out. Now, onto AI, physics and proper collision detection.