Animated Sprites Games under Mac OS X - Where to Start ?

Trax
Unregistered
 
Post: #1
Hi everyone...

I'm new on this forum, and I hope you will be able to help me because I'm kind of desperated. I've been programming Cocoa for 2 years. I know basic C and Obj-C, and a little openGL.

I tried to make simple 2D animated sprites games, but I was always pissed off (the kind of anger where you want to tear your hair off) because I couldn't understand why Cocoa can't handle 30 FPS animation with simple triangles and squares moving around the screen.

Unfortunately, I still can't. After a lot of fumbling, I could only come to the conclusion that I took the wrong path at the beginning, and I'm still stuck in that path, and as a result, everything goes wrong, no matter the effort.

Here's a description of the last thing I did that lead me to this forum :

A black NSView about half the size of the screen with a gray triangle that moves according to user input.
Upon user input, the triangle can shoot little yellow lines straight ahead.

That's all. No collision test for now. As soon as there's more than 1 projectile on the view, my frame rate seems to slow down dramatically. I read one of Andrews Sage's articles about not worrying about frame rate at the beginning, but hey, having all the fancy physics and every variable working just well is good, indeed, but it's useless if your frame rate makes the game unplayable.

Here are some of my other conceptions I have about Mac programming. I'd like to know what you think about it, or just tell me if I'm plain wrong.

- I don't want to use Carbon, because I feel like it's legacy and seems quite complicated.
- I don't think about openGL because to me, it's for 3D graphic. And I don't want to do 3D right now.
- If I don't use openGL, I get ugly results as described above. Quartz seems to be good, but not for animated graphics.

I feel cornered. I don't know what to do. I guess I missed some basic concepts about drawing and performance. I don't have problems with algorithms, AI, collision tests, etc, but if I can't get the most basic engine to work, I can't do aynthing else...

Thanks for your help on this issue...
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
OpenGL is perfectly good for 2D graphics, nothing in the API forces you to do 3D. It's also the only way to get speedy graphics on Mac OS X.
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #3
Welcome to the forum.
As OSC said OpenGL has become a very accepted method for doing 2d graphics this is because OpenGL can handle them just as fast or faster then other options on the market (this is a generalization dont burn me).

If you are having trouble with FPS it is most likely the way you are setting up your code, at this point it dosnt seem like a lot that would be slowing you down, Im sure if you post your code here someone will be more the willing to help you look at it.

You dont have to worry about Carbon when you are just starting out, many great games have been written in cocoa and it has the abilty to even handle complex 3d games. Work one the basics till you need to do something you cant do with Cocoa, and dont forget your project can always include both Cocoa and Carbon so you arent pinning yourself into a corner TOO badly.

In regards to your frame rate issue, What kind of computer are you using? What screen Res do you have? Are you running windowed or full screen? These options can greatly affect game speed and if you are working on a 233 Ghz iMac with 1024x768 with millions of colors in a window 30 FPS is not too unbelivable.

Please provide some more details so we can answer your questions better.

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Member
Posts: 156
Joined: 2002.11
Post: #4
My game engine supports both OpenGL and Quartz for rendering graphics, and there's no way you'll get a descent frame rate with Quartz in your games. I strongly recommend you use OpenGL to render your sprites.
Quote this message in a reply
Moderator
Posts: 698
Joined: 2002.04
Post: #5
As always, I'd suggest you take a look at SDL, but I'm not certain that SDL works with Obj-C (but you state that you know C, so...)

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Trax
Unregistered
 
Post: #6
Thank you for your quick replies. I'm using an eMac G4 800MHz, 512 RAM, OS X.3.9

Okay, now I know openGL is not only for 3D graphics, so it's kind of relieving.
But, there's something else that bothers me. When I played around learning basic 3D vertex calls and such, I noticed the way measurements are calculated. No more pixels, no more "1024 X 768", only arbitrary "units" that makes it hard to know how many units wide your screen is. Is there any way to work with pixels instead of such units ? Or maybe it's better to work with units and I just don't understand why it could be better ?

As for the project I'm working on, I think I will convert it to openGL, since Quartz doesn't seem to be the best for animated graphics. But, after saying that, I wonder : what's so good with Quartz then ?
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #7
If you want to work with "just" pixels, then all you have to do is set the projection matrix accordingly. For example, setting the projection matrix to:
Code:
gluOrtho2D(0, 640, 0, 480);
Effectively sets the "size" of your screen to be 640x480.

Another convenient bit about this is that you can use the modelview matrix to move the viewport around without having to change the screen coordinates, everything can be drawn using their absolute coordinates. This makes rotation as easy as anything else. (try that without openGL, yuck)
Quote this message in a reply
Member
Posts: 168
Joined: 2004.10
Post: #8
Trax Wrote:But, after saying that, I wonder : what's so good with Quartz then ?
See that shadow behind that window? That's Quartz. See how fast the mouse moves around the screen and with icons dragging without huge massive long delays as you get in XP? That's Quartz. See that blue shading that appears when you put your mouse over a window in exposé or cmd-shift-4-space mode? That's also Quartz.
Just because it isn't suited for games, doesn't mean it doesn't have a use.
Quote this message in a reply
Member
Posts: 42
Joined: 2002.09
Post: #9
Detox uses a near-fullscreen NSView full of NSImages bouncing around, and seems to run smooth enough. At 1024x768 on the 500MHz iMac I developed it on it managed around 18fps with other apps in the background.

Maybe you need to turn on the optimised drawing flag?

Visit http://www.theDailyGrind.net for your recommended daily intake of embittered satire.
Quote this message in a reply
Trax
Unregistered
 
Post: #10
Quote:See that shadow behind that window? That's Quartz. See how fast the mouse moves around the screen and with icons dragging without huge massive long delays as you get in XP? That's Quartz. See that blue shading that appears when you put your mouse over a window in exposé or cmd-shift-4-space mode? That's also Quartz.
Just because it isn't suited for games, doesn't mean it doesn't have a use.
Sorry, I didn't meant that, I only wanted to know how Quartz can be used and be efficient in its use.

Anyways, I reclycled my project and translated in OpenGL commands. For now, everything seems okay. I have another question. It's about scrolling.

For example, say my viewport is set to 200X100. I have somethign drawn beyond the borders, say at 300,50. I want to scroll to see the hidden darwing. How do I do that ? And can I do that repeatedly ?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
draw your stuff further left...
Quote this message in a reply
Member
Posts: 198
Joined: 2005.01
Post: #12
Yet another example of why OpenGL is perfect for 2D games too. Just change the viewport or use a translation matrix before you draw. Everything gets shifted and clipped for you (of course you waste drawing time if you draw stuff off the screen, but it works).

Cryptic Allusion Games / Cryptic Allusion, LLC
http://www.cagames.com/
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How to start writing games (includes exhaustive list of options) stevejohnson 13 7,199 Nov 1, 2009 12:55 PM
Last Post: Mike Richardson
  textured windows/animated buttons hyperzoanoid 5 3,949 Jan 5, 2003 01:19 PM
Last Post: hyperzoanoid