Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Kayou |
Hi everyone!
I’m on a mobile game project with my girlfriend and I, and we are stuck on a problem with our game…
Let me explain :
We are making an Idle Tycoon game where the player will have to place buildings.
In order to achieve that, I’ve got the idea of clicking on a button to activate an new popup menu where the player will have the ability to place confirmations tiles (to see where the buildings are gonna be build).
I’ve already done this part (I will give you the code).
The problem is where we want to make a confirmation button (the problem is also the same for the cancel button) :
Once we click on the confirmaton button… A “confirm tile” is summonned beneath the button! So the player is actually building an “extra” building under the button, and no matter what I try (getting the button position and see if the click is inside etc) it’s not working and I still didn’t find any help over the internet.
I’m stuck on this problem since 3 days and I would really appreciate some hints so I can continue programming it !
extends TileMap
var terre = false
var charbon = false
var nbrplaced = 0
var popup1
var confirm_button = false
onready var buttonpos =
get_parent().get_node("Control/Canvas/ConfirmMenu/Confirmbutton")
signal coal1()
func _ready():
popup1 = get_parent().get_node("Control/Canvas/Buildmenu")
var tilemap_rect = get_parent().get_node("TileMap").get_used_rect()
var tilemap_cell_size = get_parent().get_node("TileMap").cell_size
get_parent().get_node("Camera2D").limit_left = tilemap_rect.position.x *
tilemap_cell_size.x
get_parent().get_node("Camera2D").limit_right = tilemap_rect.end.x *
tilemap_cell_size.x
get_parent().get_node("Camera2D").limit_top = tilemap_rect.position.y *
tilemap_cell_size.y
get_parent().get_node("Camera2D").limit_bottom = tilemap_rect.end.y *
tilemap_cell_size.y
pass
func _process(delta):
if get_global_mouse_position().distance_to(buttonpos.get_position()) > 30:
print(buttonpos.get_global_position())
print(get_local_mouse_position())
if Input.is_mouse_button_pressed(BUTTON_LEFT) and terre == true: # Test avec terre BETA
var mousePos = get_global_mouse_position()
var loc = world_to_map(mousePos)
var cell = get_cell(loc.x,loc.y)
if(cell == 15):
set_cell(loc.x,loc.y, 13)
if Input.is_mouse_button_pressed(BUTTON_LEFT) and charbon == true: # Test avec charbon
var mousePos = get_global_mouse_position()
var loc = world_to_map(mousePos)
var cell = get_cell(loc.x,loc.y)
if(cell == 13):
set_cell(loc.x,loc.y, 0)
nbrplaced = nbrplaced + 1
emit_signal("coal1")
Also I know why it’s actually not working, it’s because the button position is “static” and is not following the camera, i’m using a CanvasLayer.
Also I’m gonna give you some screenshots of my scene tree so you could probably find where the problem is :
Thank you for helping me