Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-29-2011, 12:15 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 97
hodgey87 is on a distinguished road
Default Counting moves in puzzle?

Hey Everyone,

Just in need of abit of help if possible

Im trying to build a slider puzzle at the moment, id like to be able to count the number of moves that are made in the puzzle. Ive started out like this so far:

play.h set up an integer and label.
Code:
int moves;
CCLabel *moveLabel;
play.m created the label to show the amount of moves.
Code:
moveLabel = [[CCLabel labelWithString: [NSString stringWithFormat:@"Moves: %d", moves] dimensions: CGSizeMake(130, 27) alignment: UITextAlignmentRight fontName:@"Marker Felt" fontSize: 25.0] retain]; 
    moveLabel.position = ccp(55,430); 
    [self schedule: @selector(tick3:) interval:1.0];
[self addChild: moveLabel];
The code that swaps the tiles is like so, i added the moves++; to the bottom of it:

Code:
-(void) changeWithTileA: (Tile *) a TileB: (Tile *) b sel : (SEL) sel{
    CCAction *actionA = [CCSequence actions:[CCMoveTo actionWithDuration:kMoveTileTime position:[b pixPosition]], [CCCallFuncND actionWithTarget:self selector:sel data: a], nil];

    CCAction *actionB = [CCSequence actions:[CCMoveTo actionWithDuration:kMoveTileTime position:[a pixPosition]], [CCCallFuncND actionWithTarget:self selector:sel data: b], nil];
    [a.sprite runAction:actionA];
    [b.sprite runAction:actionB];

    [a trade:b];

    moves++;
}
My thoughts were this would count every move that would be made, but im not sure how to reference this method in the label at the top specifically on this line:

Code:
   [self schedule: @selector() interval:1.0];
tick3: isnt used anywhere, just wondered if any could help me out.

Cheers

Last edited by hodgey87; 03-31-2011 at 08:08 AM.
hodgey87 is offline   Reply With Quote
Old 03-30-2011, 04:56 AM   #2 (permalink)
Registered Member
 
Join Date: Mar 2011
Location: Delhi
Posts: 1
Rithika8765 is on a distinguished road
Default Reply

Nice stuff.
Rithika8765 is offline   Reply With Quote
Old 03-30-2011, 12:25 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 97
hodgey87 is on a distinguished road
Default

Anyone able to help?
hodgey87 is offline   Reply With Quote
Old 03-30-2011, 07:59 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

By tick3: isn't used anywhere, do you mean you have written a method called that? Btw, I haven't had any experience in Cocos2d.

Why don't you create a function that updates the label and call that function every time a move is made?
Domele is offline   Reply With Quote
Old 03-31-2011, 08:10 AM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 97
hodgey87 is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
By tick3: isn't used anywhere, do you mean you have written a method called that? Btw, I haven't had any experience in Cocos2d.

Why don't you create a function that updates the label and call that function every time a move is made?
Cheers for your reply, i know i used tick3: just as an example, in the label i thought i could call the tile swapping method using this:

Code:
[self schedule: @selector(  ) interval:1.0];
But im not sure how to actually call:

Code:
-(void) changeWithTileA: (Tile *) a TileB: (Tile *) b sel : (SEL) sel{
    CCAction *actionA = [CCSequence actions:[CCMoveTo actionWithDuration:kMoveTileTime position:[b pixPosition]], [CCCallFuncND actionWithTarget:self selector:sel data: a], nil];

    CCAction *actionB = [CCSequence actions:[CCMoveTo actionWithDuration:kMoveTileTime position:[a pixPosition]], [CCCallFuncND actionWithTarget:self selector:sel data: b], nil];
    [a.sprite runAction:actionA];
    [b.sprite runAction:actionB];

    [a trade:b];

    moves++;
}
hodgey87 is offline   Reply With Quote
Old 04-02-2011, 10:29 PM   #6 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Why don't you just call the method directly? Why do you need a scheduler (not really familiar with schedulers)?
Domele is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 427
7 members and 420 guests
chemistry, Emy, hussain1982, mistergreen2011, Retouchable, skrew88, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,922
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:15 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0