ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator In-Game Menu
person icon
nightowljrm
Registered User
Quote
2024-07-25 22:20:15

Hi all,

This may be a silly question, but what is the best way to bring up an in-game menu, such as an equipment screen? I am using the first-person camera, so it would need to free the cursor temporarily, then the cursor return to the camera after close.

Is this possible without custom behaviors and actions?

person icon
Guest
Guest
Quote
2024-07-25 22:36:27

Check out ccbSetCursorVisible() in the documentation. You will also need to switch between a simple camera and the fps camera. I'm not sure how you'd do it without using a little JS.

person icon
nightowljrm
Registered User
Quote
2024-07-25 23:12:34

That makes me wonder if I should just use 2D elements that I show and hide based off a button and release the cursor at that time. That seems like it'd be feasible.

person icon
Guest
Guest
Quote
2024-07-25 23:14:57

You'll need to switch out of the FPS camera because the cursor is locked to the center of the screen when it is active. Normally I just parent the simple camera to the FPS camera and switch between them, showing the cursor when needed.

person icon
nightowljrm
Registered User
Quote
2024-07-25 23:16:03

Oh, that's a good idea, so the camera will stay looking where the FPS camera is.

person icon
Guest
Guest
Quote
2024-07-25 23:24:34

You'll need to update the targets of the two cameras to match each other. CC's default behaviors/actions are rather limited. The JS needed to do this is rather basic and not overtly complex.

person icon
Guest
Guest
Quote
2024-07-25 23:28:18

I can make a behavior that links the two cameras together. Just let me know if you need help. You can make a basic inventory fairly simply but say using a black overlay and displaying images inside it that you can click on. There's no reason to use those little boxes people use. Lots of ways to go about it.

person icon
nightowljrm
Registered User
Quote
2024-07-26 00:41:01

I may give it a go myself soon and bump the thread if I need assistance! I used to be a developer several years ago for a year, but it's been so long I'm admittedly a bit sheepish to get back into it. Y'know what they say, if you don't use it, you lose it.

CC is still pretty robust out of the box, but you're right. I have had to use other people's custom behaviors and actions already. I might as well start making my own.

person icon
Guest
Guest
Quote
2024-07-26 01:13:17

That's the spirit. Good luck with your project.

person icon
okeoke
Registered User
Quote
2024-07-26 07:58:24

nightowljrm wrote:
Hi all,

This may be a silly question, but what is the best way to bring up an in-game menu, such as an equipment screen? I am using the first-person camera, so it would need to free the cursor temporarily, then the cursor return to the camera after close.

Is this possible without custom behaviors and actions?


There might be couple of things that you can do.

In case you want your game scene to pause completely, you can simply create a separate menu scene and switch to it. Game scene will be paused but will not be reset, so if you switch back everything is the same as it was before you "paused".

Improvement would be setting mouse cursor to center position before switching to the game scene, that way you can avoid immediate fps camera rotation.
var halfWidht = ccbGetScreenWidth() / 2;
var halfHeight = ccbGetScreenHeight() / 2;

ccbSetMousePos(halfWidht, halfHeight);


Another approach, is as guest mentioned, to switch to a simple camera and show a 2d overlay. There are also a couple of things that you can do to make your life easier. First of all, make a root inventory element, which contains all its other elements as children. That way you only have to hide/show this element. Second thing, there is a strange behavior when switching from fps camera to a simple camera - in case you hold any of the movement buttons fps camera keeps moving, while not active. In order to avoid this behavior you can disable the input before switching the cameras using ccbEmulateKey:
var KEY_W = 87;
var KEY_A = 65;
var KEY_S = 83;
var KEY_D = 68;
ccbEmulateKey(KEY_W, this.moveKeys[KEY_W]);
ccbEmulateKey(KEY_A, this.moveKeys[KEY_A]);
ccbEmulateKey(KEY_S, this.moveKeys[KEY_S]);
ccbEmulateKey(KEY_D, this.moveKeys[KEY_D]);

Switching cameras is pretty simple too. You're taking source camera position and target and then apply it to the target camera, then make the target camera active:
function switchCams(source, target) {
var sourceCamPos = ccbGetSceneNodeProperty(source, 'Position');
var sourceCamTarget = ccbGetSceneNodeProperty(source, 'Target');
ccbSetSceneNodeProperty(target, 'Position', sourceCamPos);
ccbSetSceneNodeProperty(target, 'Target', sourceCamTarget);
ccbSetActiveCamera(target);
}

Remember to also set mouse cursor to center before switching back to the fps cam, overwise you will get it rotated right after the switch.

person icon
okeoke
Registered User
Quote
2024-07-26 08:04:36

Also, you can check the example here:https://zeicmann.itch.io/ccb-var...


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |