#making a blackjack game

1 messages · Page 1 of 1 (latest)

kind steeple
#

I'm trying to make a blackjack game, and I can't get the Camera2D to display enough information. I currently have the attached image. Any suggestions on how to fix it?

dry scroll
#

how big is that rectangle

pseudo bramble
#

As it stands, your ColorRect & Buttons node are inside the Camera2D so they will always be stuck there in the Camera's view.

You'll want to have your Camera separate from these. And then do something like find a bounding box between all nodes you want to be visible, center your camera on the center of the bounding box, and then decrease the camera zoom until everything is visible (VisibleOnScreen nodes)

kind steeple
#

ok

#

@pseudo bramble can you give me more details on how to configure the Camera2D to show more? In Godot 4.4.1 not seeing VisibleOnScreen

pseudo bramble
kind steeple
#

Would I make the ColorRect a child of it?

pseudo bramble
#

Yeah I think that should work fine

dry scroll
#

I'm not sure if visibleonscreennotifier is the best way to ensure that everything thing is on screen

#

They won't be on screen until you change the camera zoom, so you'll have to change it for every object until they're all on screen

#

I think it would be better to just use math to calculate what the zoom of the camera would need to be

pseudo bramble
#

Yeah that's probably better. But I couldn't recommend it personally cause I don't know what math that is haha

dry scroll
#

Just divide the bounding rectangle by the base viewport size and set the camera zoom equal to that

kind steeple
#

to bad I can't set the Camera2D size to the size of the Rect lol

dry scroll
#

The color rect?

pseudo bramble
#

That's basically the math paintsimmon is referencing. But instead you set the zoom to output the bounding box size that is wanted

dry scroll
#

Yeah

#

You can also change the size of the camera rectangle by changing the display size in project settings

kind steeple
#

Display > Window > Size?

pseudo bramble
#

Idk if that's the best method. If you ever use config overrides that will get messy. Would be best to do the math to calculate the proper camera zoom based on the bounding box of all 2d nodes that should be visible

kind steeple
#

OK.

dry scroll
#

Yeah that setting should just be the base default size of the game

#

It's set to a weird number by default though

#

1152x648

kind steeple
#

With Google's Gemini help, I came up with this, but it seems not to do the trick: ```extends Node2D

@onready var color_rect: ColorRect = $ColorRect
@onready var camera_2d: Camera2D = $Camera2D

func fit_camera_to_color_rect():
if color_rect == null or camera_2d == null:
return # Handle cases where nodes are not found

var rect_size: Vector2 = color_rect.size
var viewport_size: Vector2 = get_viewport().get_visible_rect().size

var zoom_x: float = viewport_size.x / rect_size.x
var zoom_y: float = viewport_size.y / rect_size.y

var target_zoom: Vector2 = Vector2(min(zoom_x, zoom_y), min(zoom_x, zoom_y)) # Use the smaller zoom to fit both dimensions
camera_2d.zoom = target_zoom

func _ready():
fit_camera_to_color_rect()```

#

is it close?

dry scroll
#

No, you need the larger zoom

#

The larger the zoom, the more stuff you see

kind steeple
#

OK so just take the min out of target_zoom?

pseudo bramble
#

I think you might want camera.get_viewport_rect().size instead of get_viewport().get_visible_rect().size, but that might be the same thing?

dry scroll
#

Probably

#

Unless the camera is on a different viewport than the node with the script

dry scroll
kind steeple
#

yeah that's what I tought, var target_zoom: Vector2 = Vector2(max(zoom_x, zoom_y), max(zoom_x, zoom_y)) # Use the smaller zoom to fit both dimensions just gives me a green screen

pseudo bramble
#

Well technically that's what you're asking for

#

add more objects and space them out

kind steeple
#

there is a button on the screen

dry scroll
#

Well the color rect is green right?

#

Is the color rect and button still a child of the camera

kind steeple
#

this is what I want to see

#

but I only see the green

#

not related, but UI bug? no, editor icon in the node window for this script

#

I found manually setting zoom to .25, .3 seems to do the trick, thanks for the help!

dry scroll
#

I thought that would be zooming in