<?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; Tag: sprite - Recent Topics</title>
		<link>http://www.cocos2d-iphone.org/forum/tags/sprite</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 04:04:47 +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/tags/sprite/topics" rel="self" type="application/rss+xml" />

		<item>
			<title>Birkemose on "[code] Water ripples"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25090#post-131291</link>
			<pubDate>Sun, 04 Dec 2011 14:43:20 +0000</pubDate>
			<dc:creator>Birkemose</dc:creator>
			<guid isPermaLink="false">131291@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi<br />
I was looking for a way to make ripples, but couldn't really find anything other than an old demo, featuring incredible long tables. Yuk.<br />
So in stead I toyed around, and made my own.</p>
<p><a href="http://www.youtube.com/user/BackfireE?feature=mhee#p/a/u/0/d5ijwDEfZSw" rel="nofollow">http://www.youtube.com/user/BackfireE?feature=mhee#p/a/u/0/d5ijwDEfZSw</a></p>
<p>I made a rippleSprite, working more or less the same as a normal CCSprite. I haven't added transformations, because at this point I don't need them, but that shouldn't be to hard.<br />
Otherwise you create it much like any other sprite.</p>
<pre><code>rippleImage = [ pgeRippleSprite ripplespriteWithFile:@&#34;image.png&#34; ];
[ self addChild:rippleImage ];</code></pre>
<p>Then you add ripples to the image<br />
<pre><code>[ rippleImage addRipple:pos type:RIPPLE_TYPE_WATER strength:1.0f ];</code></pre>
<p>and update the image each frame<br />
<pre><code>[ rippleImage update:dt ];</code></pre>
<p>And that is it.</p>
<p>The rippleSprite class is as follows</p>
<pre><code>//
//  pgeRippleSprite.h
//  rippleDemo
//
//  Created by Lars Birkemose on 02/12/11.
//  Copyright 2011 Protec Electronics. All rights reserved.
//
// --------------------------------------------------------------------------
// import headers

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#60;Foundation/Foundation.h&#62;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;cocos2d.h&#34;

// --------------------------------------------------------------------------
// defines

#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> RIPPLE_DEFAULT_QUAD_COUNT_X             30
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> RIPPLE_DEFAULT_QUAD_COUNT_Y             20 

#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> RIPPLE_BASE_GAIN                        0.1f        // an internal constant

#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> RIPPLE_DEFAULT_RADIUS                   800         // radius in pixels
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> RIPPLE_DEFAULT_RIPPLE_CYCLE             0.2f        // timing on ripple ( 1/frequenzy )
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> RIPPLE_DEFAULT_LIFESPAN                 3.0f        // entire ripple lifespan

// --------------------------------------------------------------------------
// typedefs

typedef enum {
    RIPPLE_TYPE_RUBBER,                                     // a soft rubber sheet
    RIPPLE_TYPE_GEL,                                        // high viscosity fluid
    RIPPLE_TYPE_WATER,                                      // low viscosity fluid
} RIPPLE_TYPE;

typedef struct _rippleData {
    RIPPLE_TYPE             rippleType;                     // type of ripple ( se update: )
    CGPoint                 center;                         // ripple center ( but you just knew that, didn&#039;t you? )
    CGPoint                 centerCoordinate;               // ripple center in texture coordinates
    float                   radius;                         // radius at which ripple has faded 100%
    float                   strength;                       // ripple strength
    float                   runtime;                        // current run time
    float                   currentRadius;                  // current radius
    float                   rippleCycle;                    // ripple cycle timing
    float                   lifespan;                       // total life span
} rippleData;

// --------------------------------------------------------------------------
// interface

@interface pgeRippleSprite : CCNode {
    CCTexture2D*            m_texture;
    int                     m_quadCountX;                   // quad count in x and y direction
    int                     m_quadCountY;
    int                     m_VerticesPrStrip;              // number of vertices in a strip
    int                     m_bufferSize;                   // vertice buffer size
    CGPoint*                m_vertice;                      // vertices
    CGPoint*                m_textureCoordinate;            // texture coordinates ( original )
    CGPoint*                m_rippleCoordinate;             // texture coordinates ( ripple corrected )
    bool*                   m_edgeVertice;                  // vertice is a border vertice
    NSMutableArray*         m_rippleList;                   // list of running ripples
}

// --------------------------------------------------------------------------
// properties

// --------------------------------------------------------------------------
// methods

+( pgeRippleSprite* )ripplespriteWithFile:( NSString* )filename;
-( pgeRippleSprite* )initWithFile:( NSString* )filename;
-( void )tesselate;
-( void )addRipple:( CGPoint )pos type:( RIPPLE_TYPE )type strength:( float )strength;
-( void )update:( ccTime )dt;

// --------------------------------------------------------------------------

@end</code></pre>
<p>And the meat</p>
<pre><code>//
//  pgeRippleSprite.m
//  rippleDemo
//
//  Created by Lars Birkemose on 02/12/11.
//  Copyright 2011 Protec Electronics. All rights reserved.
//
// --------------------------------------------------------------------------
// import headers

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;pgeRippleSprite.h&#34;

// --------------------------------------------------------------------------
// implementation

@implementation pgeRippleSprite

// --------------------------------------------------------------------------
// properties

// --------------------------------------------------------------------------
// methods
// --------------------------------------------------------------------------

+( pgeRippleSprite* )ripplespriteWithFile:( NSString* )filename {
	return [ [ [ self alloc ] initWithFile:filename ] autorelease ];
}

// --------------------------------------------------------------------------

-( pgeRippleSprite* )initWithFile:( NSString* )filename {
    self = [ super init ];
    // load texture
    m_texture = [ [ CCTextureCache sharedTextureCache ] addImage: filename ];
    // reset internal data
    m_vertice = nil;
    m_textureCoordinate = nil;
    // builds the vertice and texture-coordinates arrays
    m_quadCountX = RIPPLE_DEFAULT_QUAD_COUNT_X;
    m_quadCountY = RIPPLE_DEFAULT_QUAD_COUNT_Y;
    [ self tesselate ];

    // create ripple list
    m_rippleList = [ [ [ NSMutableArray alloc ] init ] retain ];
    // done
    return( self );
}

// --------------------------------------------------------------------------

-( void )draw {
    // skip is not visible
    if ( self.visible == NO ) return;

    // add transformations
    glPushMatrix( );

    // well, I dont really need transformations on my ripples, so I will leave this part to you
    // but I added push and pop - just to be nice

    // set states
    glDisableClientState( GL_COLOR_ARRAY );

    // and plx, dont just draw anything
    glBindTexture( GL_TEXTURE_2D, [ m_texture name ] ); 

    // set texture coordinates
    // if no ripples running, use original coordinates ( Yay, dig that kewl old school C syntax )
    glTexCoordPointer( 2, GL_FLOAT, 0, ( m_rippleList.count == 0 ) ? m_textureCoordinate : m_rippleCoordinate );

    // set vertice pointer
    glVertexPointer( 2, GL_FLOAT, 0, m_vertice );

    // draw as many triangle fans, as quads in y direction
    // ( I guess traditional mongolians, would have made it vertical fans, but here I am, sitting in western Europa )
    for ( int strip = 0; strip &#60; m_quadCountY; strip ++ ) {
        glDrawArrays( GL_TRIANGLE_STRIP, strip * m_VerticesPrStrip, m_VerticesPrStrip );
    }

    // reset any state altered ( Riq wants us to )
    glEnableClientState( GL_COLOR_ARRAY );

    // restore
    glPopMatrix( );
}

// --------------------------------------------------------------------------

-( void )dealloc {
    rippleData* runningRipple;

    // clean up buffers
    free( m_vertice );
    free( m_textureCoordinate );
    free( m_rippleCoordinate );
    free( m_edgeVertice );

    // clean up running ripples
    for ( int count = 0; count &#60; m_rippleList.count; count ++ ) {

        // get a pointer and free manually, as data was allocated manually
        // a void pointer would do, but this adds readability at no expense
        runningRipple = ( rippleData* )[ [ m_rippleList objectAtIndex:count ] pointerValue ];
        free( runningRipple );

    }

    // delete list
    [ m_rippleList release ];

    // done
    [ super dealloc ];
}

// --------------------------------------------------------------------------
// tesselation is expensive

-( void )tesselate {
    int vertexPos = 0;
    CGPoint normalized;

    // clear buffers ( yeah, clearing nil buffers first time around )
    free( m_vertice );
    free( m_textureCoordinate );
    free( m_rippleCoordinate );
    free( m_edgeVertice );

    // calculate vertices pr strip
    m_VerticesPrStrip = 2 * ( m_quadCountX + 1 );

    // calculate buffer size
    m_bufferSize = m_VerticesPrStrip * m_quadCountY;

    // allocate buffers
    m_vertice = malloc( m_bufferSize * sizeof( CGPoint ) );
    m_textureCoordinate = malloc( m_bufferSize * sizeof( CGPoint ) );
    m_rippleCoordinate = malloc( m_bufferSize * sizeof( CGPoint ) );
    m_edgeVertice = malloc( m_bufferSize * sizeof( bool ) );

    // reset vertice pointer
    vertexPos = 0;

    // create all vertices and default texture coordinates
    // scan though y quads, and create an x-oriented triangle strip for each
    for ( int y = 0; y &#60; m_quadCountY; y ++ ) {

        // x counts to quadcount + 1, because number of vertices is number of quads + 1
        for ( int x = 0; x &#60; ( m_quadCountX + 1 ); x ++ ) {

            // for each x vertex, an upper and lower y position is calculated, to create the triangle strip
            // upper + lower + upper + lower
            for ( int yy = 0; yy &#60; 2; yy ++ ) {

                // first simply calculate a normalized position into rectangle
                normalized.x = ( float )x / ( float )m_quadCountX;
                normalized.y = ( float )( y + yy ) / ( float )m_quadCountY;

                // calculate vertex by multiplying rectangle ( texture ) size
                m_vertice[ vertexPos ] = ccp( normalized.x * m_texture.pixelsWide, normalized.y * m_texture.pixelsHigh );

                // adjust texture coordinates according to texture size
                // as a texture is always in the power of 2, maxS and maxT are the fragment of the size actually used
                // invert y on texture coordinates
                m_textureCoordinate[ vertexPos ] = ccp( normalized.x * m_texture.maxS, m_texture.maxT - ( normalized.y * m_texture.maxT ) );

                // check if vertice is an edge vertice, because edge vertices are never modified to keep outline consistent
                m_edgeVertice[ vertexPos ] = (
                                              ( x == 0 ) &#124;&#124;
                                              ( x == m_quadCountX ) &#124;&#124;
                                              ( ( y == 0 ) &#38;&#38; ( yy == 0 ) ) &#124;&#124;
                                              ( ( y == ( m_quadCountY - 1 ) ) &#38;&#38; ( yy &#62; 0 ) ) );

                // next buffer pos
                vertexPos ++;

            }
        }
    }
}

// --------------------------------------------------------------------------
// adds a ripple to list of running ripples
// higher strength result in more distinct ripples

-( void )addRipple:( CGPoint )pos type:( RIPPLE_TYPE )type strength:( float )strength {
    rippleData* newRipple;

    // allocate new ripple
    newRipple = malloc( sizeof( rippleData ) );

    // initialize ripple
    newRipple-&#62;rippleType = type;
    newRipple-&#62;center = pos;
    newRipple-&#62;centerCoordinate = ccp( pos.x / m_texture.pixelsWide * m_texture.maxS, m_texture.maxT - ( pos.y / m_texture.pixelsHigh * m_texture.maxT ) );
    newRipple-&#62;radius = RIPPLE_DEFAULT_RADIUS;
    newRipple-&#62;strength = strength;
    newRipple-&#62;runtime = 0;
    newRipple-&#62;currentRadius = 0;
    newRipple-&#62;rippleCycle = RIPPLE_DEFAULT_RIPPLE_CYCLE;
    newRipple-&#62;lifespan = RIPPLE_DEFAULT_LIFESPAN;

    // add ripple to running list
	[ m_rippleList addObject:[ NSValue valueWithPointer:newRipple ] ];

}

// --------------------------------------------------------------------------
// update any running ripples
// it is parents responsibility to call the method with appropriate intervals

-( void )update:( ccTime )dt {
    rippleData* ripple;
    CGPoint pos;
    float distance, correction;

    // test if any ripples at all
    if ( m_rippleList.count == 0 ) return;

    // ripples are simulated by altering texture coordinates
    // on all updates, an entire new array is calculated from the base array
    // not maintainng an original set of texture coordinates, could result in accumulated errors
    memcpy( m_rippleCoordinate, m_textureCoordinate, m_bufferSize * sizeof( CGPoint ) );

    // scan through running ripples
    // the scan is backwards, so that ripples can be removed on the fly
    for ( int count = ( m_rippleList.count - 1 ); count &#62;= 0; count -- ) {

        // get ripple data
        ripple = ( rippleData* )[ [ m_rippleList objectAtIndex:count ] pointerValue ];

        // scan through all texture coordinates
        for ( int count = 0; count &#60; m_bufferSize; count ++ ) {

            // dont modify edge vertices
            if ( m_edgeVertice[ count ] == NO ) {

                // calculate distance
                // you might think it would be faster to do a box check first
                // but it really isnt,
                // ccpDistance is like my sexlife - BAM! - and its all over
                distance = ccpDistance( ripple-&#62;center, m_vertice[ count ] );

                // only modify vertices within range
                if ( distance &#60;= ripple-&#62;currentRadius ) {

                    // load the texture coordinate into an easy to use var
                    pos = m_rippleCoordinate[ count ];  

                    // calculate a ripple
                    switch ( ripple-&#62;rippleType ) {

                        case RIPPLE_TYPE_RUBBER:
                            // method A
                            // calculate a sinus, based only on time
                            // this will make the ripples look like poking a soft rubber sheet, since sinus position is fixed
                            correction = sinf( 2 * M_PI * ripple-&#62;runtime / ripple-&#62;rippleCycle );
                            break;

                        case RIPPLE_TYPE_GEL:
                            // method B
                            // calculate a sinus, based both on time and distance
                            // this will look more like a high viscosity fluid, since sinus will travel with radius
                            correction = sinf( 2 * M_PI * ( ripple-&#62;currentRadius - distance ) / ripple-&#62;radius * ripple-&#62;lifespan / ripple-&#62;rippleCycle );
                            break;

                        case RIPPLE_TYPE_WATER:
                        default:
                            // method c
                            // like method b, but faded for time and distance to center
                            // this will look more like a low viscosity fluid, like water     

                            correction = ( ripple-&#62;radius * ripple-&#62;rippleCycle / ripple-&#62;lifespan ) / ( ripple-&#62;currentRadius - distance );
                            if ( correction &#62; 1.0f ) correction = 1.0f;

                            // fade center of quicker
                            correction *= correction;

                            correction *= sinf( 2 * M_PI * ( ripple-&#62;currentRadius - distance ) / ripple-&#62;radius * ripple-&#62;lifespan / ripple-&#62;rippleCycle );
                            break;

                    }

                    // fade with distance
                    correction *= 1 - ( distance / ripple-&#62;currentRadius );

                    // fade with time
                    correction *= 1 - ( ripple-&#62;runtime / ripple-&#62;lifespan );

                    // adjust for base gain and user strength
                    correction *= RIPPLE_BASE_GAIN;
                    correction *= ripple-&#62;strength;

                    // finally modify the coordinate by interpolating
                    // because of interpolation, adjustment for distance is needed,
                    correction /= ccpDistance( ripple-&#62;centerCoordinate, pos );
                    pos = ccpAdd( pos, ccpMult( ccpSub( pos, ripple-&#62;centerCoordinate ), correction ) );

                    // another approach for applying correction, would be to calculate slope from center to pos
                    // and then adjust based on this

                    // clamp texture coordinates to avoid artifacts
                    pos = ccpClamp( pos, CGPointZero, ccp( m_texture.maxS, m_texture.maxT ) );

                    // save modified coordinate
                    m_rippleCoordinate[ count ] = pos;

                }
            }
        }

        // calculate radius
        ripple-&#62;currentRadius = ripple-&#62;radius * ripple-&#62;runtime / ripple-&#62;lifespan;

        // check if ripple should expire
        ripple-&#62;runtime += dt;
        if ( ripple-&#62;runtime &#62;= ripple-&#62;lifespan ) {

            // free memory, and remove from list
            free( ripple );
            [ m_rippleList removeObjectAtIndex:count ];

        }

    }
}

// --------------------------------------------------------------------------

@end</code></pre></description>
		</item>
		<item>
			<title>ignazioc on "texture atlas and npot sprite"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28966#post-142774</link>
			<pubDate>Sun, 05 Feb 2012 20:37:56 +0000</pubDate>
			<dc:creator>ignazioc</dc:creator>
			<guid isPermaLink="false">142774@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hi, if i use a software to pack my texture in a one big texture atlas 1024x1024 can i create my single sprite in any dimension without waste memory?<br />
i know that cocos2d 1.1 use npot texture by default...this mean that my texture atlas can be 1030x1030 without problems?
</p></description>
		</item>
		<item>
			<title>Seerex on "[SOLVED] Only display 1 of 2 layers on scene?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28936#post-142629</link>
			<pubDate>Sat, 04 Feb 2012 07:40:46 +0000</pubDate>
			<dc:creator>Seerex</dc:creator>
			<guid isPermaLink="false">142629@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>[ANSWER]</p>
<p>Oh well, i actually send the shared directer runWithScene: and passed in a layer, not a scene. To my surprise, this actually worked? So, the sharedDirector can't tell the difference between a scene or layer i guess? </p>
<p>Hi all,</p>
<p>I'm reading through a book on cocos2d, and the second chapter puzzles me. I created 2 layers, one containing a sprite as a character, the other a sprite as background. I then create a game scene that adds the 2 layers as childs in the init method. I then redirect the CCDirecter sharedDirector in the appDelegate.m to load in the gameScene. Now, i get displayed the layer showing the game scene, but not the background? any particular reason for this? Here are the code:</p>
<p>@implementation BackgroundLayer</p>
<p>-(id) init {<br />
    self = [super init];<br />
    if (self) {<br />
        CCSprite *backgroundImage;<br />
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {<br />
            // Indicate game is running on ipad<br />
            backgroundImage = [CCSprite spriteWithFile:@"background.png"];<br />
        } else {<br />
            backgroundImage = [CCSprite spriteWithFile:@"backgroundiPhone.png"];<br />
        }</p>
<p>        CGSize screenSize = [[CCDirector sharedDirector] winSize];<br />
        [backgroundImage setPosition:CGPointMake(screenSize.width/2, screenSize.height/2)];</p>
<p>        [self addChild:backgroundImage z:0 tag:0];<br />
    }</p>
<p>    return self;<br />
}</p>
<p>@implementation GameplayLayer</p>
<p>-(id) init {<br />
    self = [super init];<br />
    if (self) {<br />
        CGSize screenSize = [CCDirector sharedDirector].winSize;<br />
        // enable touches<br />
        self.isTouchEnabled = YES;<br />
        vikingSprite = [CCSprite spriteWithFile:@"sv_anim_1.png"];<br />
        [vikingSprite setPosition:CGPointMake(screenSize.width/2, screenSize.height*0.17f)];</p>
<p>        [self addChild:vikingSprite];</p>
<p>        if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {<br />
            // if NOT for the ipad, scale down ole<br />
            // in games, use this to load art sized for the device<br />
            [vikingSprite setScaleX:screenSize.width/1024.0f];<br />
            [vikingSprite setScaleY:screenSize.height/768.0f];<br />
        }<br />
    }</p>
<p>    return self;<br />
}</p>
<p>@implementation GameScene</p>
<p>-(id) init {<br />
    self = [super init];<br />
    if (self) {<br />
        // bacground layer<br />
        BackgroundLayer *backgroundLayer = [BackgroundLayer node];<br />
        [self addChild:backgroundLayer z:0];<br />
        // Gameplay layer<br />
        GameplayLayer *gameplayLayer = [GameplayLayer node];<br />
        [self addChild:gameplayLayer z:5];<br />
    }</p>
<p>    return self;<br />
}</p>
<p>Thanks on advance
</p></description>
		</item>
		<item>
			<title>CAppleton on "Animation sprites not showing"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28802#post-141914</link>
			<pubDate>Mon, 30 Jan 2012 22:53:57 +0000</pubDate>
			<dc:creator>CAppleton</dc:creator>
			<guid isPermaLink="false">141914@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi everyone, I apologise if this sort of thread has been posted and discussed but i could not see it when i looked, I am pretty new to cocos2d and this is the first time I have done any animations on it. I have created a valid plise and png with the same file name and added them to my project, i then have the following code in my class to setup the animation of the sprite in it:</p>
<p>CCSpriteFrameCache* framecache = [CCSpriteFrameCache sharedSpriteFrameCache];</p>
<p>        CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"SnakeAnimation.png"];<br />
        [m_gameScene addChild:spriteSheet];</p>
<p>        [framecache addSpriteFramesWithFile:@"SnakeAnimation.plist"];</p>
<p>        m_sprite = [CCSprite spriteWithSpriteFrameName:@"Snake2.png"];<br />
        [spriteSheet addChild:m_sprite];</p>
<p>        NSMutableArray* animFrames = [NSMutableArray array];<br />
        for(int i = 0; i &#60; 7; i++)<br />
        {<br />
            CCSpriteFrame* frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Snake%d.png",i+1]];<br />
            [animFrames addObject:frame];<br />
        }</p>
<p>        CCAnimation *animation = [CCAnimation animationWithFrames:animFrames delay:0.1];</p>
<p>        [m_sprite runAction:[CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:animation] ]];</p>
<p>I have checked the frame cache etc and they are all valid and appear to add the plist etc correctly, however they can never find any of the files and my objects are created on screen without any image what so ever. I'm not sure what else i need to do to get it working so any help would be greatly appreciated!
</p></description>
		</item>
		<item>
			<title>phantomsri on "how to remove a overlapped sprite."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28537#post-140520</link>
			<pubDate>Sat, 21 Jan 2012 10:37:36 +0000</pubDate>
			<dc:creator>phantomsri</dc:creator>
			<guid isPermaLink="false">140520@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi need help,<br />
I have 3 sprites overlapped, with tag 1 to 3.  How i can remove multiple overlapped sprite in a single touch?<br />
I have a loop code below to remove sprite based on tag, its not working. All im getting is that i need to click the same spot 3 times to remove the 3 sprites.</p>
<pre><code>-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* myTouch = [touches anyObject];
    CGPoint location = [myTouch locationInView: [myTouch view]];
    location = [[CCDirector sharedDirector]convertToGL:location];
    location = [self convertToNodeSpace:location];

    int totalNumberOfItems=4;
    for (int y=0; y &#60; totalNumberOfItems; y++){
        CCSprite *temp = (CCSprite*)[self getChildByTag:y];

        CGRect test1 = [temp boundingBox];

        if (CGRectContainsPoint(test1, location)) {
            NSLog(@&#34;touched&#34;);
            [self removeChild:temp cleanup:YES ];
            return;
        }
    }  

}</code></pre></description>
		</item>
		<item>
			<title>KORNMIRZA on "how to use ccfollow and keep the sprite left side?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28778#post-141802</link>
			<pubDate>Mon, 30 Jan 2012 01:42:55 +0000</pubDate>
			<dc:creator>KORNMIRZA</dc:creator>
			<guid isPermaLink="false">141802@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Heloo<br />
as you know ccfollow is moving the sprite to the center of the screen,i want to find a way to hold my sprite in it's position that is left side.<br />
can anyone help me?<br />
thank you in advance
</p></description>
		</item>
		<item>
			<title>Harrison Xi on "How to create white flash effect for sprites?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28478#post-140170</link>
			<pubDate>Thu, 19 Jan 2012 07:52:45 +0000</pubDate>
			<dc:creator>Harrison Xi</dc:creator>
			<guid isPermaLink="false">140170@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have tried to search the answer, but the ways I found do not work very well.</p>
<p>e.g.<br />
<a href="http://www.cocos2d-iphone.org/forum/topic/4363" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/4363</a><br />
[original setBlendFunc: (ccBlendFunc) { GL_SRC_ALPHA, GL_ONE }];</p>
<p>Additive blend cannot white a sprite completely. This is the effect I want:<br />
<img src="http://ww4.sinaimg.cn/mw600/768207d3tw1dp7sfry53vj.jpg" /></p>
<p>Does anyone know how to implement it? Thanks a lot.
</p></description>
		</item>
		<item>
			<title>eJayStudios on "Smooth moving sprite with accelerometer"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28679#post-141318</link>
			<pubDate>Thu, 26 Jan 2012 05:44:39 +0000</pubDate>
			<dc:creator>eJayStudios</dc:creator>
			<guid isPermaLink="false">141318@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,</p>
<p>Looked trough many threads, can't find a solution.<br />
I've implemented accelerometer ala "Tilt to Live",  from <a href="http://www.paradeofrain.com/2010/07/lessons-learned-in-tilt-controls/">here</a></p>
<p>Accelerometer code works very nice, no issue here. But there is 2 strange things:</p>
<p>- first, I downloaded example from link above and little image moves much faster in example project with same settings compared to my project (example project in in OpenGL)<br />
- second, in my game when sprite moves I can see a little trail behind image as if it doesn't refresh nicely, sort of flickering effect.</p>
<p>Basically code is this:</p>
<pre><code>- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
    Vec2 accel2D(0,0);
    Vec3 ax(1, 0, 0);
    Vec3 ay(-.63f, 0,-.92f);
    Vec3 az(Vec3::Cross(ay,ax).normalize());
    ax = Vec3::Cross(az,ay).normalize();
    accel2D.x = -Vec3::Dot(Vec3(acceleration.x, acceleration.y, acceleration.z), ax);
    accel2D.y = -Vec3::Dot(Vec3(acceleration.x, acceleration.y, acceleration.z), az);

    const float xSensitivity = 2.8f;
    const float ySensitivity = 2.8f; // yay magic numbers!
    const float tiltAmplifier = 8; // w0ot more magic numbers

    // since we are in a landscape orientation.
    // now apply it to our player&#039;s velocity data.
    // we also rotate the 2D vector by 90 degrees by switching the components and negating one
    vx += -(accel2D.y) * tiltAmplifier * xSensitivity;
    vy += -accel2D.x * tiltAmplifier * ySensitivity;
}</code></pre>
<p>Then in update I do this:</p>
<pre><code>-(void) update:(ccTime)delta
{
	x += vx;
	y += vy;

	// put the breaks on our velocity.
	vx *= 0.2f;
	vy *= 0.2f;

	//bound the player
	if (x &#62; 460)
	{
		x = 460;
	}
	if( x &#60; 20)
	{
		x = 20;
	}

	if(y &#62; 300)
	{
		y = 300;
	}
	if( y &#60; 20)
	{
		y = 20;
	}

    playerSprite.position = ccp(x, y);
}</code></pre>
<p>Tried with setting animation refresh to 1/30, also accelerometer update interval to 1/30, nothing helps.<br />
If I increase sensitivity via xSensitivity, ySensitivity I can get sprite to move as fast as in example project, but flickering effect is even worse.</p>
<p>Any idea what I'm doing wrong? Why image in my game runs much slower then in example with same settings? Could it be because in cocos2D we have update method?
</p></description>
		</item>
		<item>
			<title>dyulyur on "change one sprite to another"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/11920#post-67233</link>
			<pubDate>Thu, 16 Dec 2010 09:54:32 +0000</pubDate>
			<dc:creator>dyulyur</dc:creator>
			<guid isPermaLink="false">67233@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi, everybody!<br />
I have one sprite (image) and create object</p>
<p>CCSprite* sprite = [CCSprite spriteWithFile:@"first.png"];</p>
<p>I have another image second.png and I want to change image first.png to image second.png for object sprite. Is it impossible to write something like [sprite setSprite:@"second.png"]?
</p></description>
		</item>
		<item>
			<title>polatolu on "Sprite Master"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28564#post-140672</link>
			<pubDate>Sun, 22 Jan 2012 16:42:57 +0000</pubDate>
			<dc:creator>polatolu</dc:creator>
			<guid isPermaLink="false">140672@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi Guys,</p>
<p>I want to talk about Sprite Master. Sprite Master is a sprite sheet generator for Mac. It generates sprite sheets using Basic and MaxRects algorithms. Also, generates coordinate data, exports .plist for Cocos2D.</p>
<p>If you are interested, you can take a look at <a href="http://www.mobinodo.com/spritemaster" rel="nofollow">http://www.mobinodo.com/spritemaster</a> for more details.
</p></description>
		</item>
		<item>
			<title>Jamorn on "CCMenuItemLabelAndImage"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19789#post-110752</link>
			<pubDate>Mon, 15 Aug 2011 18:43:32 +0000</pubDate>
			<dc:creator>Jamorn</dc:creator>
			<guid isPermaLink="false">110752@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi guys, I've been using cocos2d for a while (still learning) but I've just created a class that I needed which is:</p>
<p>A menu item that uses a Label (text) as well as Images so that you can use normal image, selected image, and disabled image. This is so you can create buttons with labels dynamically instead of making a 1000 buttons in photoshop by just changing its text.</p>
<p>If you observe, the text label actually moves down by 1 pixel when you press the menu item, that's meant to happen, to simulate the button being pressed.</p>
<p>The class is created as a cross between CCMenuItemLabel and CCMenuItemImage. It is in fact a child of the CCMenuItemImage and I've added the label capability within.</p>
<p>Maybe this has been created already but I couldn't find it. I hope people can benefit from this :) It works really well for me.</p>
<p><strong>CCMenuItemLabelAndImage.h</strong><br />
<pre><code>/*
 * CCMenuItemLabelAndImage
 *
 * Copyright (c) 2011 Jamorn Horathai
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the &#34;Software&#34;), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#60;Foundation/Foundation.h&#62;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;cocos2d.h&#34;

@interface CCMenuItemLabelAndImage : CCMenuItemImage {
    CCNode&#60;CCLabelProtocol, CCRGBAProtocol&#62; *label_;
	ccColor3B	colorBackup;
	ccColor3B	disabledColor_;
}

/** the color that will be used to disable the item */
@property (nonatomic,readwrite) ccColor3B disabledColor;

/** Label that is rendered. It can be any CCNode that implements the CCLabelProtocol */
@property (nonatomic,readwrite,assign) CCNode&#60;CCLabelProtocol, CCRGBAProtocol&#62;* label;

/** creates a menu item with a label and a normal and selected image*/
+ (id) itemWithLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage:(NSString*)value selectedImage:(NSString*) value2;
/** creates a menu item with a label and a normal and selected image with target/selector */
+(id) itemFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*)value selectedImage:(NSString*) value2 target:(id) r selector:(SEL) s;
/** creates a menu item with a label and a normal,selected  and disabled image */
+(id) itemFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage: (NSString*) value3;
/** creates a menu item with a label and a normal,selected  and disabled image with target/selector */
+(id) itemFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s;
/** initializes a menu item with a label and a normal, selected  and disabled image with target/selector */
-(id) initFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s;
#<a href='http://www.cocos2d-iphone.org/forum/tags/if'>if</a> NS_BLOCKS_AVAILABLE
/** creates a menu item with a label and a normal and selected image with a block.
 The block will be &#34;copied&#34;.
 */
+(id) itemFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*)value selectedImage:(NSString*) value2 block:(void(^)(id sender))block;
/** creates a menu item with a label and a normal,selected  and disabled image with a block.
 The block will be &#34;copied&#34;.
 */
+(id) itemFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block;
/** initializes a menu item with a label and a normal, selected  and disabled image with a block.
 The block will be &#34;copied&#34;.
 */
-(id) initFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block;
#endif

/** sets a new string to the inner label */
-(void) setString:(NSString*)label;

/** Enable or disabled the CCMenuItemFont
 @warning setIsEnabled changes the RGB color of the font
 */
-(void) setIsEnabled: (BOOL)enabled;

@end</code></pre>
<p><strong>CCMenuItemLabelAndImage.m</strong><br />
<pre><code>/*
 * CCMenuItemLabelAndImage
 *
 * Copyright (c) 2011 Jamorn Horathai
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the &#34;Software&#34;), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCMenuItemLabelAndImage.h&#34;

@interface CCMenuItemLabelAndImage()

- (void) repositionLabel;

@end

@implementation CCMenuItemLabelAndImage

@synthesize disabledColor = disabledColor_;

+ (id) itemWithLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage:(NSString*)value selectedImage:(NSString*) value2
{
    return [self itemFromLabel:label normalImage:value selectedImage:value2 disabledImage:nil target:nil selector:nil];
}

+(id) itemFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*)value selectedImage:(NSString*) value2 target:(id) r selector:(SEL) s
{
    return [self itemFromLabel:label normalImage:value selectedImage:value2 disabledImage:nil target:r selector:s];
}

+(id) itemFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage: (NSString*) value3
{
    return [[[self alloc] initFromLabel:label normalImage:value selectedImage:value2 disabledImage:value3 target:nil selector:nil] autorelease];
}

+(id) itemFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s
{
    return [[[self alloc] initFromLabel:label normalImage:value selectedImage:value2 disabledImage:value3 target:r selector:s] autorelease];
}

-(id) initFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 target:(id) r selector:(SEL) s
{
    if ((self = [super initFromNormalImage:value selectedImage:value2 disabledImage:value3 target:r selector:s])) {
        colorBackup = ccWHITE;
        disabledColor_ = ccWHITE;
        self.label = label;
    }
    return self;
}

#<a href='http://www.cocos2d-iphone.org/forum/tags/if'>if</a> NS_BLOCKS_AVAILABLE

+(id) itemFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*)value selectedImage:(NSString*) value2 block:(void(^)(id sender))block
{
    return [self itemFromLabel:label normalImage:value selectedImage:value2 disabledImage:nil block:block];
}

+(id) itemFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*)value selectedImage:(NSString*) value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block
{
    return [[[self alloc] initFromLabel:label normalImage:value selectedImage:value2 disabledImage:value3 block:block] autorelease];
}

-(id) initFromLabel:(CCNode&#60;CCLabelProtocol,CCRGBAProtocol&#62;*)label normalImage: (NSString*) value selectedImage:(NSString*)value2 disabledImage:(NSString*) value3 block:(void(^)(id sender))block
{
    block_ = [block copy];
    return [self initFromLabel:label normalImage:value selectedImage:value2 disabledImage:value3 target:block_ selector:@selector(ccCallbackBlockWithSender:)];
}
#endif // NS_BLOCKS_AVAILABLE

-(CCNode&#60;CCLabelProtocol, CCRGBAProtocol&#62;*) label
{
	return label_;
}
-(void) setLabel:(CCNode&#60;CCLabelProtocol, CCRGBAProtocol&#62;*) label
{
	if( label != label_ ) {
		[self removeChild:label_ cleanup:YES];
		[self addChild:label];

		label_ = label;

        [self repositionLabel];
	}
}

-(void) setString:(NSString *)string
{
	[label_ setString:string];
    [self repositionLabel];
}

-(void) setPosition:(CGPoint)position
{
    [super setPosition:position];
    [self repositionLabel];
}

-(void) repositionLabel
{
    label_.position = ccp(normalImage_.position.x + normalImage_.contentSize.width/2, normalImage_.position.y + normalImage_.contentSize.height/2);
}

-(void) selected
{
	// subclass to change the default action
	if(isEnabled_) {
		[super selected];
        // Move the label down 1 point to look like the button&#39;s pressed.
        label_.position = ccp(label_.position.x, label_.position.y-1);
	}
}

-(void) unselected
{
	// subclass to change the default action
	if(isEnabled_) {
		[super unselected];
        // Move the label back up
		label_.position = ccp(label_.position.x, label_.position.y+1);
	}
}

-(void) setIsEnabled: (BOOL)enabled
{
	if( isEnabled_ != enabled ) {
		if(enabled == NO) {
			colorBackup = [label_ color];
			[label_ setColor: disabledColor_];
		}
		else
			[label_ setColor:colorBackup];
	}

	[super setIsEnabled:enabled];
}

- (void) setOpacity: (GLubyte)opacity
{
    [label_ setOpacity:opacity];
}
-(GLubyte) opacity
{
	return [label_ opacity];
}
-(void) setColor:(ccColor3B)color
{
	[label_ setColor:color];
}
-(ccColor3B) color
{
	return [label_ color];
}

@end</code></pre></description>
		</item>
		<item>
			<title>NOG on "Issues using convertToNodeSpace from a method call in init"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28525#post-140430</link>
			<pubDate>Fri, 20 Jan 2012 17:00:28 +0000</pubDate>
			<dc:creator>NOG</dc:creator>
			<guid isPermaLink="false">140430@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have a sprite added from a method call in init using convertToNodeSpace, and it is placing it incorrectly.  I use practically use the same code elsewhere to place sprites with convertToNodeSpace (placing it in the center of the iPad screen) and it works fine. </p>
<p>My guess is before init returns self, convertToNodeSpace cannot make an accurate conversion.  Is this the problem most likely, and is there any known solutions?
</p></description>
		</item>
		<item>
			<title>davidthecoder on "Sprite Not Appearing? please help"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28520#post-140392</link>
			<pubDate>Fri, 20 Jan 2012 12:16:36 +0000</pubDate>
			<dc:creator>davidthecoder</dc:creator>
			<guid isPermaLink="false">140392@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have a sprite that is called out on my gamelayer from another file using this method,<br />
(it is called when two specific objects collide, it checks for collision from within the character file)</p>
<p>character.mm</p>
<pre><code>....
 gamelayer * pl = [gamelayer alloc];

 [pl spawnSprite];
..</code></pre>
<p>this is what is in the gamelayer..<br />
<pre><code>-(void)spawnSprite{

    CCLOG(@&#34;Spawning sprite..&#34;);
    [self createSpriteAtLocation:ccp(130,130)];
}</code></pre>
<p>pretty basic stuff, the two objects collide, it is visible that they have collided,<br />
the console outputs "Spawning sprite.." so i know that the method is working,<br />
but for some odd reason the sprite is not visible on the screen.</p>
<p>i removed the entire method and added " [self createSpriteAtLocation:ccp(130,130)]; "<br />
directly into the gamelayers init and to my surprise the sprite spawns and is visible! :O</p>
<p>this has kept me up all night and confused );</p>
<p>is there anybody in the community that can try to help me, or give me a method that might work?</p>
<p>-thank you for your time.<br />
p.s I am actually trying to get a b2body character to spawn on collision but after a series of test i ended up using a sprite; the outcome is the same.
</p></description>
		</item>
		<item>
			<title>aramk on "Limiting Sprite Displacement Based On Delta"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28486#post-140203</link>
			<pubDate>Thu, 19 Jan 2012 13:43:52 +0000</pubDate>
			<dc:creator>aramk</dc:creator>
			<guid isPermaLink="false">140203@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have a sprite X which moves around as fast or slow as it likes. I have another sprite Y which moves around based on X's movement, however, it can only move at a maximum velocity. Velocity is <code>displacement/time</code>, and time here is the delta from the update: call. If I want a velocity of arbitrary value 5, then I read in X's displacement and the delta, and then my Y's <code>maxDispacement = velocityX * delta</code>. This means that if delta is very small, our Y has a smaller maximum displacement, whereas when we have a large delta, we can afford to move further and still maintain the same maximum velocity.</p>
<p>The issue arises when delta begins to fluctuate. If I am at a maximum displacement of 10, and delta drops, then the maximum displacement becomes 8, and Y slows down on the screen with a jitter. This shouldn't happen from what I can tell, because if delta fell, then it would mean X would move less in this update round than it did in the previous, so I should see a continuous motion for Y as well. And yet, every time delta falls and my maximum displacement reduces, the smooth motion of Y is cut short. Is there a noticeable flaw in my logic?
</p></description>
		</item>
		<item>
			<title>jarodl on "Displaying CCSprite/CCLabelTTF on sides of cube"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28392#post-139772</link>
			<pubDate>Tue, 17 Jan 2012 01:04:17 +0000</pubDate>
			<dc:creator>jarodl</dc:creator>
			<guid isPermaLink="false">139772@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'm trying to add a CCSprite and a CCLabelTTF to the side of a cube and have it use the proper perspective as it rotates. I started by trying to add a CC3Billboard to the side of a CC3BoxNode.</p>
<pre><code>// Make a simple box template available. Only 6 faces per node.
CC3BoxNode *mn = [CC3BoxNode nodeWithName:kBoxName];
CC3BoundingBox bBox;
bBox.minimum = cc3v(-100.0f, -100.0f, -100.0f);
bBox.maximum = cc3v( 100.0f,  100.0f,  100.0f);
mn.uniformScale = 5.0f;
mn.material = [CC3Material material];
mn.isTouchEnabled = YES;
CCLabelTTF *testLabel = [CCLabelTTF labelWithString:@&#34;TestBB&#34;
                                           fontName:kStandardFontName
                                             fontSize:30.0f];
CC3Billboard *bb = [CC3Billboard nodeWithName:@&#34;TestBB&#34; withBillboard:testLabel];
bb.color = ccYELLOW;
bb.shouldUseLighting = NO;
bb.zOrder = -1;
bb.shouldDrawAs2DOverlay = YES;
bb.location = cc3v( 0.0, 80.0, 0.0 );
bb.unityScaleDistance = 425.0;
bb.offsetPosition = ccp( 0.0, 15.0 );
[mn addChild:bb];
[mn populateAsSolidBox:bBox];</code></pre>
<p>I'm using the sample project titled CC3Demo3DTiles as a starting point and not much else has changed. I'm doing this in the <code>initializeTemplates</code> method.
</p></description>
		</item>
		<item>
			<title>SimzStudios on "Set No Gravity In Chipmunk/Spacemanager"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28417#post-139860</link>
			<pubDate>Tue, 17 Jan 2012 15:50:43 +0000</pubDate>
			<dc:creator>SimzStudios</dc:creator>
			<guid isPermaLink="false">139860@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have been searching these forums for this answer but cannot seem to find what I am looking for. I would like to create a game that is of the Brick Breaker type where there is NO GRAVITY. Any help would be greatly appreciated! I am using SpaceManager/Chipmunk</p>
<p>Thank you in advance.</p>
<p>S.Studios
</p></description>
		</item>
		<item>
			<title>Matt Welch on "Z-Order of sprites on ancestor/child nodes"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28318#post-139332</link>
			<pubDate>Fri, 13 Jan 2012 03:18:01 +0000</pubDate>
			<dc:creator>Matt Welch</dc:creator>
			<guid isPermaLink="false">139332@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I've got a layer with a sprite (let's call it sprite A) on it, plus a menu with CCMenuItemImages. I've got the z-order on Sprite A set way high, so the CCMenuItemImage sprites will be obscured by it. (The menu can move around in certain situations). However, I'm trying to pop the CCMenuItemImage sprites ABOVE Sprite A in other situations. I've tried [self reorderChild]ing the CCMenu, the CCMenuItemImage, and the [CCMenuItemImage normalImage], all with no luck. The menu images remain behind Sprite A.</p>
<p>What can I do to get those menu images to pop above Sprite A?</p>
<p>Thanks.
</p></description>
		</item>
		<item>
			<title>cocosbean on "Check sprite texture"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25626#post-133433</link>
			<pubDate>Thu, 15 Dec 2011 03:45:31 +0000</pubDate>
			<dc:creator>cocosbean</dc:creator>
			<guid isPermaLink="false">133433@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have a sprite that will change it's texture multiple times during the game. How do I check which texture it currently has?
</p></description>
		</item>
		<item>
			<title>goodeats2009 on "How to replace Class Name with an NSString?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28153#post-138490</link>
			<pubDate>Sat, 07 Jan 2012 05:33:51 +0000</pubDate>
			<dc:creator>goodeats2009</dc:creator>
			<guid isPermaLink="false">138490@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hi, so i have these classes,  how do i replace "Tower" and "Tower2" with an NSString?</p>
<pre><code>Tower *tower = [[Tower alloc] initWithSpriteFrameName:@&#34;an1_anim1.png&#34;];</code></pre>
<pre><code>Tower2 *tower = [[Tower2 alloc] initWithSpriteFrameName:@&#34;an2_anim1.png&#34;];</code></pre>
<p>replace it with<br />
<pre><code>NSString *className = [NSString stringWithFormat:@&#34;%d&#34;];

className *tower = [[className alloc] initWithSpriteFrameName:@&#34;an2_anim1.png&#34;];</code></pre>
<p>i am creating many types of sprites so if this format is possible, it will shorten my code a lot.<br />
i tried NSClassFromString but it returns the actual Class Object and does not allow me to add an instance of it (e.g. in this case 'tower').<br />
any help is appreciated.  thanks
</p></description>
		</item>
		<item>
			<title>cocosbean on "Turn sprite black and white"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28142#post-138444</link>
			<pubDate>Fri, 06 Jan 2012 20:32:41 +0000</pubDate>
			<dc:creator>cocosbean</dc:creator>
			<guid isPermaLink="false">138444@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have some sprites on the screen that when touched will turn black and white. How would I do that?
</p></description>
		</item>
		<item>
			<title>cocosbean on "CCScaleTo not being applied to every sprite"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28140#post-138429</link>
			<pubDate>Fri, 06 Jan 2012 19:04:00 +0000</pubDate>
			<dc:creator>cocosbean</dc:creator>
			<guid isPermaLink="false">138429@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have an array of sprites that I want to scale. However only the last case (case 5) runs the action and scales the sprite. I've been trying for hours to figure out why only the last one is running the action and not all of them but just can't figure it out. Here's the code:</p>
<p>id scaleUp = [CCScaleTo actionWithDuration:0.4 scale:1.0];</p>
<p>    int i = 0;<br />
    for(CCSprite *bulletSprite in bulletArray) {<br />
        switch (i) {<br />
            case 0:<br />
                bulletSprite.position = ccp(110,105);<br />
                [self addChild: bulletSprite z:1000];<br />
                [bulletSprite runAction:scaleUp];<br />
                break;<br />
            case 1:<br />
                bulletSprite.position = ccp(130,105);<br />
                [self addChild: bulletSprite z:1000];<br />
                [bulletSprite runAction:scaleUp];<br />
                break;<br />
            case 2:<br />
                bulletSprite.position = ccp(150,105);<br />
                [self addChild: bulletSprite z:1000];<br />
                [bulletSprite runAction:scaleUp];<br />
                break;<br />
            case 3:<br />
                bulletSprite.position = ccp(170,105);<br />
                [self addChild: bulletSprite z:1000];<br />
                [bulletSprite runAction:scaleUp];<br />
                break;<br />
            case 4:<br />
                bulletSprite.position = ccp(190,105);<br />
                [self addChild: bulletSprite z:1000];<br />
                [bulletSprite runAction:scaleUp];<br />
                break;<br />
            case 5:<br />
                bulletSprite.position = ccp(210,105);<br />
                [self addChild: bulletSprite z:1000];<br />
                [bulletSprite runAction:scaleUp];<br />
                break;<br />
            default:<br />
                break;<br />
        }    </p>
<p>        i += 1;<br />
    }
</p></description>
		</item>
		<item>
			<title>Navi2D on "Accelerometer not working after approval from app store"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/26001#post-134498</link>
			<pubDate>Tue, 20 Dec 2011 05:32:10 +0000</pubDate>
			<dc:creator>Navi2D</dc:creator>
			<guid isPermaLink="false">134498@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>My game is approved by the apple but the accelerometer is not working is my app. Here is the link of my app.</p>
<p><a href="http://itunes.apple.com/in/app/the-plane-game-lite/id489110251?mt=8" rel="nofollow">http://itunes.apple.com/in/app/the-plane-game-lite/id489110251?mt=8</a></p>
<p>This problem is occurring in my other too more apps which are build by using COCOS2D accelerometer code. Please help me out i have stuck here with no functionality. Here is my code. This is working fine in released code but not after approval from app store.</p>
<p><code><br />
-(id)init<br />
{<br />
         self.isAccelerometerEnabled = YES;<br />
         [self schedule:@selector(nextFrame:)];<br />
}</p>
<p>- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration<br />
{</p>
<p>	// Set up variables<br />
	CGSize winSize = [CCDirector sharedDirector].winSize;</p>
<p>	#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> kFilteringFactor 0.5<br />
	#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> kShipMaxPointsPerSec (winSize.height*0.5)<br />
	#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> kRestAccelX (xCallib)<br />
	#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> kMaxDiff 0.2<br />
	#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> kRestAccelY (yCallib)<br />
	#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> kMaxDiffY 0.1</p>
<p>	UIAccelerationValue rollingX = 0;<br />
	float accelX;</p>
<p>	// High pass filter for reducing jitter<br />
	rollingX = (acceleration.x * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));    </p>
<p>	accelX = acceleration.x - rollingX;</p>
<p>	// Calculate movement for x and y axis<br />
	float accelDiffX = accelX - kRestAccelX;<br />
	float accelFractionX = accelDiffX / kMaxDiff;<br />
	movementX = kShipMaxPointsPerSec * accelFractionX;</p>
<p>	// Thresh holds for x and y axis movement<br />
	willMoveX = YES;</p>
<p>	if (((movementX &#60; 45.0f) &#38;&#38; (movementX &#62; -45.0f))) willMoveX = NO;<br />
}</p>
<p>-(void)nextFrame:(ccTime)dt<br />
{</p>
<p>	CCSprite *plane =(CCSprite *) [self getChildByTag:80];</p>
<p>	CGSize screenSize = [[CCDirector sharedDirector]winSize];</p>
<p>	float oldX = [plane position].x;<br />
	float newX;	</p>
<p>	if (willMoveX) {<br />
		newX = [plane position].x + (movementX * dt);<br />
	} else newX = oldX;</p>
<p>	if ((newX &#62; (screenSize.width -45)) &#124;&#124; newX &#60; 45.0f ) {<br />
		newX = oldX;<br />
	}</p>
<p>	[plane setPosition:ccp(newX,60)];<br />
}</code>
</p></description>
		</item>
		<item>
			<title>Fanoaky on "How do I flip a card over in a fluid animation?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/15771#post-89162</link>
			<pubDate>Wed, 20 Apr 2011 17:39:17 +0000</pubDate>
			<dc:creator>Fanoaky</dc:creator>
			<guid isPermaLink="false">89162@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'm trying to figure out an easy way to have a card flip over in a fluid animation without using several animation frames. I tried the fipx property but this is an instantAction and I want a fluid animation for the flip.</p>
<p>Any ideas?</p>
<p>Thanks
</p></description>
		</item>
		<item>
			<title>FiberCore on "CCFlipX3D  cannot be used on CCSprite?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/10703#post-61048</link>
			<pubDate>Thu, 28 Oct 2010 13:18:57 +0000</pubDate>
			<dc:creator>FiberCore</dc:creator>
			<guid isPermaLink="false">61048@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I need an action like CCFlipX3D doing. But I found it just used for CCColorLayer, not for CCSprite.<br />
Does it mean cocos2d is 2D game engine, cannot support sprite flipping which is an 3D action?
</p></description>
		</item>
		<item>
			<title>Edel on "Make a class with two sprites"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/27945#post-137228</link>
			<pubDate>Thu, 29 Dec 2011 16:52:41 +0000</pubDate>
			<dc:creator>Edel</dc:creator>
			<guid isPermaLink="false">137228@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi guys !</p>
<p>Before posting here, i'd looked in both Google and this forum, but i'd not found what i'm looking for.</p>
<p>I'm making a ballistic game, you have two tanks and you must shot the other tank but there is an obstacle between each tank.</p>
<p>My problem is I want to make my costum class "tank", I need to do it with two srpites, one is the body of the tank, the other is the cannon, here a pic if you dont really understand </p>
<p><a href="http://www.hostingpics.net/viewer.php?id=559731example.png" rel="nofollow">http://www.hostingpics.net/viewer.php?id=559731example.png</a></p>
<p>And the canon will move with an angle. I can't use a spritesheet because all pics are made by a friends, and I don't want to give to her to much work.</p>
<p>So, I want to make a class, with those srpite, but i dont have any idea how to do it. I tried a class from CCNode and CCSprite, but how to integrated two sprite in place in place of one? This is my problem and I hope you will give me some tips or advice to achieve my class.
</p></description>
		</item>
		<item>
			<title>cocosbean on "Move sprite within another sprite"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/27810#post-136628</link>
			<pubDate>Thu, 22 Dec 2011 20:31:39 +0000</pubDate>
			<dc:creator>cocosbean</dc:creator>
			<guid isPermaLink="false">136628@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I want to move a smaller sprite that is within a larger sprite and not let the small one get out of the bounding box of the larger one. I know ccTouchMoved would be used but I can't figure out how to only move within the boundary.
</p></description>
		</item>
		<item>
			<title>gametreesnet on "CCSpriteFrameCatche question"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/27845#post-136761</link>
			<pubDate>Sat, 24 Dec 2011 04:29:18 +0000</pubDate>
			<dc:creator>gametreesnet</dc:creator>
			<guid isPermaLink="false">136761@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello people.<br />
I've got a problem that is bugging me for a long time.<br />
I'm trying to use CCSpriteFrameCatche as a way to use images from .plist files (like most people).<br />
However, the problem is that the sprite which needs to use CCSpriteFrameCatche is a separate class, and is added every second or so. (like a monster)<br />
When I see tutorials like Bobueland and Raywenderlich, they use the point of main class, not seperate class.<br />
Therefore, whenever I add a code like this in the main class:<br />
<pre><code>[[CCSpriteFrameCache sharedSpriteFrameCache]
      addSpriteFramesWithFile:@&#34;enemyAtlas.plist&#34;];
        sceneSpriteBatchNode =
        [CCSpriteBatchNode batchNodeWithFile:@&#34;enemyAtlas.png&#34;];
        [self addChild:sceneSpriteBatchNode z:0];</code></pre>
<p>It does not work because the image is not in the main class.<br />
I found another method to initialize a sprite and write the spriteFrame code in the main class like this:<br />
<pre><code>CCSprite *sprite = [ ccSprite alloc[nitWithSpriteFrameName:@&#34;abc.png&#34;]];</code></pre>
<p>but that does not work in my class because I've got an array of sprites, not one, so I cannot initialize the sprite in the main class because then, I can only make one pointer to the sprite class.<br />
Finally, the last attempt I had was to make my sprite class inherit from another class.<br />
In the another class, I would write this:<br />
<pre><code>[[CCSpriteFrameCache sharedSpriteFrameCache]
      addSpriteFramesWithFile:@&#34;enemyAtlas.plist&#34;];
        sceneSpriteBatchNode =
        [CCSpriteBatchNode batchNodeWithFile:@&#34;enemyAtlas.png&#34;];
        [self addChild:sceneSpriteBatchNode z:0];</code></pre>
<p>so my sprite can recognize the ccSpriteFrameCatche from the parent class.<br />
Unfortunately, this also did not work.<br />
Therefore, my questions is... is there any tutorial on having to deal with another sprite class? (I watched some, but they weren't what I was looking for.)<br />
If not, is there any suggestions?<br />
I'm sorry for the long question, but it seems that every game has a way to make this work, but it does not work for me.<br />
Thank you.
</p></description>
		</item>
		<item>
			<title>Leonsg on "Cleaning up texture sprites"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/27855#post-136799</link>
			<pubDate>Sat, 24 Dec 2011 17:16:48 +0000</pubDate>
			<dc:creator>Leonsg</dc:creator>
			<guid isPermaLink="false">136799@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi everyone,</p>
<p>I have a piece of code that generates a scrolling background using the gl_repeat method. I am deallocating the sprite in the dealloc method, but it does not seem enough as my frame rate is still dropping after running the game for sometime.</p>
<p>Here are the relevant portions of code.</p>
<p>groundSprite = [[CCSprite spriteWithFile:@"platform.png" rect:CGRectMake(0, 0, winSize.width*10, 128)];<br />
groundSprite.position = ccp(0, winSize.height * 0.14);<br />
ccTexParams params = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};<br />
[groundSprite.texture setTexParameters:&#38;params];<br />
[self addChild:groundSprite];</p>
<p>// Update Method<br />
CGSize size = groundSprite.textureRect.size;<br />
groundSprite.position = CGPointMake(winSize.width*0.4+_offset, winSize.height*0.14);<br />
groundSprite.textureRect = CGRectMake(_offset, 0, size.width, size.height);</p>
<p>I think I am suppose to do a sprite removal if the sprite is out of the screen and unused, but I am not sure how I can do that when the sprite has been assigned as a texture.</p>
<p>Can anyone provide some insight on the issue I'm facing. Thanks!
</p></description>
		</item>
		<item>
			<title>Tadegol on "Create Dynamic CCSpriteBatchNode on NSthread"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25740#post-134111</link>
			<pubDate>Sun, 18 Dec 2011 23:27:46 +0000</pubDate>
			<dc:creator>Tadegol</dc:creator>
			<guid isPermaLink="false">134111@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello, im looking some information about how fix my problem please.</p>
<p>What i want to do: Create dynamic objets from one thread or anything else.<br />
Problem: when the thread is running and trying to create the object then shows a EXC BAD ACCESS</p>
<p>i've been reading some topics about nsthreads and glgraphic and they said that i can't modify the GLGraphics with a thread. so i want to know other solutions to create a dynamic  CCSpriteBatchNode objects</p>
<p>i hope someone know any solution for my problem. Thanks!</p>
<p>My snipet example:</p>
<p>i call this function on my main method</p>
<pre><code>[NSThread detachNewThreadSelector:@selector(newMonster:) toTarget:self  withObject:self];</code></pre>
<p>this is how i create new monsters<br />
<pre><code>-(void) newMonster:(Game*)myGame
{
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	while (TRUE)
	{
		sleep(3);
		Monster *_monster = [Monster monsterWithGame:myGame];
		[myGame addChild:_monster.batchNode z:6];
	}

	[pool release];
}</code></pre>
<p>This is how i made the monster. on Monster.m</p>
<pre><code>+(id) monsterWithGame:(Game*)game
{
	return [[[self alloc] initWithGame:game] autorelease];
}

-(id) initWithGame:(Game*)game
{
	cpShape *shape = [game.spacemanager addRectAt:cpvzero mass:STATIC_MASS width:30 height:30 rotation:0];
	return [self initWithGame:game shape:shape];
}

-(id) initWithGame:(Game*)game shape:(cpShape*)shape;
{
	[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@&#34;walksprite.plist&#34;];
	CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@&#34;walksprite.png&#34;];
	[super initWithShape:shape spriteFrameName:@&#34;walk1.png&#34;];
	_game = game;

	self.autoFreeShape = YES;
	self.spaceManager = game.spacemanager;

	NSMutableArray *walkAnimFrames = [NSMutableArray array];
	for(int i = 1; i &#60;= 3; i++)
	{
		[walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache]
		spriteFrameByName:[NSString stringWithFormat:@&#34;walk%d.png&#34;, i]]];
	}

	CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.3f];
	walkingAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:YES]];

	[spriteSheet addChild:self];
	self.batchNode = spriteSheet;

	return self;
}</code></pre>
<p>thanks...
</p></description>
		</item>
		<item>
			<title>zedarus on "Use part of an image as a texture for sprite"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/27799#post-136554</link>
			<pubDate>Thu, 22 Dec 2011 09:55:01 +0000</pubDate>
			<dc:creator>zedarus</dc:creator>
			<guid isPermaLink="false">136554@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey everybody!</p>
<p>Here's what I'm trying to do: let's say we have an image and a square sprite with random size. I need to take a random area from the image like this:</p>
<p><img src="http://www.zedarus.ru/public/initial_small.png" alt="Texture Image" /></p>
<p>And apply it as a texture to the square sprite like this:</p>
<p><img src="http://www.zedarus.ru/public/result_small.png" alt="Textured sprite" /></p>
<p>Is there a way to do so in cocos2d with OpenGL? Unfortunately, I'm not very good with OpenGL (yet), so I will really appreciate if someone will point me in a right direction.</p>
<p>Thanks!
</p></description>
		</item>

	</channel>
</rss>

