Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Are these lines part of the Trampoline class?</p> <pre><code>Sprite *trampoline = [Sprite spriteWithFile:@"trampoline.png"]; [self addChild:trampoline]; </code></pre> <p>From my limited experience with cocos2d, contentSize of a Sprite seems to only apply to the content that actually belongs to the Sprite, and not all children of that Sprite. As a result, in your example above, asking for the contentSize in your log statement won't work, since there isn't any content added to the Trampoline node. However, if you were to override the contentSize method inside your Trampoline class to return the contentSize of the Sprite that actually loaded the graphic, that should work.</p> <p>Here's a snippet of a Sprite I'm using in a game I'm currently working on that illustrates what I'm talking about:</p> <pre><code>- (id) init { self = [super init]; if (self != nil) { self.textLabel = [Label labelWithString:@"*TEXT*" fontName:@"Helvetica" fontSize:18]; [textLabel setRGB:0 :0 :0]; textLabel.transformAnchor = CGPointZero; textLabel.position = CGPointZero; self.transformAnchor = CGPointZero; [self addChild:textLabel]; } return self; } // - (CGSize) contentSize { return textLabel.contentSize; } </code></pre> <p>This comes from a class that extends Sprite. Until I added the override for contentSize, asking for it from another class would give me the same results your seeing. Now that I'm telling it return the content size of the textLabel, it's working just like I'd expect it to.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload