#making a blackjack game
1 messages · Page 1 of 1 (latest)
how big is that rectangle
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)
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
If you want to use VisibleOnScreenNotifier2D (it's a 2D node that inherits Node2D), you place it inside of a 2D node and connect to it's signal. The signal will fire when it is visually visible in the camera viewport.
Would I make the ColorRect a child of it?
Yeah I think that should work fine
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
Yeah that's probably better. But I couldn't recommend it personally cause I don't know what math that is haha
Just divide the bounding rectangle by the base viewport size and set the camera zoom equal to that
to bad I can't set the Camera2D size to the size of the Rect lol
The color rect?
That's basically the math paintsimmon is referencing. But instead you set the zoom to output the bounding box size that is wanted
Yeah
You can also change the size of the camera rectangle by changing the display size in project settings
Display > Window > Size?
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
OK.
Yeah that setting should just be the base default size of the game
It's set to a weird number by default though
1152x648
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?
OK so just take the min out of target_zoom?
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?
Use max
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
Well technically that's what you're asking for
add more objects and space them out
there is a button on the screen
Well the color rect is green right?
Is the color rect and button still a child of the camera
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!
I thought that would be zooming in