Pause/Resume and other simple concepts I can't figure out.

General discussion about the R.U.B.E editor
Post Reply
Phantom Ppepper
Posts: 22
Joined: Tue Sep 10, 2013 3:59 am

Pause/Resume and other simple concepts I can't figure out.

Post by Phantom Ppepper »

First of all, BRAVO with the recent update! I feel like I'm able to move 10 times faster since the new RUBE menu tutorials, by the way. But if you give me long enough, I'll manage to break something :roll:

I'm trying to figure out the best way to go about making a simple pause/resume menu while using RUBE as my UI builder, which is working well. I guess I'm a little confused on how to push and pop rube scenes?

Also, for other "data" based elements like current score, high score, lives etc, would it be better to use cocos2d on top of the rube scene?

Thanks a million ya'll.

G
Phantom Ppepper
Posts: 22
Joined: Tue Sep 10, 2013 3:59 am

Re: Pause/Resume and other simple concepts I can't figure ou

Post by Phantom Ppepper »

ok - I think I might have this one...

In my hud layer, ive got a pause button with the action "pauseGame" assigned to it. And I've got a pause layer - another rube scene - with 2 buttons: one ruturns home and the other resumes the game. the resume button has an action called "resumeGame". So, over in XCODE, I added the following to ButtonRUBELayer.mm:

Code: Select all

-(void)pauseGame
{
    [[CCDirector sharedDirector] pushScene:[pauseLayer node]];
    [[CCDirector sharedDirector] pause];
        
}
    
-(void)resumeGame
{
    [[CCDirector sharedDirector] popScene];
    [[CCDirector sharedDirector] resume];
}
So far, this seems to be working... there are a few things that need to be adjusted. But is this smart coding?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Pause/Resume and other simple concepts I can't figure ou

Post by iforce2d »

Yes, seems like a decent plan. A couple of tactics I have used to do this with just one layer for the button are:
- use same button and switch texture
- move buttons off-screen temporarily

The first method will only work well if the pause and resume textures are the same dimensions. In cocos2d you can switch the texture of a sprite like:
[sprite setTexture:[[CCSprite spriteWithFile:@"whatever.png"] texture]];
Note that the button will still call the same method regardless of which texture it has, so you will need to also keep track of which state it is currently in, so that you know what should happen when the user presses it.

The second method is better if the buttons being swapped between are different sizes, shapes, or positions, and also lets you keep a separate method call for each. You can just SetTransform for the two bodies involved to put one of them in the button position and the other one offscreen somewhere so it can't be seen.

If you're using the 'hover state' feature that I showed in the video where buttons temporarily switch their texture while being pressed, the first method might screw that up.
Post Reply