Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- i have two animations declared in the player class, and i want to run then from another class but i can't here's my code:
- player.h
- <code>
- @interface Player : CCSprite {
- CCAnimate *animationOllie;
- CCRepeatForever *repeatNormal;
- }
- </code>
- player.m:
- <code>
- @implementation Player
- -(id)initWithFile:(NSString *)filename
- {
- if (self = [super initWithFile:filename]) {
- self.velocity = ccp(0.0, 0.0);
- CCAnimation *ollie = [CCAnimation animation];
- [ollie setDelayPerUnit:0.05f];
- [ollie addSpriteFrameWithFilename:@"ollie1.png"];
- [ollie addSpriteFrameWithFilename:@"ollie2.png"];
- animationOllie = [CCAnimate actionWithAnimation:ollie];
- CCAnimation *normal = [CCAnimation animation];
- [normal setDelayPerUnit:0.05f];
- [normal addSpriteFrameWithFilename:@"normal1.png"];
- [normal addSpriteFrameWithFilename:@"normal2.png"];
- CCAnimate *animationNormal = [CCAnimate actionWithAnimation:normal];
- repeatNormal = [CCRepeatForever actionWithAction:animationNormal];
- [self runAction:repeatNormal];
- }
- return self;
- }
- -(void)animateThePlayer {
- [self stopAction:repeatNormal];
- [self runAction:animationOllie];
- }
- </code>
- And in the GameScene Class:
- GameScene.h:
- @interface GamePlayLayer : CCLayerColor {
- float yVel;
- }
- GameScene.m:
- <code>
- #import "Player.h"
- @interface GamePlayLayer()
- {
- Player *player;
- }
- @end
- @implementation GamePlayLayer
- -(id) init
- {
- if( (self=[super initWithColor:ccc4(255,255,255,255)] )) {
- player = [[Player alloc] initWithFile:@"normal1.png"];
- [self addChild:player];
- self.isTouchEnabled = YES;
- player.position = ccp(85,70);
- [self schedule:@selector(update:)];
- }
- return self;
- }
- -(void)update:(ccTime)dt {
- if (player.position.y > 70) {
- yVel -= 0.1;
- }
- else {
- if (yVel != 5.5) {
- yVel = 0;
- player.position = ccp(player.position.x, 70);
- //xVel = 0;
- }
- }
- player.position = ccp(player.position.x, player.position.y + yVel);
- }
- - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- yVel = 5.5;
- [player animateThePlayer];
- }
- </code>
- And that's it, it builds fine, and everything works but when i click the layer it crashes and i get this message:
- 0x1df609b: movl 8(%edx), %edi
- Thread 1: EXC_BAD_ACCESS (code=2, address=0xf
- What can i do? Thanks in advance
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement