cocos2d-iphone

Objective C - XCode not recognizing variable outside of if statement

杀马特。学长 韩版系。学妹 提交于 2019-12-12 07:27:41
问题 Trying to set a sprite filename with an if statement, then load the proper file based on that string. It looks like there's a problem with my variable scope, but I don't know what it is. Here's my code: if ([[GameManager sharedGameManager] newHighScore] == TRUE) { NSString *highScoreLabelText = @"label-new-high-score.png" } else { NSString *highScoreLabelText = @"label-high-score.png" } CCSprite *highScoreLabel = [CCSprite spriteWithSpriteFrameName:highScoreLabelText]; [highScoreLabel

UIPinchGestureRecognizer - Suppress 'close pinch' detection

こ雲淡風輕ζ 提交于 2019-12-12 05:32:35
问题 I'm using the UIPinchRecognizer and an open pinch to detect when someone 'pulls apart' a sprite in a Box2D world. The problem is that when you drag two items toward each other it detects this as a close pinch and breaks all my touchjoints and the movement of the box2d objects. I've tried to split my problem into two questions - the question you're reading now: is it is possible to suppress the close pinch, and if that's not possible: how to detect an open pinch myself. I need to either

Game Physics - Not very life-like

柔情痞子 提交于 2019-12-12 04:59:11
问题 In a simple game (cocos2d) I have a made a small physics engine to move a sprite so that it can jump and stand on platforms ect. To update the position (vertical movement) I use basic kinematics equations in each update: position = oldPosition + velocity(delta) +1/2(gravity)(delta)^2 velocity = oldVelocity + (gravity)(delta) For some reason the game doesn't seem very life-like. It seems to take a long time near the top of an arc, despite how great I make gravity. If I want my sprite to jump

How can I retrieve the corresponding texture name from a GLuint?

自作多情 提交于 2019-12-12 04:44:45
问题 EDIT 5: Optimization level build settings: EDIT 4: I tried to change the build configuration putting all to "Debug" and then run for "testing". Weirdly enough it didn't crash for about 20 times (I kept load and unloading various GameScenes whith different assets). At the 21st time (even if not statistically relevant) I was about to think that it might not crash anymore but it crashed. The summary is still unavailable so I am wondering if I am doing it right or if there is some other issue..

Custom texture dimensions using TexturePacker and Cocos2D

帅比萌擦擦* 提交于 2019-12-12 04:37:31
问题 When I switched from POT to any size in TexturePacker, per this question, Cocos2D starting throwing this warning: cocos2d: WARNING. Current texture size=(1613,2047). Convert it to size=(1614,2047) in order to save memory cocos2d: WARNING: File: units_black-hd.pvr.ccz cocos2d: WARNING: For further info visit: http://www.cocos2d-iphone.org/forum/topic/31092 I cannot figure out how to explicitly set a texture size in TexturePacker so that it meets these constraints. POT fixes it, of course, but

Game Design: handling different game types?

折月煮酒 提交于 2019-12-12 04:37:18
问题 I'm curious if there is a good strategy for handling various game types inside a game that run off the same main game loop? In other words, I have a game with three different game types. There are only a few minor differences between each type, so they currently run using the same loop/classes. One is a 'how many X's can you get before time runs out', another is 'how long does it take you to capture 10 X's', and the last is a 'practice/ infinite time' game type. Right now my strategy is to

How to continuously run my pendulum equation in cocos2d (Objective-C)?

*爱你&永不变心* 提交于 2019-12-12 04:36:52
问题 I got a working equation for the rotation angle of my pendulum as seen in the code below: const float gravity = 9.8; float L = 0.01; double CurrentTime = CACurrentMediaTime(); double angle = 120 * sin(sqrt((gravity/L)*CurrentTime)); But what I can't seam to figure out is how to make the sprite rotate continuously so that it acts just like a pendulum. I only make it move to the current value of the angle at the moment I click run, then it stopes when it reaches that position. Here is what I

Slight pause between sound loop with Simple Audio Engine

自闭症网瘾萝莉.ら 提交于 2019-12-12 04:09:13
问题 When playing background music in Simple Audio Engine with playBackgroundMusic loop:YES , there seems to be a slight delay before the audio loops back to the beginning and starts over again. Is there any way to prevent this slight pause? 回答1: The pause is actually an artefact of the MP3 encoding/compression algorithms. There are ways to suppress the pause, by doing some math on the 'last frame' of the stream and the first frame. Some software tools exist for that. I ended up using Winamp pro

Kobold2d: KKInput anyTouchEndedThisFrame

早过忘川 提交于 2019-12-12 03:52:49
问题 The anyTouchEndedThisFrame must be buggy I´ve tried about everything now, and it will only reckonize a touch that´s ended if I move the finger, if I touch and let go at the same spot it does not reckonize it, If I am wrong please correct me -(void) moveObjectToNewPosition:(KKInput *)input { if (input.anyTouchEndedThisFrame) { [self touchesEnded:[input locationOfAnyTouchInPhase:KKTouchPhaseAny]]; } if (input.anyTouchBeganThisFrame) { [self touchesBegan:[input locationOfAnyTouchInPhase

Adding a integer after variable name to access

核能气质少年 提交于 2019-12-12 03:46:27
问题 I am trying to run an action, but i want to decide which. for example i have [bullet runAction:bullet1]; I want to be able to manipulate the variable its accessing something like [bullet runAction:bullet%d, i]; 回答1: use an array of actions, and use the index to access them NSArray bulletActions = @[bullet1, bubble2]; [bullet runAction:bulletActions[0]]; I think it will serve your needs 回答2: You need to use selector SEL selector=NSSelectorFromString([NSString stringWithFormat:@"bullet%d", i]);