Search Results

Search found 560 results on 23 pages for 'cocos2d'.

Page 9/23 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • How to get the location (x,y) of a CCLabel that is a child of a CCScene?

    - by RexOnRoids
    (learning Cocos2D) After creating a CCLabel and adding it to a CCLayer like this: //From HelloWorldScene.m // create and initialize a Label CCLabel* label1 = [CCLabel labelWithString:@"Hello" fontName:@"Marker Felt" fontSize:10]; label1.position = ccp(35, 435); // add the label as a child to this Layer [self addChild: label1]; How do I determine when a user has TOUCHED the label on the screen?

    Read the article

  • Problem with migrating from Texture2D to CCTexture2D (Setting CCSprite texture)

    - by marie
    My problem is that whenever I change the texture of a sprite, the new texture will retain the size of the original sprite's texture. I have this code: mySprite = [CCSprite spriteWithFile:@"mySprite.png"]]; ... // change current stage here CCTexture2D *newTexture=[[[CCTexture2D alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"stage number %d.png",currentStageNumber]]]autorelease]; [mySprite setTexture:newTexture]; The new sprite is stretched or compressed depending on the size of the original sprite. If the original sprite is larger, the new texture is stretched. I didn't have this problem when I was using cocos2d v0.8 What am I doing wrong?

    Read the article

  • Sprite backgrounds

    - by Mattias Akerman
    I use cocos2d for iphone and in my game I'm using a sprite as static background image. I've noticed that when removing code for adding the sprite the framerate goes from ~30fps to over 40fps. Is it any other way to show a static background that is less expensive? I'm not moving the background sprite at all. To code right now: background = [Sprite spriteWithFile:@"t1_5.jpg"]; [self addChild:background z:0]; background.position = ccp(240, 160);

    Read the article

  • Is there a way to morph / convert a circular sprite into a square programmatically?

    - by John
    I have a sprite which is basically just an image of a circle and some content inside. Is there a way that I can programmatically stretch / distort it into something like: I don't care so much about the distortion. The original circular image is 100x100px, and the modified image should also be 100x100px. So its really the content that is being distorted. Can this be done using shaders or some other programmatic way ? The initial circular image is most likely determined at run time, which is why I need to programmatically convert the circular sprite to square. Please do not edit the tags, as the question applies to both versions of cocos2d (iPhone & x), and the solution will most likely work in both regardless of whether one uses C or C++ since the apis are similar, and OpenGL commands work similarly.

    Read the article

  • Can we use (id) in if- else condition ?

    - by srikanth rongali
    I have written my code in following way in cocos2d. id actionTo = [CCFadeOut actionWithDuration:4.0f]; id actionTo0 = [CCSequence actionWithDuration:2.0f]; if (m < enemyNumber) id actionTo1 = [CCCallFunc actionWithTarget:self selector:@selector(goToNextScene)]; else id actionTo1 = [CCCallFunc actionWithTarget:self selector:@selector(goToEndScene)]; id actionSeq = [CCSequence actions:actionTo, actionTo0, actionTo1, nil]; [targetE runAction: [CCSequence actions:actionSeq, nil]]; error: expected expression before 'id' I am getting the above error. Should not we use (id) in if condition ? I want to get called two selectors by using the if- else condition. How can I make it ? Thank You.

    Read the article

  • Smoothly drag a Sprite in cocos2d - iPhone

    - by Saurabh
    Hi All I have implemented a drag on a sprite object as follows.. -(BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch * touch = [touches anyObject]; CGPoint location = [[Director sharedDirector] convertCoordinate: [touch locationInView:touch.view]]; [diskSprite setPosition:ccp(location.x , location.y )]; return kEventHandled; } but this dragging is not smooth..... when i drag fast with my thumb the object left from the path. Thanks

    Read the article

  • Replacing image in sprite - cocos2d game development of iphone

    - by sagar
    I want to change the sprite image. Say for example. mainSprite=[Sprite spriteWithFile:@"redFile.png"]; [self addChild:mainSprite]; Here, Sprite is already added to a layer. I have mainSprite (pointer) which can access it. If I change [mainSprite setOpacity:150]; it works perfectly. But Here I want to change the sprite image instead of opacity. But Don't know how? Thanks in advance for helping me. Sagar

    Read the article

  • remote database connection with my iphone application using cocos2d

    - by Rana
    MCPResult *theResult; MCPConnection *mySQLConnection; //initialize connection string vars NSString *dbURL = @"192.168.0.16"; NSString *userName = @""; NSString *pass = @""; int port = 3306; //open connection to database mySQLConnection = [[MCPConnection alloc] initToHost: dbURL withLogin:userName password:pass usingPort:port]; if ([mySQLConnection isConnected]) { NSLog(@"The connection to database was successfull"); } else { NSLog(@"The connection to database was failed"); } //selection to database if([mySQLConnection selectDB:@"blackjack_DB"]) { NSLog(@"Database found"); } else { NSLog(@"Database not found"); } //selection to Table theResult = [mySQLConnection queryString:@"select * from test"]; //theResult = [mySQLConnection queryString:@"select * from test where id='1'"]; //theResult = [mySQLConnection queryString:@"select id from test"]; //theResult = [mySQLConnection queryString:@"select name from test where pass='main_pass'"]; NSArray *m= [theResult fetchRowAsArray]; NSLog(@"%@", m); NSLog(@"%@", [m objectAtIndex:2]); Use this code for connecting & receive information from remotedatabase. And also use some framework. AppKit.framework, Cocoa.framework, Carbon.framework, MCPKit_bundled.framework. But stile i didn't connect my application with remort database.

    Read the article

  • collision detection in cocos2d.

    - by seenu
    i want to detect collision detection two times in same row. for example:-(see the below image) the ellipse and rectangle or detcted. after that my ellipse will travelling in the straight line path to down and detect the another rectangle. first one is( travelled in trajectory path ) working fine. second one i want to pass in straight line to down for collision detection. how to do this process.

    Read the article

  • Cocos2D: Problem Rotating a CCMenu

    - by srikanth rongali
    If I try to do actions over menuItems but the actions are not running as expected. I think code below should make the menuItem rotate by 90 degrees but when I run it, the menuItem translates from its coordinates to another coordinate then returns to its original coordinate. The complete translation takes 3 seconds. What I need is for the menuItem to rotate by 90 degrees in place within a 3 seconds duration. Please explain where I have done wrong? CCMenuItemImage *targetE;//Globally declared CCMenu *menu;//Globally declared -(id)init { if( (self = [super init]) ) { isTouchEnabled = YES; CGSize windowSize = [[CCDirector sharedDirector] winSize]; targetE = [CCMenuItemImage itemFromNormalImage:@"grossinis_sister1.png" selectedImage:@"grossinis_sister1.png" target:self selector:@selector(touch:)]; menu = [CCMenu menuWithItems:targetE,nil]; id action4 = [CCRotateBy actionWithDuration:3.0 angle:90]; [menu runAction: [CCSequence actions: action4, nil]]; menu.position = ccp(windowSize.width/2 + 200, windowSize.height/2); [self addChild: menu z:10]; } return self; } @end Thank You.

    Read the article

  • Good way to make animations with cocos2d?

    - by Johnny Oin
    Hi there, I'm making a little iphone game, and I would get some clues. Let's imagine: Two background sprites moving pretty fast from right to left, and moving up and down with accelerometer. I guess I can't use animations here, cause the movement of the background is recalculated at each frame. So I use a schedule with an interval of 0.025s and move my sprites at each clock with a : sprite.position = ccp(x, y); So here is my problem: the result is laggy, with only these two sprites. I tried both declaring sprites in the header, and getting them with CCNodes and Tags. It's quite the same. So if someone can give me a hint on what is the best way to do that, that would be so nice. I wonder if the problem can't be the fact that sprites are moving very fast, but i'm not sure. Anyway, thanks for your time. J.

    Read the article

  • use more then one sound in my iphone application using cocos2d

    - by Rana
    avc = [[MPAVController sharedInstance] avController]; //avc is AVController NSString *path = [[NSBundle mainBundle] pathForResource:@"Sound" ofType:@"wav"]; id feeder = [[MPArrayQueueFeeder alloc] initWithPaths:[NSArray arrayWithObject:path]]; [avc setQueueFeeder:feeder]; [avc play:nil]; [feeder release]; NSTimer *sound = [NSTimer scheduledTimerWithTimeInterval:(9.0) target:self selector:@selector(Gamesoundplay) userInfo:nil repeats:YES]; Hear i use tow framework for playing sound. 1. MediaPlayer.framework 2. AudioToolbox.framework I success to play the background sound with repeat after lodding the game. I also want to play sound after clicking some button action without stop the previous background sound.But when i click the other button that time background sound is stop and start again after time intereval ( 9.0 sec ) which i mention for repeated the sound time line. If anyone do this work then help me to complete my application.

    Read the article

  • Problem trying to move a CCSprite circle in Cocos2d

    - by thyrgle
    Hi, So I am trying to move a CCSprite (which has the picture of a circle and is 32 by 32 pixels) with ccTouchesBegan. I have tried the following: -(void) ccTouchesBegan:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint location = [touch locationInView:touch.view]; if ((location.x <= L1Circle1.position.x + 32 && location.x >= L1Circle2.position.x - 32) && (location.y <= L1Circle1.position.y + 32 || location.y >= L1Circle2.position.y - 32)) { L1Circle1.position = ccp(location.x, location.y); } } But, when I touch the screen in the simulator nothing happens... What am I doing wrong?

    Read the article

  • How to dismiss the MFMailComposeViewController in cocos2d ?

    - by srikanth rongali
    I have changed my code to this way. Now mail controller is opening in landscape mode. But the problem is If I touch on cancel button or send button the mail controller is not dismissing its view. How can I do it ? -(void)goToFirstScreen:(id)sender { NSLog(@"goToFirstScreen: "); CCScene *Scene = [CCScene node]; CCLayer *Layer = [EmailScene node]; [Scene addChild:Layer]; [[CCDirector sharedDirector] setAnimationInterval:1.0/60]; [[CCDirector sharedDirector] pushScene: Scene]; } Th EmailScene class is #import "EmailScene.h" #import "testOfEnd.h" @implementation EmailScene - (id) init { self = [super init]; if (self != nil) { [self displayComposerSheet]; } return self; } -(void)displayComposerSheet { [[CCDirector sharedDirector] pause]; picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [[[CCDirector sharedDirector] openGLView] addSubview:picker.view]; [[CCDirector sharedDirector] stopAnimation]; [picker presentModalViewController:picker animated:YES]; [picker release]; } - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { [[CCDirector sharedDirector] resume]; //dismiss view after otherwise the code is not executed [picker.view removeFromSuperview]; [[CCDirector sharedDirector] startAnimation]; [picker dismissModalViewControllerAnimated:YES]; //return to previous scene CCScene *Scene = [CCScene node]; CCLayer *Layer = [testOfEnd node]; [Scene addChild:Layer]; [[CCDirector sharedDirector] replaceScene:Scene]; } @end Thank You.

    Read the article

  • Cocos2D TouchesEnded not allowing me to access sprites?

    - by maiko
    Hey Guys! Thanks so much for reading! - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch * touch = [touches anyObject]; CGPoint location = [[CCDirector sharedDirector] convertToGL: [touch locationInView:touch.view]]; CGRect myRect = CGRectMake(100, 120, 75, 113); int tjx = sprite.position.x; if(CGRectContainsPoint(myRect, location)) { tjx ++; } } For some reason, ccTouchesEnded isn't allowing me to access my "sprite". I also tried to use CGRectMake like so : CGRectMake( sprite.position.x, sprite.position.y, sprite.contentSize.Width, sprite.contentSize.Height) But I couldn't access my sprites position or height. I keep getting "sprite" undeclared when it is declared in the init method, and added to the child. Please help!! I'm sure i'm missing something really simple here.

    Read the article

  • Cocos2d shake/accelerometer issue.

    - by Ryan Poolos
    So I a little backstory. I wanted to implement a particle effect and sound effect that both last about 3 sec or so when the user shakes their iDevice. But first issue arrived when the build in UIEvent for shakes refused to work. So I took the advice of a few Cocos veterans to just use some script to get "violent" accelerometer inputs as shakes. Worked great until now. The problem is that if you keep shaking it just stacks the particle and sounds over and over. Now this wouldn't be that big of a deal except it happens even if you are careful to try and not do so. So what I am hoping to do is disable the accelerometer when the particle effect/sound effect start and then reenable it as soon as they finish. Now I don't know if I should do this by schedule, NStimer, or some other function. I am open to ALL suggestions. here is my current "shake" code. - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { const float violence = 1; static BOOL beenhere; BOOL shake = FALSE; if (beenhere) return; beenhere = TRUE; if (acceleration.x > violence * 1.5 || acceleration.x < (-1.5* violence)) shake = TRUE; if (acceleration.y > violence * 2 || acceleration.y < (-2 * violence)) shake = TRUE; if (acceleration.z > violence * 3 || acceleration.z < (-3 * violence)) shake = TRUE; if (shake) { id particleSystem = [CCParticleSystemQuad particleWithFile:@"particle.plist"]; [self addChild: particleSystem]; // Super simple Audio playback for sound effects! [[SimpleAudioEngine sharedEngine] playEffect:@"Sound.mp3"]; shake = FALSE; } beenhere = FALSE; }

    Read the article

  • COCOS2D - Animation Stops During Move

    - by maiko
    Hey guys! I am trying to run a "Walk" style animation on my main game sprite. The animations work fine, and my sprite is hooked up to my joystick all fine and dandy. However, I think where I setup the call for my walk animations are wrong. Because everytime the sprite is moving, the animation stops. I know putting the animation in such a weak if statement is probably bad, but please tell me how I could get my sprite to animate properly while it is being moved by the joystick. The sprite faces the right direction, so I can tell the action's first frame is being called, however, it doesn't animate until I stop touching my joystick. Here is How I call the action: //WALK LEFT if (joypadCap.position.x <= 69 /*&& joypadCap.position.y < && joypadCap.position.y 40 */ ) { [tjSprite runAction:walkLeft]; }; //WALK RIGHT if ( joypadCap.position.x = 71 /* && joypadCap.position.y < 100 && joypadCap.position.y 40 */) { [tjSprite runAction:walkRight]; }; THIS: is the how the joystick controls the character: CGPoint newLocation = ccp(tjSprite.position.x - distance/8 * cosf(touchAngle), tjSprite.position.y - distance/8 * sinf(touchAngle)); tjSprite.position = newLocation; Please help. Any alternative ways to call the characters walk animation would be greatly appreciated!

    Read the article

  • Starting a cocos2d game with initial gameplay as background

    - by boz
    Hi All, Id like to start my game, with the initial game play layout as the background, with a buttons layer over the top with maybe 'Tap to start' and a high score etc. and similarly, when the game finishes, id like to just 'pause' the final game play layout and overlay a game over menu of sorts. I tried calling [[CCDirector sharedDirector] pause] as the last line of the appDidFinishLaunching which didnt seem to have any effect. Is there a better way trying to do this? I dont really like my initial approach.

    Read the article

  • CCAnimate/CCAnimation cause inconsistent setTexture behavior in cocos2d on iPhone

    - by chillid
    Hi, I have a character that goes through multiple states. The state changes are reflected by means of a sprite image (texture) change. The state change is triggered by a user tapping on the sprite. This works consistently and quite well. I then added an animation during State0. Now, when the user taps - setTexture gets executed to change the texture to reflect State1, however some of the times (unpredictable) it does not change the texture. The code flows as below: // 1. // Create the animation sequence CGRect frame1Rect = CGRectMake(0,32,32,32); CGRect frame2Rect = CGRectMake(32,32,32,32); CCTexture2D* texWithAnimation = [[CCTextureCache sharedTextureCache] addImage:@"Frames0_1_thinkNthickoutline32x32.png"]; id anim = [[[CCAnimation alloc] initWithName:@"Sports" delay:1/25.0] autorelease]; [anim addFrame:[CCSpriteFrame frameWithTexture:texWithAnimation rect:frame1Rect offset:ccp(0,0)]]; [anim addFrame:[CCSpriteFrame frameWithTexture:texWithAnimation rect:frame2Rect offset:ccp(0,0)]]; // Make the animation sequence repeat forever id myAction = [CCAnimate actionWithAnimation: anim restoreOriginalFrame:NO]; // 2. // Run the animation: sports = [[CCRepeatForever alloc] init]; [sports initWithAction:myAction]; [self.sprite runAction:sports]; // 3. stop action on state change and change texture: NSLog(@"Stopping action"); [sprite stopAction:sports]; NSLog(@"Changing texture for kCJSports"); [self setTexture: [[CCTextureCache sharedTextureCache] addImage:@"SportsOpen.png"]]; [self setTextureRect:CGRectMake(0,0,32,64)]; NSLog(@"Changed texture for kCJSports"); Note that all the NSLog lines get logged - and the texture RECT changes - but the image/texture changes only some of the times - fails for around 10-30% of times. Locking/threading/timing issue somewhere? My app (game) is single threaded and I only use the addImage and not the Async version. Any help much appreciated.

    Read the article

  • Animation management in COCOS2D iphone.

    - by shreya
    Hi All, I have near about 255 image frames for background animation, 99 frames of enemy sprite and 125 frames of player sprite. All animations are running simultaneously on the screen. That is background animation is running and 4-5 enemies are on the screen are present at a time, also player is there at the same time. Take a look at the code below, CCAnimation *_enemyAnimation = [CCAnimation animationWithName:@"Enemy" delay:0.1f]; for (int i = 1; i<99; i++) { [_enemyAnimation addFrameWithFilename:[NSString stringWithFormat:@"enemy %02d.jpg",i]]; } id action1 = [CCAnimate actionWithAnimation: _enemyAnimation]; [_enemySprite runAction:[CCRepeatForever actionWithAction: action1]]; [self schedule:@selector(BackToGameLogic:) interval:5.0]; This makes my game too slower and consumes memory about 65MB in the allocations. How should I manage my animations so there will be improvement in speed and memory consumption will be reduced?. Please suggest me the way. Thanks.

    Read the article

  • Cocos2d - smooth sprite movement in tile map RPG

    - by Lendo92
    I've been working on a 2-D Gameboy style RPG for a while now, and the game logic is mostly all done so I'm starting to try to make things look good. One thing I've noticed is that the walking movement / screen movement is a little bit choppy. Technically, it should work fine, but either it seems to be having some quirks, either due to taking up a lot of processing power or just timing inconsistencies between moving the screen and moving the sprite. To move the sprite, once I know where I want to move it, I call: tempPos.y += 3*theHKMap.tileSize.width/5; id actionMove = [CCMoveTo actionWithDuration:0.1 position:tempPos]; id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(orientOneMove)]; [guy runAction:[CCSequence actions:actionMove, actionMoveDone, nil]]; [self setCenterOfScreen:position]; Then, in orientOneMove, I call: [self.guy setTexture:[[CCTextureCache sharedTextureCache] addImage:@"guysprite07.png"]]; //the walking picture-I change texture back at the end of the movement id actionMove = [CCMoveTo actionWithDuration:0.15 position:self.tempLocation2]; id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(toggleTouchEnabled)]; [guy runAction:[CCSequence actions:actionMove, actionMoveDone, nil]]; The code for the concurrently running setCenterOfScreen:position method is: id actionMove = [CCMoveTo actionWithDuration:0.25 position:difference]; [self runAction: [CCSequence actions:actionMove, nil, nil]]; So the setCenterOfScreen moves the camera in one clean move while the guy moving is chopped into two actions to animate it (which I believe might be inefficient.) It's hard to tell what is making the movement not perfectly clean from looking at it, but essentially the guy isn't always perfectly in the center of the screen -- during movement, he's often times a pixel or two off for an instant. Any ideas/ solutions?

    Read the article

  • iPhone: Cocos2d how to make a sequence

    - by Johannes Jensen
    I have two logos, which I want to come in after each other. I'd like to use CCFadeIn and CCFadeOut. I have Logo1, and then I want it to CCFadeIn, then I want it to stay for 2 seconds, then make it fade out using CCFadeOut, and then make Logo2 CCFadeIn for 1 second, stay for 2 seconds and then go away during 1 second with CCFadeOut. How I would make this I'm not completely sure. I can't seem to find a way to make a CCAction fire a method (let's say -finishedFadingInLogo1:), so I don't know how to do this. Any ideas?

    Read the article

  • cocos2d 2.x scene retainCount

    - by Shefy Gur-ary
    I'm pushing a scene to the game I'm working on, after pressing a button in the main menu. This scene is a gameplayScene which should have two layers ad childs: boardLayer and hudLayer. for now I'm testing with the boardLayer, I'm using block to call the gameplayScene to close both itself and the boardLayer, but by the time I get there the retain count of both layer is 3 (seems to be increasing after setting the block to 2, and I'm not sure when it is going up to 3) What cause this, and how should it be handled?

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >