Tutorial 4 Progress Update
I’m working on the next Tutorial this weekend which will cover bitmap fonts. I have found though some performance issues with using glDrawArrays and drawing each image on the screen seperately. The API overhead of calling glDrawArrays for each image puts a real strain on the CPU and can cause your game to jitter and skip.
I’ve been making some changes so that you can both render individual images and also use vertex arrays to be able to render multiple images using just a single call to glDrawElements. For the tilemap class I’ve just completed this resulted in a 350% reduction in the amount of CPU being used when drawing the tile map.
Because of this and the fact that the bitmap font class renders a different image for each character, I am going to make changes to this class so that it also makes use of vertex arrays. This will mean that the Tutorial may not be available until the start of next week.
I think it will be worth waiting as using vertex arrays really seems to be the way to go to significantly improve performance when rendering many things to the screen. Once I have made all the changes necessary, I will do a tutorial on those changes as it will effect the image class, spritesheet class etc.
Check back soon and thanks for all the great comments :)
Mike
18 Comments
luke on April 11th, 2009
Can’t wait. Thanks a ton.
bob on April 11th, 2009
same here… can’t wait..
bob on April 12th, 2009
have a question for you. I added a sprite class and I have about 30 running. here’s the catch it works in the simulator but not on the iphone. I get only have of them showing up..
any idea… send you my code if you would like..
bob on April 12th, 2009
also, I have a suggestion. Would it be possible to add a way to flip the image horizontally and vertically..
Thanks… this code is great
bob on April 12th, 2009
PS.. maybe I should wait for your changes.. This might be a moot point..
Thanks for all your great work, and I hope you got the Coffee I sent.
Thanks Again..
mike on April 12th, 2009
Hi guys
@Bob, it could be a number of things really. If you want to post or send me your code I’d be happy to have a look mike@blog_domain_name.co.uk
I’m also adding the flipping of sprites horizontally and vertically too as I needed those features, so good timing :)
Also thanks for the coffee bob, its much appreciated. After your comment I checked and the email about the coffee had been put into spam, so I’ve now got it and sorted that out. It’s really appreciated.
Mike
bob on April 12th, 2009
Hi Mike, I just emailed the code to you. Thanks again for everything.
Ant1 on April 12th, 2009
I can’t wait for the next tutorial!
Hope it’s as useful as the last ones
Thanks for all the help
Justin on April 12th, 2009
Still waiting for you tutorial 4. And tonight i found that the mainGameLoop in your tutorial 3 code ran more than 90% cpu time of my machine when i ran it in my IPhone Simulator. Does it mean the line: while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource); could not produce any delay for the loop? If I run that application in IPhone, will it run with all the cpu time too?
Thanks!
bob on April 13th, 2009
Hi Mike,
I found the answer..
It seems the Simulator doesn’t care if you get the case wrong in when referencing image file names… (ie, “Rjet.png” should have been “RJet.png”), whereas the device does!!
mike on April 13th, 2009
Excellent. I would have assumed that they would have both complained the same in that case!!
If you check the log output in Xcode and see the message
Image: null
That also means that a file passed into the Texture2D class could not be found or loaded and you know that its not been able to get the file you have passed in.
Not sure why but I didn’t get the code you sent over either…
MikeD
mike on April 13th, 2009
@Justin, I have also noticed that the Simulator can use up 100% of my machines processor. I think its just as the sim is hungry. When I run the same app on the iPhone is uses way less CPU. If you run instruments and take a look at the CPU you should see that overall the game is taking around 30% of the processor.
I am going to be making more changes to the main game loop which I’ll be posting on the blog soon, but I don’t think the current game loop would max out your iPhone.
Let me know if you have any other questions.
Mike
bob on April 13th, 2009
HI Mike,
Thanks for the tip about image NULL… that will help in the future.
I sent the code a 3rd time hopefully you’ll see it tomorrow. I now have clouds moving, jets flying, ship moving, ocean waves and sound. Next is Accelerometer…
can’t wait till the next tutorial..
mike on April 13th, 2009
@bob, sounds like things are really coming along :)
I’ve still not got your code though, I’m not sure why. I’ve checked my spam folders etc in case they were picking it up but nothing is in there. Just to check the email is mike @ 71squared . co . uk obviously without the spaces.
I am uploading the next Tutorial as I type so it will be up soon :)
Mike
bob on April 13th, 2009
HI Mike,
I had the wrong email address, I sent it again so you can see what it looks like. about 70% done
mike on April 13th, 2009
Yep, got it that time bob and its looking really good. I love seeing peoples ideas for games, I always seem to come up short when trying to think of an actual game idea rather than the mechanics :) I really like your game idea and the boat on the waves is a very nice touch.
I hope you enjoy Tutorial 4 and I’ll be getting Tutorial 5 up soon on Animation. I just need to make sure it all works with the changes I’ve made :)
Mike
bob on April 13th, 2009
@Mike
the original has the accelerometer so when you tip the phone back and forth the ship moves across the waves, and the jets randomly attack a do a loop D loop when they come down.
The Tutorials and code help a real lot. Thanks so much for all of your hard work. I about half way through T4. It looks great, just like the rest that you’ve done. I hope your family is feeling better, we all appreciate thye time and effort you put into this.




Justin on April 11th, 2009
Thank you very much!!!