#import "MainScene.h"
static const CGFloat scrollSpeed = 80.f;
@implementation MainScene {
CCSprite *_hero;
CCPhysicsNode *_physicsNode;
CCNode *_ground1;
CCNode *_ground2;
NSArray *_grounds;
NSTimeInterval _sinceTouch;
}
- (void)didLoadFromCCB {
_grounds = @[_ground1, _ground2];
self.userInteractionEnabled =TRUE;
}
- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
[_hero.physicsBody applyImpulse:ccp(0, 400.f)];
// _sinceTouch+=delta;
_hero.rotation = clampf(_hero.rotation, -30.f, 90.f);
if (_hero.physicsBody.allowsRotation) {
float angularVelocity = clampf(_hero.physicsBody.angularVelocity, -2.f, 1.f);
_hero.physicsBody.angularVelocity = angularVelocity;
}
//position of hero
- (void)update: (CCTime) delta {
_hero.position = ccp(_hero.position.x + delta * scrollSpeed, _hero.position.y);
_physicsNode.position = ccp(_physicsNode.position.x - (scrollSpeed *delta), _physicsNode.position.y);
// loop the ground
for (CCNode *ground in _grounds) {
// get the world position of the ground
CGPoint groundWorldPosition = [_physicsNode convertToWorldSpace:ground.position];
// get the screen position of the ground
CGPoint groundScreenPosition = [self convertToNodeSpace:groundWorldPosition];
// if the left corner is one complete width off the screen, move it to the right
if (groundScreenPosition.x <= (-1 * ground.contentSize.width)) {
ground.position = ccp(ground.position.x + 2 * ground.contentSize.width, ground.position.y);
// clamp velocity
float yVelocity = clampf(_hero.physicsBody.velocity.y, -1 * MAXFLOAT, 200.f);
_hero.physicsBody.velocity = ccp(0, yVelocity);
NSTimeInterval _sinceTouch;
if ((_sinceTouch > 0.5f)) {
[_hero.physicsBody applyAngularImpulse:-40000.f*delta];
}
}
- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
[_hero.physicsBody applyImpulse:ccp(0, 400.f)];
[_hero.physicsBody applyAngularImpulse:10000.f];
_sinceTouch = 0.f;
}
}
}
@end
获取未声明的标识符“ - (void)update:(CCTime)delta {”for update
我已经尝试了一段时间来解决这个问题,但似乎无法弄清楚如何在该错误上声明变量任何帮助将非常感谢这是一个学校项目,它很快就会重新开始。
谢谢:)
答案 0 :(得分:0)
您需要结束&#34; }
&#34;对于这种方法:
- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
它不平衡。