Hi guys. I'm new to cocos2d and also to this forum. I want to make a simple game, but don't know how to make a sprite. I just want the sprite to be a picture. It's not on the main menu either, it's on a different page. I'd really appreciate it if you could help. Thanks.
Add sprite
(162 posts) (19 voices)-
Posted 1 year ago #
-
Hi Joe
You drag them into your project in Xcode as images (I use PNG files), and then can either use them as part of a spritesheet like this:
atlasExplosionManager=[[CCSpriteSheet spriteSheetWithFile:@"complete_form.png"] retain];
[self addChild:atlasExplosionManager z:25];atlasExplosionSprite=[CCSprite spriteWithTexture:atlasExplosionManager.texture rect:CGRectMake(0,0,320,322)];
[atlasExplosionSprite setOpacity:255];
[atlasExplosionSprite setScale:1.5];
[atlasExplosionSprite setPosition:ccp(160,-320)];
[atlasExplosionManager addChild:atlasExplosionSprite z:16];
or simply, like this:
bgSprite=[CCSprite spriteWithFile:@"big-bg.png"];
[bgSprite setPosition:ccp(160, 316)];
[bgSprite setScale:1.0];
[bgSprite setOpacity:255];
[self addChild:bgSprite z:0];
1.0 and 255 are the default values for scale and opacity respectively - you can leave those out, I just left them in so you could see how to vary them.
Posted 1 year ago # -
oh yes - those variables were already declared elsewhere - you need to declare them first, like this:
CCSpriteSheet *atlasExplosionManager;
CCSprite *AtlasExplosionSprite;CCSprite *bgSprite;
you can do this as part of your creation command:
CCSprite *bgSprite = [CCSprite spriteWithFile:@"big-bg.png"];
if you're wondering why the "atlas" thing - the classes used to be called AtlasSpriteManager and AtlasSprite in an older version, and the variables date from then :) You can of course call them whatever you want.
Posted 1 year ago # -
Hi Joe
There are loads of great resources if you're new to cocos2d that should get you up and running pretty quickly, the first stop should be here;
http://www.cocos2d-iphone.org/forum/topic/3
Which will let you know about the test code provided with cocos2d, these are in the form of examples and pretty much demonstrate the features of cocos2d. Then check out Rays blog for tutorials on creating games from scratch;
http://www.raywenderlich.com/352/how-to-make-a-simple-iphone-game-with-cocos2d-tutorial
Posted 1 year ago # -
There is some great documentation already on the Cocos2D site:
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index
or just click the "Documentation" button at the top of this page.
Posted 1 year ago # -
Ok thanks so much guys! I really appreciate it!
Posted 1 year ago # -
@dannorcott - i tried the second method you provided me with and got 8 errors. they all say " expected " something. can you help me out?
Posted 1 year ago # -
Here's a picture of the problem.
http://img413.imageshack.us/img413/1562/fullscreene.pngPosted 1 year ago # -
@Joethemonkey101 init is a method, you need to enclose the statements it contains within curly wurlys
-(id) init { // your code goes here }Posted 1 year ago # -
Ok thanks. What code needs to go there?
Posted 1 year ago # -
You should initialize your object's properties/variables (if any) from inside those curly wurlys. You should also call super's -init first. So something like:
- (id) init { if (![super init]) return nil; self.myProperty = someInitialValue; return self; }Posted 1 year ago # -
thanks codemattic, i'll try that.
Posted 1 year ago # -
The problem is that I don't know what properties and values i need to add. It's just an image. Sorry, I'm new to coding.
Posted 1 year ago # -
I think that you can start by adding the cocos2d templates on xcode before starting the development:
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index
After adding them, you can check out:
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:hello_world
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:hello_actions
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:hello_events
They are the super duper beginner tutorials! They helped me when i was starting...
Posted 1 year ago # -
you should start by reading the resources abitofcode pointed you to.
Also take a look at the tests that come with cocos2d, there you will find for example how to do what you ask for. Among a lot of other useful things.Posted 1 year ago # -
Sorry I tried reading the sprite test but I still don't get how to add one.
Posted 1 year ago # -
Have you checked http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:hello_actions ?
Posted 1 year ago # -
Read this post, particularly the section entitled 'Adding A Sprite' it explains in some detail how to add a sprite. It'll also then give you some ideas of what to do with the sprite once you've added it.
http://www.raywenderlich.com/352/how-to-make-a-simple-iphone-game-with-cocos2d-tutorial
There are a number of other tutorials on the Rays site that'll get you heading in the right direction.
Posted 1 year ago # -
Ok thanks guys, I'll check them out
Posted 1 year ago # -
Ok I fixed all the errors. I forgot the curly brackets for the init method. The thing is that there's this new error that says
" Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1 "
I don't know how to fix this.Posted 1 year ago # -
Joe, I think that means you're either missing code in your package (make sure all the box are ticked for each file you created in your project) or you are missing a required framework (check your target's libraries/frameworks).
Posted 1 year ago # -
Thanks Greg, I'll check to make sure I did that.
Posted 1 year ago # -
Greg, I went into cocos2d and made sure everything important was checked. About half of them was unchecked. I'm not sure what to do with those.
Posted 1 year ago # -
I'm still stuck with one error. I don't know what to do.
Posted 1 year ago # -
Can anyone help?
Posted 1 year ago # -
Can you get the cocos2d tests to run? (see Read Before Posting post at top of forum).
If these don't work then it may be worth downloading the latest copy of the SDK from apple and trying again.
Once you can get the tests to run, then try setting up a new project using the template that comes with cocos2d and running this.
It's hard to respond to questions such as "I'm still stuck with one error. I don't know what to do." its the equivalent of walking into the doctors and saying "I feel poorly, what's wrong".
Posted 1 year ago # -
Sorry I just don't know how to explain it. Would screenshots help?
Posted 1 year ago # -
What is the one error? Same as before or new?
Posted 1 year ago # -
It's still " Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1 "
Posted 1 year ago # -
But also now I messed something up. Take a look. http://yfrog.com/1gscreenshot20100507at454p
Posted 1 year ago #
Topic Closed
This topic has been closed to new replies.