cocos2d-iphone

CGRect with an angle

无人久伴 提交于 2019-12-25 04:06:14
问题 I have a line, which is a sprite made by using this code CGPoint diff = ccpSub(startLocation, endLocation); float rads = atan2f( diff.y, diff.x); float degs = -CC_RADIANS_TO_DEGREES(rads); float dist = ccpDistance(endLocation, startLocation); CCSprite *line = [CCSprite spriteWithFile:@"line.png"]; [line setAnchorPoint:ccp(0.0f, 0.5f)]; [line setPosition:endLocation]; [line setScaleX:dist / line.boundingBox.size.width]; [line setRotation: degs]; line.tag = 1; [_lines addObject:line]; [self

stack of actions for one sparite in cocos2d

荒凉一梦 提交于 2019-12-25 04:05:32
问题 I've got a question: My games hero can jump ( CCJumpTo ) and move to forward and backward direction ( CCMoveTo ). I faced with problem: if game recived a command from user to move the hero, but in this time hero is jumping ( CCJumpTo ), how can I do this command after the end of jumping. (can I use some stack of actions for one sparite in cocos2d) I can't use immediately [self.sprite stopAllActions]; to begin CCMoveTo because the hero have to finish the jump action and if I use CCMoveTo the

rotate a sprite around an anchor point

混江龙づ霸主 提交于 2019-12-25 03:34:27
问题 I have a sprite : ombreoeuf1 = [CCSprite spriteWithFile:@"mangeurcentremieu3_03.png" ]; ombreoeuf1.position = ccp(240,160); [self addChild:ombreoeuf1]; And I would like to rotate it constantly around an anchor point. How can I do it? 回答1: You can first set anchor point by setting the property anchorPoint , for example: [ombreoeuf1 setAnchorPoint:ccp(0,0)] and then set rotation (in degrees) by setting another property rotation : [ombreoeuf1 setRotation:90] anchorPoint and rotation are both

rotate a sprite around an anchor point

≯℡__Kan透↙ 提交于 2019-12-25 03:34:17
问题 I have a sprite : ombreoeuf1 = [CCSprite spriteWithFile:@"mangeurcentremieu3_03.png" ]; ombreoeuf1.position = ccp(240,160); [self addChild:ombreoeuf1]; And I would like to rotate it constantly around an anchor point. How can I do it? 回答1: You can first set anchor point by setting the property anchorPoint , for example: [ombreoeuf1 setAnchorPoint:ccp(0,0)] and then set rotation (in degrees) by setting another property rotation : [ombreoeuf1 setRotation:90] anchorPoint and rotation are both

Cocos2d Jump Animation & Moving

依然范特西╮ 提交于 2019-12-25 03:19:14
问题 So far I am able to control my sprite's side to side movement with buttons in Cocos2d. I am now trying to incorporate a jump animation but I have absolutely no idea how to do this. I have tried one sample code which utilized the init method and combined to animations (jump up and jump down) but whenever I tried to move the sprite while it was jumping i got a SIGABRT error. Please note that I am very unexperienced with Cocos2d and walking me through the steps to make a successful jump

How to create a circle shape without solid polygon or non solid circle``

Deadly 提交于 2019-12-25 02:43:26
问题 I am developing a casino roulette game in box2d. As you know in this game a ball/dice will be in a circular spinning wheel. First I tried with b2circleShape but it didn't work. I mean that the ball is not sitting inside the circular shape. Then I tried with b2EdgeShape. But for the b2edgeShape I need to create as many vertices as I can to build a smooth circular surface. Is there anyway that I can create such circle shapes which are not polygons or which are not solid polygons? If have any

Draw Quad and Cubic Bezier in Cocos2d v3 on IOS

五迷三道 提交于 2019-12-25 02:42:11
问题 I want to draw a Cubic/Quad Bezier with Cocos2d v3. I looked at CCDrawNode but no change. Does anyone know a way around? Thanks!! 回答1: finally, I found the solution: https://github.com/njt1982/CCDrawNode-Bezier 回答2: This is how I did it in Cocos2d 3.3: // blue test auto bluN = DrawNode::create(); //Draw a blue quadratic bezier curve Color4F blue(0, 0, 1, 1); bluN->drawCubicBezier(Vec2(0.0, 0.0), Vec2(_visibleSize.height, 0.0), Vec2(_visibleSize.height, _visibleSize.height), Vec2(0.0,

Keep track of sprite position in an array on update loop

。_饼干妹妹 提交于 2019-12-25 02:26:00
问题 Hi I have a loop adding monsters to an NSMutableArray - (void)addMonster:(CCTime)dt { _monster1 = [[Monster1 alloc] init]; for(int i=0;i<=num; i++) { [spriteArray insertObject:_monster1 atIndex:num]; } [_physicsWorld addChild:_monster1]; num++; } in my update loop this code is meant to check if each sprite has passed a certain point: for (int i=0; i <= num; i++) { CCSprite *tempSprite = (CCSprite *) [spriteArray objectAtIndex:i]; if (tempSprite.position.x > 100) { structurelife--; } } However

Cocos2d 3.0 + Chipmunk + CCAnimation: moving physics body with animated object. How?

江枫思渺然 提交于 2019-12-25 02:22:11
问题 I have a boat with attached physics body. This boat is static physics body. Boat moving with CCAnimateMoveTo from left to right. When I tap on screen my character fall down. I detect collisions well. But I want that after collision my character just fall on boat and keep moving with it. Character is dynamic body. Link to sample video: Sample video Here I create a boat: - (void)createBoat { currentBoat = [CCSprite spriteWithImageNamed:@"Boat.png"]; currentBoat.position = ccp(0 - currentBoat

High score and current score

回眸只為那壹抹淺笑 提交于 2019-12-25 02:06:51
问题 I want to show on the screen the current score of the gameplay and the storical best score. It is work, but every times i restart the game the best score change even if the current score is lower than the best score. CCLabelTTF *punteggio; NSString *stringa; NSString *stringa2; CCLabelTTF *punteggioMAX; int score; int scoreMAX; There are the methods to SAVE the score, to add the score and to reset the score at the end of the game. -(void)aum{ score++; stringa = [NSString stringWithFormat:@