Search Results

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

Page 13/23 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • Should iOS games use a Timer?

    - by ????
    No matter what frameworks we use -- Core Graphics, Cocos2D, OpenGL ES -- to write games, should a timer be used (for games that has animation even when a user doesn't do any input, such as after firing a missile and waiting to see if the UFO is hit)? I read that NSTimer might not get fired until after scheduled time (interval), and CADisplayLink can delay and get fired at a later time as well, only that it tells you how late it is so you can move the object more, so it can make the object look like it skipped frame. Must we use a Timer? And if so, what is the best one to use?

    Read the article

  • What is the correct way to implement hit detection with non-rectangular sprites?

    - by hogni89
    What is the correct way to implement hit or touch detection for non-rectangular sprites in Cocos2d? I am working on a jigsaw puzzle, so our sprites have some strange forms (jigsaw puzzle bricks). As of now, we have implemented the "detection" this way: - (void)selectSpriteForTouch:(CGPoint)touchLocation { CCSprite * newSprite = nil; // Loop array of sprites for (CCSprite *sprite in movableSprites) { // Check if sprite is hit. // TODO: Swap if with something better. if (CGRectContainsPoint(sprite.boundingBox, touchLocation)) { newSprite = sprite; break; } } if (newSprite != selSprite) { // Move along, nothing to see here // Not the problem } } - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint touchLocation = [self convertTouchToNodeSpace:touch]; [self selectSpriteForTouch:touchLocation]; return TRUE; } I know that the problem is in the keyword "sprite.boundingBox". Is there a better way of implementing this, or is it a limitation when using sprites based on .png's? If so, how should I proceed?

    Read the article

  • How do I control an animation with a drag command?

    - by Zishan
    I want to play an animation when someone drags a sprite from it's default position to another selected position. If they drag half of the selected position then animation will be play half. For example, I have 15 frames of a animation for a projectile arm. The projectile arm can be rotated a maximum of 30°, if someone rotates the arm 2° then the animation sprite should show the 2nd frame, if rotated 12° then the animation sprite should show the 6th frame.... and so on. Also when they release the arm, the arm will be reverse back to it's default position and animation frames also will be reverse back to the default first frame. I am new on cocos2D. I know how to make an animation and how to drag a sprite but I have no idea how to combine them. Can anyone give me an idea or any tutorial on how to do this?

    Read the article

  • Triangles in a C++ STL Vector as an Objective-C member sometimes draws incorrectly in OpenGL ES

    - by Rahil627
    The polygons draw correctly 80% of the time. When it fails, a vertex is dislocated. The polygon is consistently drawn with the wrong vertex. I checked that the vector is correct during initialization, even when it's wrongly drawn. I'm using Cocos2d. The class member: @interface Polygon : CCSprite { std::vector<float> triangleVertices; } The draw function called in [Polygon draw]: + (void)drawTrianglesWithVertices:(const std::vector<float> &)v { //glEnableClientState(GL_VERTEX_ARRAY); glDisable(GL_TEXTURE_2D); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glVertexPointer(2, GL_FLOAT, 0, &v[0]); glDrawArrays(GL_TRIANGLES, 0, v.size()); //glDisableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_TEXTURE_2D); } Any ideas?

    Read the article

  • Adding gesture recognizer (or dragging) to CCSprite

    - by user339946
    I'm trying to allow a CCSprite to be dragged across the screen. I've succeeded so far by doing it on a Layer level (from this tutorial). However, this only allows ONE sprite to be dragged at a time as the method implementation can only identify a single sprite to move at a time. I'd like to be able to perhaps add a gesture recognizer or somehow implement ccTouchesBegan/Moved in my own little CCSprite subclass. However, from what I understand, you can't just add gesture recognizers to CCSprites. ccTouchMoved are also not available on CCSprites?? Really confused as to how to implement touches on Cocos2D. What is the easiest way to add some position translation code to a CCSprite so it can be dragged around? Thanks!

    Read the article

  • Should I drawing directly on CCLayer or CCSprite?

    - by einverne
    Now I am a little confused in my cocos2d-x cpp project. I want to draw lines with user's finger touch. Following the screenshot of a CCScene: In the screen, there are two squares. I want show an animation in the first square and let the second one draw lines with user touch. Now these two squares are CCSprite. And I can draw dots in the second one on the CCLayer. But I am little confused that I should draw lines on the Sprite or on the Layer. Or are there other ways to organize the code?

    Read the article

  • Drawing line from sprite with a touch

    - by Kaizer
    I am working with cocos2d for the iPhone and I have a question about how to implement the following. I have a circle shaped sprite on my layer. When I touch the sprite and move my finger a line must be drawn from the sprite to where my finger is. When I move my finger on the screen the line must follow (straight line). When I release my finger the line should disappear. In a good looking way I should be able to restyle the line into an arrow. Can anyone move me in the right direction for this ? Kind regards

    Read the article

  • Organize a game set

    - by jncunha
    I'm developing a endless running game and I'm not really sure on how to make the set. The first approach was to make a BIG set like 10240x3072 pixels so that we have a nice portion of set. After having like 3 or 4 sets that go along with each other I would work on making their elements sequential and repeatable. However this is getting really heavy for the iPad 1 (it's running good in the iPad 2 and the New iPad) even though I'm splitting all the set in slices through Photoshop. For the implementation I'm using Cocos2D. Is there any better approach to make something like this but truly efficient for the iPad memory? Thank you.

    Read the article

  • Collision detection on a 2D hexagonal grid

    - by SundayMonday
    I'm making a casual grid-based 2D iPhone game using Cocos2D. The grid is a "staggered" hex-like grid consisting of uniformly sized and spaced discs. It looks something like this. I've stored the grid in a 2D array. Also I have a concept of "surrounding" grid cells. Namely the six grid cells surrounding a particular cell (except those on the boundries which can have less than six). Anyways I'm testing some collision detection and it's not working out as well as I had planned. Here's how I currently do collision detection for a moving disc that's approaching the stationary group of discs: Calculate ij-coordinates of grid cell closest to moving cell using moving cell's xy-position Get list of surrounding grid cells using ij-coordinates Examine the surrounding cells. If they're all empty then no collision If we have some non-empty surrounding cells then compare the distance between the disc centers to some minimum distance required for a collision If there's a collision then place the moving disc in grid cell ij So this works but not too well. I've considered a potentially simpler brute force approach where I just compare the moving disc to all stationary discs at each step of the game loop. This is probably feasible in terms of performance since the stationary disc count is 300 max. If not then some space-partitioning data structure could be used however that feels too complex. What are some common approaches and best practices to collision detection in a game like this?

    Read the article

  • Which data structure should I use for dynamically generated platforms?

    - by Joey Green
    I'm creating a platform type of game with various types of platforms. Platforms that move, shake, rotate, etc. Multiple types and multiple of each type can be on the screen at once. The platforms will be procedural generated. I'm trying to figure out which of the following would be a better platform system: Pre-allocate all platforms when the scene loads, storing each platform type into different platform type arrays( i.e. regPlatformArray ), and just getting one when I need one. The other option is to allocate and load what I need when my code needs it. The problem with 1 is keeping up with the indices that are in use on screen and which aren't. The problem with 2 is I'm having a hard time wrapping my head around how I would store these platforms so that I can call the update/draw methods on them and managing that data structure that holds them. The data structure would constantly be growing and shrinking. It seems there could be too much complexity. I'm using the cocos2d iPhone game engine. Anyways, which option would be best or is there a better option?

    Read the article

  • How to expose game data in the game without a singelton?

    - by zardon
    I'm quite new to cocos2d and games programming, and am currently I am writing a game that is currently in Prototype stage. Everything is going okay, but I've realized a potentially big problem and I am not sure how to solve it. I am using a singelton to store a bunch of arrays for everything, a global list of planets, a global list of troops, a global list of products, etc. And only now I'm realizing that all of this will be in memory and this is the wrong way to do it. I am not storing files or anything on the disk just yet, with exception to a save/load state, which is a capture of everything. My game makes use of a map which allows you to select a planet, then it will give you a breakdown of that planets troops and resources, Lets use this scenario: My game has 20 planets. On which you can have 20 troops. Straight away that's an array of 400! This does not add the NPC, which is another 10. So, 20x10 = 200 So, now we have 600 all in arrays inside a Singelton. This is obviously very bad, and very wrong. Especially as the game scales in the amount of data. But I need to expose pretty much everything, especially on the map page, and I am not sure how else to do it. I've been told that I can use a controller for the map page which has the information I need for each planet, and other controllers for other items I require global display for. I've also thought about storing each planet's data in a save file, using initWithCoder however there could be a boatload of files on the user's device? I really don't want to use a database, mainly because I would need to translate NSObjects and non-NSObjects like CGRects and CGPoints and Colors into/from SQL. I am open to other ideas on how to store and read game data to prevent using a singelton to store everything, everywhere. Thanks for your time.

    Read the article

  • Clear edged sprite

    - by Ananth
    I am a newbie to cocos2d. I would like make user to draw similar to what a painting brush would do. I am using CCSprite for that. I almost implemented the velocity, color and opacity factors for that tool, but I couldn't get the Sprite to be as clear as it should be. I can draw only in the below image http://i.imgur.com/KBe0L.png which has blunt edges. But I want it to be harder / clear outside edges as in http://i.stack.imgur.com/GrFlv.png. I am getting no idea to make it clear edged. The piece of code Im using is glEnable(GL_BLEND); [brush.texture setAliasTexParameters]; [brush setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}]; [brush visit]; I suspect the problem would be on blending mode. I tried some blending modes, but with no expected results. I am trying this for the past five days and so confused. Can some one help me sort this out? Thanks in advance.

    Read the article

  • Player sprite moving slower on iPhone 4

    - by nvillec
    I just finished getting movement/jump animation for a player sprite in Xcode using Cocos2D. The basic movement algorithm is a timer that updates every 0.01 sec, changing the sprite position to (sprite.position.x + xVel, sprite.position.y + yVel). Each time a movement button is tapped, the appropriate velocity (initialized to 0) is changed to whatever speed I choose, then a stop movement button returns the velocity to 0. It's not an ideal solution but I'm very new at this and stoked to at least have that working with little help from the internet. So I may not have explained that perfectly, but it is in fact working to my satisfaction in Xcode's iPhone Simulator, however when I build it for my device and run it on my phone, the sprite's movement speed is noticeably slower than in Xcode. At first I thought it must have to do with the resolution of the iPhone 4, making the sprite's movement path twice as long, but I found that if I pull up the multitask bar, then return to the app the speed will sometimes jump back to normal. My second theory was that the code is just inefficient and is bogging the processes down, but I would see this reflected in the frame rate wouldn't I? It stays at 59-60 the whole time, and the spritesheet animation runs at the correct speed. Has anyone experienced this? Is this a really obvious issue that I'm completely missing? Any help (or tips for optimizing my approach to movement) would be much appreciated!

    Read the article

  • how to give action to the CCArray which contain bubbles(sprites)

    - by prakash s
    I am making bubbles shooter game in cocos2d I have taken one array in that i have inserted number of different color bubbles and i showing on my game scene also , but if give some move action to that array ,it moving down but it displaying all the bubbles at one position and automatically destroying , what is the main reason behind this please help me here is my code: -(void)addTarget { CGSize winSize = [[CCDirector sharedDirector] winSize]; //CCSprite *target = [CCSprite spriteWithFile:@"3.png" rect:CGRectMake(0, 0, 256, 256)]; NSMutableArray * movableSprites = [[NSMutableArray alloc] init]; NSArray *images = [NSArray arrayWithObjects:@"1.png", @"2.png", @"3.png", @"4.png",@"5.png",@"1.png",@"5.png", @"3.png", nil]; for(int i = 0; i < images.count; ++i) { NSString *image = [images objectAtIndex:i]; // generate random number based on size of array (array size is larger than 10) CCSprite*target = [CCSprite spriteWithFile:image]; float offsetFraction = ((float)(i+1))/(images.count+1); //target.position = ccp(winSize.width*offsetFraction, winSize.height/2); target.position = ccp(350*offsetFraction, 460); // [[CCActionManager sharedManager ] pauseAllActionsForTarget:target ] ; [self addChild:target]; [movableSprites addObject:target]; //[target runAction:[CCMoveTo actionWithDuration:20.0 position:ccp(0,0)]]; id actionMove = [CCMoveTo actionWithDuration:10 position:ccp(winSize.width/2,winSize. height/2)]; id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)]; [target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]]; } } after the move at certain position i want to display all the bubbles in centre of my window

    Read the article

  • Cocos2D SpriteSheet animation problem, my number of frames is much larger.

    - by vaibhav-tekam
    Hello, I am trying to use SpriteSheet to run an animation. My frames are of 320x480 in size each, So I am able to put max 6 frames on the texture image. But my animation consists of frame number ranging from 50 to 200 sometimes, and all are of size 320x480. But this much number of frames cannot be added on the Texture image as the size is restricted to 1024x1024. Is there any other approach I can try out. Can I play one animation after the other.And won't it be hampering the performance. Please, I need suggestions. Best, Vaibhav Tekam.

    Read the article

  • How to hide the label (CCLabel) after a certain time in cocos2d ?

    - by srikanth rongali
    I added a label by using CCLabel to my layer. Now I want it do disappear after some time like (2sec). How can I make it to disappear? CCLabel *labelPerfectDraw = [CCLabel labelWithString:@"Perfect Draw" fontName:@"Marker Felt" fontSize:30 ]; labelPerfectDraw.color = ccc3(0x00, 0x00, 0xff); labelPerfectDraw.position = ccp(windowSize.width/2, windowSize.height/2+80); [self addChild:labelPerfectDraw]; I added label in above way. Please give me the idea how can I work on it?

    Read the article

  • How to tell if you touched a CCLabel? (Cocos2d Question)

    - by RexOnRoids
    How to tell if you touched a CCLabel? The following code obviously does not work well enough because it only tests for point equality. Naturally touch point will not necessarily be equal to the position property of the CCLabel (CCNode). How to I tell if a Touch point has fallen within the "rectangle?" of the CCLabel? - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { for( UITouch *touch in touches ) { CGPoint location = [touch locationInView: [touch view]]; location = [[CCDirector sharedDirector] convertToGL:location]; self.myGraphManager.isSliding = NO; if(CGPointEqualToPoint(location, label1.position)){ NSLog(@"Label 1 Touched"); }else if(CGPointEqualToPoint(location, label2.position)){ NSLog(@"Label 2 Touched"); }else if(CGPointEqualToPoint(location, label3.position)){ NSLog(@"Label 3 Touched"); }else if(CGPointEqualToPoint(location, label4.position)){ NSLog(@"Label 4 Touched"); }else if(CGPointEqualToPoint(location, label5.position)){ NSLog(@"Label 5 Touched"); }else if(CGPointEqualToPoint(location, label6.position)){ NSLog(@"Label 6 Touched"); } NSLog(@"Touch Made!"); } }

    Read the article

  • Where do I attach the StoreKit delegate and observer in a Cocos2d App?

    - by Jeff B
    I have figured out how all of the StoreKit stuff works and have actually tested working code... however, I have a problem. I made my "store" layer/scene the SKProductsRequestDelegate. Is this the correct thing to do? I get the initial product info like so: SKProductsRequest *productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers: productIDs]; [productRequest setDelegate: self]; [productRequest start]; The problem is that if I transition to a new scene when a request is in progress, the current layer is retained by the productRequest. This means that touches on my new scene/layer are handled by both the new layer and the old layer. I could cancel the productRequest when leaving the scene, but: I do not know if it is in progress at that point. I cannot release it because it may or may not have been released by the request delegates. There has got to be a better way to do this. I could make the delegate a class external to the current layer, but then I do not know how to easily update the layer with the product information when the handler is called.

    Read the article

  • Cocos2d: is it good practice to use a shared GameScene when having various levels?

    - by mm24
    In my code (based on the ShootEmUp example in this book, which I highly reccomend, source code in chapter 8 available here) I often use the trick of accessing the GameScene via: +(GameScene*) sharedGameScene; which returns a reference to the static instance of GameScene. Is a static instance of GameScene as in the book still a valid pattern in case I want a MainMenu calling GameScene initialized with different level data each time (e.g. different enemies)? (I have created a sceneWithId:(int) method where I load different level data each time. Or should I pheraps create a GameScene class and then sublcass it? E.g. FirstGameScene : GameScene

    Read the article

  • How to create a level with curved lines with cocos2d + Box2d on the iphone?

    - by Steven
    I'd like to create a game that has levels such as this: http://img169.imageshack.us/img169/7294/picdq.png The Player moves "flies" through the level and mustn't collide with the walls. How can I create such levels? I found that piece of software: http://www.sapusmedia.com/levelsvg/ It's not that cheap, so I wonder whether there is another way to create such a level as shown in the picture above...?

    Read the article

  • How do I change the color of a Cocos2d MenuItem?

    - by Rob Sawyer
    [MenuItemFont setFontSize:20]; [MenuItemFont setFontName:@"Helvetica"]; //I'm trying to change the color of start (below item) MenuItem *start = [MenuItemFont itemFromString:@"Start Game" target:self selector:@selector(startGame:)]; MenuItem *help = [MenuItemFont itemFromString:@"Help" target:self selector:@selector(help:)]; Menu *startMenu = [Menu menuWithItems:start, help, nil]; [startMenu alignItemsVertically]; [self add:startMenu];

    Read the article

  • Interface Builder vs Cocos 2D - how choice the best for your app.

    - by baDa
    Hello everyone! I was a flash developer for 3 years, and in the last 5 months, i begin the iphone development, i do 2 applications with interface builder for clients, and now i really want to do a little game, is quite simple, one match 3! I made the engine in interface builder, and seens good to me! But after i read some posts, i really want to try it in the cocos2D! So, in 2 days i rewrite all my first engine for cocos2D, very annoying upsidedown coordinates but ok, i really do! But the performance side by side with interface builder version is really scare! Many Many slow downs at the cocos2d side! And the animation seens bugged to me! I really scare! I really don't know what is the best choice for a simple game. And i want some opinions: Using cocos2d when need some physics? When we have many objects at screen? What is the performance boost i have with cocos2D? I have how to share this 2 applications with you guys?! Without your UID?!

    Read the article

  • Is object remain fixed when scrolling background in cocos2d.

    - by russell
    I have one question when infinite background scrolling is done, is the object remain fixed(like doodle in doodle jump, papy in papi jump) or these object really moves.Is only background move or both (background and object )move.plz someone help me.I am searching for this solution for 4/5 days,but can't get the solution.So plz someone help me. And if object does not move how to create such a illusion of object moving.

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >