Cocos2d and IBook style page turning

General discussion about iOS development - a great place to ask questions about iOS or help out others. For discussion of the official tutorials, see the Official Tutorials forum.

Cocos2d and IBook style page turning

Postby glebv » Mon Feb 06, 2012 9:50 am

Hi!

I try to make an interactive book which is used cocos2d with Box2D.
I'd want to add a page turning as IBook style but my book should work under ios 4.x and I cannot use PageViewController which was added on ios 5.0

What is the best and the simplest way?
I want to try to integrate Leaves lib (https://github.com/brow/leaves) but I guess that it will work only with static images(pages)

Could you suggest me some library or approach which help me to solve my task ?

Thanks a lot.
glebv
n00b
 
Posts: 3
Joined: Mon Jan 09, 2012 8:38 am
Has thanked: 0 time
Been thanked: 0 time

Re: Cocos2d and IBook style page turning

Postby Elliott » Mon Feb 06, 2012 8:45 pm

Hi,

There a stunning page curl effect built into cocos2d which you can achieve with the following code;

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

CGSize screenSize = [[CCDirector sharedDirector] winSize];

UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];

if (location.x < (screenSize.width * .25) && location.y < (screenSize.height * .25)) {

CCTransitionPageTurn *transition = [CCTransitionPageTurn transitionWithDuration:1.75 scene:[Page1 scene] backwards:YES];
[[CCDirector sharedDirector] replaceScene:transition];
}

if (location.x > (screenSize.width * .75) && location.y < (screenSize.height * .25)) {

CCTransitionPageTurn *transition = [CCTransitionPageTurn transitionWithDuration:1.75 scene:[Page3 scene] backwards:NO];
[[CCDirector sharedDirector] replaceScene:transition];
}
}

In the code we are on Page2 and can go back to page 1 or forward to page 3. I have set the screen touch area to be in the bottom left and right corners for going backwards and forwards as seen above. The corners can be either tapped or swiped. Make sure you add backwards:YES]; or NO]; to determine the direction you would like the page to curl.

Hope this helps =]
User avatar
Elliott
Uber Haxx0r
 
Posts: 455
Joined: Sun Jan 02, 2011 10:34 pm
Location: UK
Has thanked: 4 times
Been thanked: 113 times

Re: Cocos2d and IBook style page turning

Postby glebv » Mon Feb 06, 2012 9:10 pm

Hi,

Thanks a lot for quick response. I am newbie on the forum and you answer is very significant for me.
In this implementation, the page does not follow a finger.
I'd wand to do something likes iBook or paperstack (http://api.mutado.com/mobile/paperstack/)

But I don't know is it possible with cocos2d ?
glebv
n00b
 
Posts: 3
Joined: Mon Jan 09, 2012 8:38 am
Has thanked: 0 time
Been thanked: 0 time

Re: Cocos2d and IBook style page turning

Postby Elliott » Mon Feb 06, 2012 9:22 pm

Sorry I don't know how to make it work where it follows the finger. If you find a soltion be sure to post it here!
User avatar
Elliott
Uber Haxx0r
 
Posts: 455
Joined: Sun Jan 02, 2011 10:34 pm
Location: UK
Has thanked: 4 times
Been thanked: 113 times

Re: Cocos2d and IBook style page turning

Postby aeberbach » Mon Feb 06, 2012 11:11 pm

Here you go - finger-following page turning code, on github:

https://github.com/ole/leaves/tree/twopages
User avatar
aeberbach
Forum Subject Matter Expert
 
Posts: 1407
Joined: Sat Feb 19, 2011 5:37 am
Has thanked: 13 times
Been thanked: 192 times

Re: Cocos2d and IBook style page turning

Postby glebv » Tue Feb 07, 2012 5:07 am

Hi,

Actually! but I have problems with integration the solution with cocos2d.
I created test project from cocos2d xcode template and added second layer and Leaves lib.
Initialization of cocos was moved from AppDelegate to RootViewControler.
And then began a magic. Only half of screen accepts gesture of turning page.
I've attached my project if it helps to understand the issue.

http://dl.dropbox.com/u/6237556/CocosLeaves.zip
glebv
n00b
 
Posts: 3
Joined: Mon Jan 09, 2012 8:38 am
Has thanked: 0 time
Been thanked: 0 time


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 12 guests