<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>cocos2d for iPhone &#187; Topic: own component dont work :-(</title>
		<link>http://www.cocos2d-iphone.org/forum/topic/1750</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 02:01:48 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.cocos2d-iphone.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.cocos2d-iphone.org/forum/rss/topic/1750" rel="self" type="application/rss+xml" />

		<item>
			<title>Mark Sawicki on "own component dont work :-("</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/1750#post-14195</link>
			<pubDate>Sat, 03 Oct 2009 22:39:21 +0000</pubDate>
			<dc:creator>Mark Sawicki</dc:creator>
			<guid isPermaLink="false">14195@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>There is an example in MenuTest.m that should show you how to use an AtlasSprite like you want..</p>
<p>Mark
</p></description>
		</item>
		<item>
			<title>smendrick on "own component dont work :-("</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/1750#post-14148</link>
			<pubDate>Sat, 03 Oct 2009 05:59:30 +0000</pubDate>
			<dc:creator>smendrick</dc:creator>
			<guid isPermaLink="false">14148@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Found this in the MenuItem class:</p>
<p>/** MenuItemAtlasCocosNode&#60;CocosNodeRGBA&#62; accepts AtlasCocosNode&#60;CocosNodeRGBA&#62; objects as items.<br />
 The images has 3 different states:<br />
 - unselected image<br />
 - selected image<br />
 - disabled image</p>
<p> Limitations:<br />
  - AtlasSprite objects can only have as a parent an AltasSpriteManager<br />
  - So they need to be added twice:<br />
    - To the Menu<br />
    - And to the AtlasSpriteManager<br />
  - To respect the menu aligments, the AtlasSpriteManager should have the same coordinates as the Menu<br />
 @since v0.8.0<br />
 */</p>
<p>Still confused but I think I'm getting closer.
</p></description>
		</item>
		<item>
			<title>smendrick on "own component dont work :-("</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/1750#post-13480</link>
			<pubDate>Sun, 27 Sep 2009 02:59:12 +0000</pubDate>
			<dc:creator>smendrick</dc:creator>
			<guid isPermaLink="false">13480@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am also trying to do create my own custom subclass of a CocosNode with:</p>
<p>- a background sprite<br />
- an overlay sprite<br />
- a selected state sprite</p>
<p>I'm loading the sprites from a sprite sheet and using AtlasSpriteManager and I don't know how to add the sprites and the label as a child to self when I also need to add the sprites as a child to the sprite manager.</p>
<p>Do I need to do both? Sorry very confused. Can anybody help explain this to me or offer any suggestions?</p>
<p>Thanks
</p></description>
		</item>
		<item>
			<title>chrisco on "own component dont work :-("</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/1750#post-11003</link>
			<pubDate>Tue, 08 Sep 2009 16:18:16 +0000</pubDate>
			<dc:creator>chrisco</dc:creator>
			<guid isPermaLink="false">11003@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Great :)
</p></description>
		</item>
		<item>
			<title>raegtime on "own component dont work :-("</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/1750#post-11002</link>
			<pubDate>Tue, 08 Sep 2009 16:01:33 +0000</pubDate>
			<dc:creator>raegtime</dc:creator>
			<guid isPermaLink="false">11002@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/1338'>Chrisco</a>... thx it works :-) ...
</p></description>
		</item>
		<item>
			<title>chrisco on "own component dont work :-("</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/1750#post-10991</link>
			<pubDate>Tue, 08 Sep 2009 14:51:06 +0000</pubDate>
			<dc:creator>chrisco</dc:creator>
			<guid isPermaLink="false">10991@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi raegtime,</p>
<p>A couple of things:</p>
<p>1 - It looks like you're subclassing Sprite. You might find it easier to subclass CocosNode and add the Sprites representing various states to that node.</p>
<p>2 - Whenever you call -init, it needs to be preceded with -alloc.  So "drop1 = [DropDown init];" doesn't work, but "drop1 = [[DropDown alloc] init];" in theory, would.</p>
<p>3. You've changed your init method to a class method (+). Actually, I'm a little surprised that the compiler doesn't throw a warning (or error) when then happens. Try reworking your init method like this (note: use a "-" and not a "+"):</p>
<pre><code>- (id)init {

    if (self = [super init]) {
       // code that creates a Sprite to represent your non-active state and adds it as a child to self
       // code that creates a Sprite to represent your active state and adds it as a child to self
       // code that creates your label and adds it as a child to self
    }
    return self;
}</code></pre>
<p>I hope this makes sense - I'm at work, so don't have a lot of time to get to in depth...
</p></description>
		</item>
		<item>
			<title>pabloruiz55 on "own component dont work :-("</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/1750#post-10990</link>
			<pubDate>Tue, 08 Sep 2009 14:49:42 +0000</pubDate>
			<dc:creator>pabloruiz55</dc:creator>
			<guid isPermaLink="false">10990@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I don't quite understand either... It seems you are allocation your object 2 times inside the init function.</p>
<p>i think a more apropiate way would be:</p>
<p>drop1 = [[DropDown alloc] init];<br />
---------------------------------</p>
<p>@implementation DropDown<br />
<pre><code>@synthesize captionLbl;
- (id) init
{
if( (self=[super init] ))
{
  And here initialize your sprites, labels,etc...
  You should have an Sprite instance variable, a Label instance variable, and so on... in your class.

  Then:
    captionLbl = [self initLabel]; (i would change the functions name so you don&#39;t misunderstand them as constructor functions, since these aren&#39;t)
}
return self;
}</code></pre></description>
		</item>
		<item>
			<title>shazbox on "own component dont work :-("</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/1750#post-10985</link>
			<pubDate>Tue, 08 Sep 2009 14:27:47 +0000</pubDate>
			<dc:creator>shazbox</dc:creator>
			<guid isPermaLink="false">10985@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Your init function confuses me a lot. Why not use more than 1 step to initialize and return?
</p></description>
		</item>
		<item>
			<title>raegtime on "own component dont work :-("</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/1750#post-10971</link>
			<pubDate>Tue, 08 Sep 2009 12:34:07 +0000</pubDate>
			<dc:creator>raegtime</dc:creator>
			<guid isPermaLink="false">10971@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hi,</p>
<p>i tryed to create a own GUI component with cocos 2d... i haved written a class (extends Sprite) ... this class initialize with graphics and a lable... if I create an instance of my class .. i  can see my component but i can user any functions... i wrote a setLabel function .. but the lable change... </p>
<p>i create a instance with this code:</p>
<p>drop1 = [DropDown init];</p>
<p>//here I call the function but it dont works :-(<br />
[drop1 setCaption:@"Produkt"];</p>
<p>///dropDown.m:</p>
<p>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> "DropDown.h"</p>
<p>@implementation DropDown</p>
<p>@synthesize captionLbl;<br />
+ (id) init<br />
{<br />
	if( (self=[super init] ))<br />
	{<br />
		return [[[self spriteWithFile:@"menue_dropdownbtn.png"] addChild:[[self alloc] initActiveState]] addChild:[[self alloc] initLabel]];<br />
	}<br />
}</p>
<p>- (id)initActiveState<br />
{<br />
	activated = [Sprite spriteWithFile:@"menue_dropactiveated.png"];<br />
	[activated setAnchorPoint:ccp(0,0)];<br />
	[activated setPosition:ccp(173,0)];<br />
	[activated setVisible:NO];<br />
	return activated;<br />
}</p>
<p>- (id)initLabel<br />
{<br />
	captionLbl = [Label labelWithString:@"Text" fontName:@"Arial" fontSize:14.0f];<br />
	[captionLbl setAnchorPoint:ccp(0,0)];<br />
	[captionLbl setPosition:ccp(10,5)];<br />
	[captionLbl setRGB:0 :0 :0];<br />
	return captionLbl;<br />
}</p>
<p>- (void)setCaption:(NSString*)text<br />
{<br />
	[captionLbl setString:text];<br />
	NSLog(@"Hallooooo");<br />
}</p>
<p>- (void)activate<br />
{<br />
	[activated setVisible:YES];<br />
	isActive = YES;<br />
}</p>
<p>- (void)deactivate<br />
{<br />
	[activated setVisible:NO];<br />
	isActive = NO;<br />
}</p>
<p>@end</p>
<p>//  DropDown.h<br />
//</p>
<p>//</p>
<p>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#60;Foundation/Foundation.h&#62;<br />
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> "cocos2d.h"</p>
<p>@interface DropDown : Sprite<br />
{<br />
	BOOL isActive;</p>
<p>	@private<br />
	Sprite* activated;<br />
	Label* captionLbl;</p>
<p>}</p>
<p>@property (nonatomic, retain) Label* captionLbl;</p>
<p>+ (id) init;<br />
- (id)initActiveState;<br />
- (id)initLabel;<br />
- (void)setCaption:(NSString*)text;<br />
- (void)activate;<br />
- (void)deactivate;<br />
@end
</p></description>
		</item>

	</channel>
</rss>

