Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Gandolfmatt

macrumors member
Original poster
Jul 18, 2008
46
0
Hey, I'm new to this forum and to Cocoa, but I have really gotten into it. I can do most things, but I just need some help with a few NS commands.

(1) I'm creating a canvas in which a sprite will be able to move around and have animation. Which is the best, NSView or NSImageView?

(2) What are the NS commands for sticking a sprite from resources onto the canvas, and to make a color of it transparent? Also if there are any other pict commands.

(3) How would I get Xcode to listen for a key down, and if so, activate some code?

(4) Lastly, what are all the string commands? Like, to get the string count, mid, nthfield, or anything like that.

Thanks,
-Matt
 
1) I don't know, abstain.
2) I don't know, abstain.
3) Do you mean how to get XCode to do some replacement or something in your code? Like some sort of Macro? Or do you mean how do you listen for a keypress event in a Cocoa application?
4) http://developer.apple.com/document...lasses/NSString_Class/Reference/NSString.html
There is a message
Code:
-length
. I don't know what mid means. There is a message
Code:
-characterAtIndex
to get a character at a particular position. Not sure if this is what you mean by nthfield, but maybe this is it. If you want to tokenize the string there is
Code:
-componentsSeparatedByCharactersInSet:(NSCharacterSet *)separator

Hopefully others can help with the rest.

-Lee
 
I don't know, abstain.

Abstain?

3) Do you mean how to get XCode to do some replacement or something in your code? Like some sort of Macro? Or do you mean how do you listen for a keypress event in a Cocoa application?

Keypress event.


Thanks :)

I don't know what mid means, not sure if this is what you mean by nthfield.

Code:
MID$(source, start, length)
Returns the characters starting from "start" onward in "source". Length is optional, specifies the number of characters to return.

NTHFIELD$(source, separator, fieldNumber)
Returns the field value from the source that precedes the fieldNumber occurrence of the separator in the source.


Thanks lee1210,
-Gandolf
 
Does anyone know the answer for questions 1,2, and 3?

(1) I'm creating a canvas in which a sprite will be able to move around and have animation. Which is the best, NSView or NSImageView?

(2) What are the NS commands for sticking a sprite from resources onto the canvas, and to make a color of it transparent? Also if there are any other pict commands.

(3) How would I get Xcode to listen for a key press event, and if so, activate some code?


Thanks,
-Matt
 
Does anyone know the answer for questions 1,2, and 3?


Thanks,
-Matt

There isn't any short answer to that question! ;)

First, you probably need to choose which graphics API/framework to use, so I'd recommend reading this.

Quartz 2D sounds best suited to your needs, IMO. You can draw sprites to bitmaps (or even better, layers), then copy to screen as and where needed.
Try here.


As for keyboard input, I've never written a Cocoa game, but I'd guess you'd have to subclass either the application or window class, then implement the following methods as required:

- (void)keyDown: (NSEvent *)theEvent;
- (void)keyUp: (NSEvent *)theEvent;
- (void)flagsChanged: (NSEvent *)theEvent;
 
Thanks. :) All my questions are just about answered.

I will research more on what you wrote, if I have any more questions, I will post here.


Thanks,
-Gandolf
 
There aren't too many tuts about quartz and most of them are stuffed with extra features that makes your brain fry when you look at the code. So, I'm going to take a look at Open Gl. Open Gl will be way faster and have 3D support.


Thanks,
-Matt
 
Alright, I've been researching into this big time and it seems good, except for one small problem.

I can't find any tuts on how to stick a pic from my resources into OpenGl. To make 2D pics instead of 3D.

Anyone know how?


-Matt
 
I'm not that familiar with OpenGL, so can't help you much, sorry.

If you want to go the Quartz2D route, there's a guide here on drawing with CGLayers here, with some example code. It's good for quick offscreen sprite drawing.
 
I lost track of this thread, just saw this...

abstain, verb: "to refrain deliberately and often with an effort of self-denial from an action or practice <abstain from drinking>"

Keypress event.

Looks like someone covered this.

Code:
MID$(source, start, length)
Returns the characters starting from "start" onward in "source". Length is optional, specifies the number of characters to return.

NTHFIELD$(source, separator, fieldNumber)
Returns the field value from the source that precedes the fieldNumber occurrence of the separator in the source.

for NTHFIELD:
Code:
componentsSeparatedByCharactersInSet:
should do this for you.

for MID:
Code:
– substringFromIndex:  
– substringWithRange:

The start would be the parameter to substringFromIndex. The NSRange for substringWithRange would have the location field set to start, and the length field set to length.

-Lee
 
Everything is running good so far. I will continue to add things and will post when I run into a problem.


Thanks guys,
-Gandolf
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.