Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ashish |
I trying to construct touchbuttons thru code. First I am manually setting up the tile map and then trying to set up a touchscreenbutton on top of each tile.
I want to extend Tilemap as a Class and achieve this. Very new to extending a Class. I have been able to achieve the desired result by making the TileMap the root Node. However, I want to achieve this by making TileMap as a child of a Node2D (which would be the root node) for future requirements of the game.
This is my present code. At runtime, the code does not seem to enter the make_the_touchButtons function.
extends Node2D
onready var tile = $TileMap
#var grid_offset = Vector2(16,16)
var kount =0
class FCTile:
extends TileMap
var tile_position = {}
var grid_offset = Vector2(16,16)
var kount
var cellids = get_used_cells_by_id(0)
var countingCells = cellids.size()
var actual_position = PoolVector2Array()
func make_the_touchButtons():
for i in range (countingCells):
var spark
var tile_position = {}
var completed = []
tile_position[i] = map_to_world(cellids[i])
actual_position.append(tile_position[i])
spark = TouchScreenButton.new()
self.add_child(spark)
spark.position = tile_position[i]
spark.name = 'spark'+str(i)
completed.append(false)
spark.normal = load("res://lock_red.png")
spark.pressed = load("res://star_09.png")
spark.z_index = 99
func _ready():
tile = FCTile.new()
add_child(tile)
tile.make_the_touchButtons()
Please help. Thanks in advance.