Hello I working at a sort pipe game for a game jam and i created a class for determine where to put a bunch of area2D nodes to collide with the pipe(in the game you ll have to drag the pipe and the area2D is like a magnet) but the problem is when i use an instance of the class in the tilemap script(if i use the class script it works). From what i seen it enters in methods but they dont change nothing. What I can do?
Grid_System.gd
class_name Grid_System
extends TileMap
#the tile size of the grid
var _tile_Size : Vector2
#the half of the tile size to center it
var _half_Tile_Size : Vector2
#the grid size
var _grid_Size :Vector2
#where the grid start on the map
var _grid_Start:Vector2
#the offset needed to allign the grid with the background
var _offset : Vector2
#helps create the grid
var _grid : Array
#helps getting the position of the anterior created grid
var _positions : Array
#setter for the half/tile set
func set_Tile_Size(tile_Size : Vector2):
print("1")
_tile_Size = tile_Size
_half_Tile_Size = tile_Size / 2
#setter for the grid size depending on the room
func set_Grid_Size(room : Vector2):
_grid_Size = room
#setter for the grid starting position depending on the room
func set_Grid_Start(room : Vector2):
_grid_Start = room
func set_Tile_Offset(offset : Vector2):
_offset = offset
#creates the grid and save its positions in the positions array
func create_Grid():
for x in range(_grid_Start.x + _grid_Size.x):
_grid.append([])
for y in range(_grid_Start.y + _grid_Size.y):
if(y>=_grid_Start.y && x >= _grid_Start.x ):
_grid[x].append(null)
var grid_Pos = Vector2(x,y)
_positions.append(grid_Pos)
print(grid_Pos)
#creates a area2D for future collisions checks
func create_Collider():
for pos in _positions:
print("here")
#creates a area2D node add pos it on center of the tile
var area = Area2D.new()
area.set_position(map_to_world(pos) +_offset - _half_Tile_Size)
add_child(area)
print("made")
#create a circlrhape2D to be added to the collision shape
var shape = CircleShape2D.new()
shape.set_radius(10)
#create a collisionshape2D to be added to the area
var collision = CollisionShape2D.new()
collision.set_shape(shape)
area.add_child(collision)
OxigenRoomGrid.gd
extends Grid_System
#create an object of type grid_system
var grid = Grid_System.new()
func _ready():
#set up the tiles offset/size and grid start pos/size
grid.set_Tile_Size(get_cell_size())
grid.set_Grid_Size(Globals.grid_size["Oxigen_Room"])
grid.set_Grid_Start(Globals.grid_Start_Pos["Oxigen_Room"])
grid.set_Tile_Offset(Globals.tile_offset["Oxigen_Room"])
#create grid and colliders
grid.create_Grid()
grid.create_Collider()
Globals.gd
extends Node
#grid offset to be in centre
var tile_offset : Dictionary = {
"Oxigen_Room": Vector2(-9,3)
}
#grid starting position
var grid_Start_Pos :Dictionary = {
"Oxigen_Room" : Vector2(12,4)
}
#grid starting position
var grid_size :Dictionary = {
"Oxigen_Room" : Vector2(6,5)
}