<?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: Sprite Crop</title>
		<link>http://www.cocos2d-iphone.org/forum/topic/202</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 01:18:51 +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/202" rel="self" type="application/rss+xml" />

		<item>
			<title>georgejcook on "Sprite Crop"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/202#post-4132</link>
			<pubDate>Wed, 15 Jul 2009 21:28:11 +0000</pubDate>
			<dc:creator>georgejcook</dc:creator>
			<guid isPermaLink="false">4132@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Gents- just wanted to say thanks a ton!</p>
<p>the spriteatlas hint worked perfectly for what I was doing.</p>
<p>I'll probably use Steve's texturealtas tweak eventually, but too busy for now..</p>
<p>thanks!!</p>
<p>GEorge
</p></description>
		</item>
		<item>
			<title>psionic on "Sprite Crop"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/202#post-1094</link>
			<pubDate>Sat, 20 Jun 2009 16:42:05 +0000</pubDate>
			<dc:creator>psionic</dc:creator>
			<guid isPermaLink="false">1094@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>In my example, setting scaleMode = scalemode_crop will do the cropping<br />
for you, without scaling the texture. There&#39;s nothing in the default<br />
library to handle this, other than the textureAtlas methods below. My<br />
method will keep the &#39;width&#39; of the sprite the same (though it will<br />
display differently), while the setTextureRect will make the sprite&#39;s<br />
width the same as the crop.</p>
<p>No real benefit to using one over the other except that the<br />
AtlasSprite is a built in function, while the method I use is an<br />
extension/modification of the source code. Mine uses a Sprite basis,<br />
while the AtlasSprite needs a manager etc.</p>
<p>Read up on steve&#39;s method before you try mine.. it&#39;s as easy as you&#39;re<br />
going to get :P</p>
<p>Chris.</p>
<p>On Sat, Jun 20, 2009 at 4:51 AM, &#60;cocos2d-iphone-discuss@gamesforfood.cl&#62; wrote:<br />
&#62; woonsung says:<br />
&#62;<br />
&#62; Thank you.<br />
&#62;<br />
&#62; But I do not want to be scaled.<br />
&#62; Do not cocos2d default library?<br />
&#62;<br />
&#62; Read the whole thread.
</p></description>
		</item>
		<item>
			<title>woonsung on "Sprite Crop"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/202#post-1086</link>
			<pubDate>Sat, 20 Jun 2009 12:56:50 +0000</pubDate>
			<dc:creator>woonsung</dc:creator>
			<guid isPermaLink="false">1086@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thank you Steve.</p>
<p>But is not simple.</p>
<p>AtlasSpriteManager *mgr = [AtlasSpriteManager spriteManagerWithFile:@"box.png" capacity:2];<br />
[self addChild:mgr z:0 tag:9999];		</p>
<p>AtlasSprite *sprite1 = [AtlasSprite spriteWithRect:CGRectMake(0, 0, 80, 100) spriteManager: mgr];<br />
sprite1.position = ccp(160, 240);</p>
<p>[mgr addChild:sprite1 z:1 tag:2];
</p></description>
		</item>
		<item>
			<title>Steve Oldmeadow on "Sprite Crop"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/202#post-1080</link>
			<pubDate>Sat, 20 Jun 2009 10:09:07 +0000</pubDate>
			<dc:creator>Steve Oldmeadow</dc:creator>
			<guid isPermaLink="false">1080@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>You could use an AtlasSprite and then use setTextureRect to adjust the displayed rectangle.  Just bear in mind that the size of the sprite will be adjusted so when you set the rectangle to 80x100 your sprite now has a width of 80.
</p></description>
		</item>
		<item>
			<title>woonsung on "Sprite Crop"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/202#post-1077</link>
			<pubDate>Sat, 20 Jun 2009 08:50:24 +0000</pubDate>
			<dc:creator>woonsung</dc:creator>
			<guid isPermaLink="false">1077@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thank you.</p>
<p>But I do not want to be scaled.<br />
Do not cocos2d default library?
</p></description>
		</item>
		<item>
			<title>allenfjordan on "Sprite Crop"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/202#post-1071</link>
			<pubDate>Sat, 20 Jun 2009 05:23:27 +0000</pubDate>
			<dc:creator>allenfjordan</dc:creator>
			<guid isPermaLink="false">1071@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Try to use backticks when posting code.  It formats things nicely, like this:</p>
<pre><code>int IntegerCompare(const void *first, const void *second) {
	uint16_t *firstInt = (uint16_t*)first;
	uint16_t *secondInt = (uint16_t*)second;
	if (*firstInt &#60; *secondInt) return -1;
	if (*firstInt &#62; *secondInt) return 1;
	return 0;
}</code></pre></description>
		</item>
		<item>
			<title>psionic on "Sprite Crop"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/202#post-1069</link>
			<pubDate>Sat, 20 Jun 2009 05:11:06 +0000</pubDate>
			<dc:creator>psionic</dc:creator>
			<guid isPermaLink="false">1069@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>yikes that doesn&#39;t look nice at all. however, simply copying and<br />
pasting into xcode should rebeautify it for you :)</p>
<p>Chris.</p>
<p>On Sat, Jun 20, 2009 at 1:09 AM, &#60;cocos2d-iphone-discuss@gamesforfood.cl&#62; wrote:<br />
&#62; psionic says:<br />
&#62;<br />
&#62; Hi woonsung,<br />
&#62;<br />
&#62; you need to make additions to the cocos2d library, since the relevant<br />
&#62; part is in Texture2d.<br />
&#62;<br />
&#62; like the following:<br />
&#62;<br />
&#62; scaleWithStretch is to stretch the item, just withScale will crop it<br />
&#62; off at the end.<br />
&#62;<br />
&#62; set the curScale.x and curScale.y for the extension as needed.<br />
&#62;<br />
&#62; hope this is useful for you.<br />
&#62;<br />
&#62; Chris.<br />
&#62;<br />
&#62; =============<br />
&#62; Additions to Texture2d (cocos2d 0.71 I believe I started with)<br />
&#62; =============<br />
&#62;<br />
&#62; //@note: here to enable drawing things like progress bars.<br />
&#62; - (void) drawAtPoint:(CGPoint)point withScale: (CGPoint) scale<br />
&#62; {<br />
&#62; GLfloat coordinates[] = { 0.0f, _maxT * scale.y,<br />
&#62; _maxS * scale.x, _maxT * scale.y,<br />
&#62; 0.0f, 0.0f,<br />
&#62; _maxS *scale.x, 0.0f };<br />
&#62; GLfloat width = (GLfloat)_width * _maxS * scale.x,<br />
&#62; height = (GLfloat)_height * _maxT * scale.y;<br />
&#62;<br />
&#62; GLfloat vertices[] = {point.x, point.y, 0.0f,<br />
&#62; width + point.x, point.y, 0.0f,<br />
&#62; point.x, height + point.y, 0.0f,<br />
&#62; width + point.x, height + point.y, 0.0f };<br />
&#62;<br />
&#62; glBindTexture(GL_TEXTURE_2D, _name);<br />
&#62; glVertexPointer(3, GL_FLOAT, 0, vertices);<br />
&#62; glTexCoordPointer(2, GL_FLOAT, 0, coordinates);<br />
&#62; glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);<br />
&#62; }<br />
&#62;<br />
&#62; //@note: here to enable drawing things like stretchy bars.<br />
&#62; - (void) drawAtPoint:(CGPoint)point withScaleStretch: (CGPoint) scale<br />
&#62; {<br />
&#62; GLfloat coordinates[] = { 0.0f, _maxT,<br />
&#62; _maxS, _maxT,<br />
&#62; 0.0f, 0.0f,<br />
&#62; _maxS, 0.0f };<br />
&#62; GLfloat width = (GLfloat)_width * _maxS * scale.x,<br />
&#62; height = (GLfloat)_height * _maxT * scale.y;<br />
&#62;<br />
&#62; GLfloat vertices[] = { point.x, point.y, 0.0f,<br />
&#62; width + point.x, point.y, 0.0f,<br />
&#62; point.x, height + point.y, 0.0f,<br />
&#62; width + point.x, height + point.y, 0.0f };<br />
&#62;<br />
&#62; glBindTexture(GL_TEXTURE_2D, _name);<br />
&#62; glVertexPointer(3, GL_FLOAT, 0, vertices);<br />
&#62; glTexCoordPointer(2, GL_FLOAT, 0, coordinates);<br />
&#62; glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);<br />
&#62; }<br />
&#62;<br />
&#62; =============<br />
&#62; Then some sort of extension subclassing sprite: (this too isn&#39;t full code)<br />
&#62;<br />
&#62; in the interface:<br />
&#62; =============<br />
&#62;<br />
&#62; typedef enum _scaleMode<br />
&#62; {<br />
&#62; scalemode_crop,<br />
&#62; scalemode_stretch,<br />
&#62; } ScaleMode;<br />
&#62;<br />
&#62; @interface SpriteExt: Sprite<br />
&#62; {<br />
&#62; cpVect curScale;<br />
&#62; ScaleMode scaleMode;<br />
&#62; }<br />
&#62;<br />
&#62; @property(readwrite, assign) cpVect curScale;<br />
&#62; @property(readwrite, assign) ScaleMode scaleMode;<br />
&#62;<br />
&#62; =============<br />
&#62; and in the implementation:<br />
&#62; =============<br />
&#62;<br />
&#62; -(id) init<br />
&#62; {<br />
&#62; if (![super init])<br />
&#62; return nil;<br />
&#62;<br />
&#62; curScale.x = curScale.y = 1;<br />
&#62; scaleMode = scalemode_crop;<br />
&#62;<br />
&#62; return self;<br />
&#62; }<br />
&#62;<br />
&#62; -(void) draw<br />
&#62; {<br />
&#62; if (curScale.x == 1 &#38;&#38; curScale.y == 1)<br />
&#62; {<br />
&#62; [super draw];<br />
&#62; return;<br />
&#62; }<br />
&#62; glEnableClientState( GL_VERTEX_ARRAY);<br />
&#62; glEnableClientState( GL_TEXTURE_COORD_ARRAY );<br />
&#62;<br />
&#62; glEnable( GL_TEXTURE_2D);<br />
&#62;<br />
&#62; glColor4ub( r, g, b, opacity);<br />
&#62;<br />
&#62; if (scaleMode == scalemode_crop)<br />
&#62; [texture drawAtPoint: CGPointZero withScale: curScale];<br />
&#62; else<br />
&#62; [texture drawAtPoint: CGPointZero withScaleStretch: curScale];<br />
&#62;<br />
&#62; glColor4ub( 255, 255, 255, 255);<br />
&#62;<br />
&#62; glDisable( GL_TEXTURE_2D);<br />
&#62;<br />
&#62; glDisableClientState(GL_VERTEX_ARRAY );<br />
&#62; glDisableClientState( GL_TEXTURE_COORD_ARRAY );<br />
&#62; }<br />
&#62;<br />
&#62; On Sat, Jun 20, 2009 at 12:33 AM,<br />
&#62; &#60;cocos2d-iphone-discuss@gamesforfood.cl&#62; wrote:<br />
&#62;&#62; woonsung says:<br />
&#62;&#62;<br />
&#62;&#62; Cut to the desired size of a sprite can draw?<br />
&#62;&#62;<br />
&#62;&#62; If you have an image of size 100 * 100<br />
&#62;&#62; However, and I want to size 80 * 100.<br />
&#62;&#62;<br />
&#62;&#62; Using images such as time bar.<br />
&#62;&#62; Do you understand?<br />
&#62;&#62;<br />
&#62;&#62; ;)<br />
&#62;&#62;<br />
&#62;&#62; Sprite *Box = [Sprite spriteWithFile:@&#34;box.png&#34;];<br />
&#62;&#62;<br />
&#62;&#62; [Box setPosition:ccp(160, 240)];<br />
&#62;&#62; [self addChild:Box z:1];<br />
&#62;&#62;<br />
&#62;&#62; Read the whole thread.<br />
&#62;<br />
&#62; Read the whole thread.
</p></description>
		</item>
		<item>
			<title>psionic on "Sprite Crop"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/202#post-1068</link>
			<pubDate>Sat, 20 Jun 2009 05:08:37 +0000</pubDate>
			<dc:creator>psionic</dc:creator>
			<guid isPermaLink="false">1068@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi woonsung,</p>
<p>you need to make additions to the cocos2d library, since the relevant<br />
part is in Texture2d.</p>
<p>like the following:</p>
<p>scaleWithStretch is to stretch the item, just withScale will crop it<br />
off at the end.</p>
<p>set the curScale.x and curScale.y for the extension as needed.</p>
<p>hope this is useful for you.</p>
<p>Chris.</p>
<p>=============<br />
Additions to Texture2d  (cocos2d 0.71 I believe I started with)<br />
=============</p>
<p>//@note: here to enable drawing things like progress bars.<br />
- (void) drawAtPoint:(CGPoint)point withScale: (CGPoint) scale<br />
{<br />
	GLfloat		coordinates[] = { 0.0f,	_maxT * scale.y,<br />
		_maxS * scale.x,	_maxT * scale.y,<br />
		0.0f,	0.0f,<br />
	_maxS *scale.x,	0.0f };<br />
	GLfloat		width = (GLfloat)_width * _maxS * scale.x,<br />
	height = (GLfloat)_height * _maxT * scale.y;</p>
<p>	GLfloat		vertices[] = {point.x,			point.y,	0.0f,<br />
		width + point.x,	point.y,	0.0f,<br />
		point.x,			height  + point.y,	0.0f,<br />
	width + point.x,	height  + point.y,	0.0f };</p>
<p>	glBindTexture(GL_TEXTURE_2D, _name);<br />
	glVertexPointer(3, GL_FLOAT, 0, vertices);<br />
	glTexCoordPointer(2, GL_FLOAT, 0, coordinates);<br />
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);<br />
}</p>
<p>//@note: here to enable drawing things like stretchy bars.<br />
- (void) drawAtPoint:(CGPoint)point withScaleStretch: (CGPoint) scale<br />
{<br />
	GLfloat		coordinates[] = { 0.0f,	_maxT,<br />
		_maxS,	_maxT,<br />
		0.0f,	0.0f,<br />
	_maxS,	0.0f };<br />
	GLfloat		width = (GLfloat)_width * _maxS * scale.x,<br />
	height = (GLfloat)_height * _maxT * scale.y;</p>
<p>	GLfloat		vertices[] = {	point.x,			point.y,	0.0f,<br />
		width + point.x,	point.y,	0.0f,<br />
		point.x,			height  + point.y,	0.0f,<br />
	width + point.x,	height  + point.y,	0.0f };</p>
<p>	glBindTexture(GL_TEXTURE_2D, _name);<br />
	glVertexPointer(3, GL_FLOAT, 0, vertices);<br />
	glTexCoordPointer(2, GL_FLOAT, 0, coordinates);<br />
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);<br />
}</p>
<p>=============<br />
Then some sort of extension subclassing sprite: (this too isn&#39;t full code)</p>
<p>in the interface:<br />
=============</p>
<p>typedef enum _scaleMode<br />
	{<br />
		scalemode_crop,<br />
		scalemode_stretch,<br />
	} ScaleMode;</p>
<p>@interface SpriteExt: Sprite<br />
{<br />
	cpVect curScale;<br />
	ScaleMode scaleMode;<br />
}</p>
<p>@property(readwrite, assign) cpVect curScale;<br />
@property(readwrite, assign) ScaleMode scaleMode;</p>
<p>=============<br />
and in the implementation:<br />
=============</p>
<p>-(id) init<br />
{<br />
	if (![super init])<br />
		return nil;</p>
<p>	curScale.x = curScale.y = 1;<br />
	scaleMode = scalemode_crop;</p>
<p>	return self;<br />
}</p>
<p>-(void) draw<br />
{<br />
	if (curScale.x == 1 &#38;&#38; curScale.y == 1)<br />
	{<br />
		[super draw];<br />
		return;<br />
	}<br />
	glEnableClientState( GL_VERTEX_ARRAY);<br />
	glEnableClientState( GL_TEXTURE_COORD_ARRAY );</p>
<p>	glEnable( GL_TEXTURE_2D);</p>
<p>	glColor4ub( r, g, b, opacity);</p>
<p>	if (scaleMode == scalemode_crop)<br />
		[texture drawAtPoint: CGPointZero withScale: curScale];<br />
	else<br />
		[texture drawAtPoint: CGPointZero withScaleStretch: curScale];</p>
<p>	glColor4ub( 255, 255, 255, 255);</p>
<p>	glDisable( GL_TEXTURE_2D);</p>
<p>	glDisableClientState(GL_VERTEX_ARRAY );<br />
	glDisableClientState( GL_TEXTURE_COORD_ARRAY );<br />
}</p>
<p>On Sat, Jun 20, 2009 at 12:33 AM,<br />
&#60;cocos2d-iphone-discuss@gamesforfood.cl&#62; wrote:<br />
&#62; woonsung says:<br />
&#62;<br />
&#62; Cut to the desired size of a sprite can draw?<br />
&#62;<br />
&#62; If you have an image of size 100 * 100<br />
&#62; However, and I want to size 80 * 100.<br />
&#62;<br />
&#62; Using images such as time bar.<br />
&#62; Do you understand?<br />
&#62;<br />
&#62; ;)<br />
&#62;<br />
&#62; Sprite *Box = [Sprite spriteWithFile:@&#34;box.png&#34;];<br />
&#62;<br />
&#62; [Box setPosition:ccp(160, 240)];<br />
&#62; [self addChild:Box z:1];<br />
&#62;<br />
&#62; Read the whole thread.
</p></description>
		</item>
		<item>
			<title>Codemattic on "Sprite Crop"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/202#post-1067</link>
			<pubDate>Sat, 20 Jun 2009 05:07:51 +0000</pubDate>
			<dc:creator>Codemattic</dc:creator>
			<guid isPermaLink="false">1067@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I dont know how to crop!  But maybe you can scale your image?</p>
<p>Box.scaleX=0.8;<br />
Box.scaleY=1.0;
</p></description>
		</item>
		<item>
			<title>woonsung on "Sprite Crop"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/202#post-1065</link>
			<pubDate>Sat, 20 Jun 2009 04:32:44 +0000</pubDate>
			<dc:creator>woonsung</dc:creator>
			<guid isPermaLink="false">1065@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Cut to the desired size of a sprite can draw?</p>
<p>If you have an image of size 100 * 100<br />
However, and I want to size 80 * 100.</p>
<p>Using images such as time bar.<br />
Do you understand?</p>
<p>;)</p>
<p>Sprite *Box = [Sprite spriteWithFile:@"box.png"];</p>
<p>[Box setPosition:ccp(160, 240)];<br />
[self addChild:Box z:1];
</p></description>
		</item>

	</channel>
</rss>

