0 votes

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 makethetouchButtons 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])
            spark = TouchScreenButton.new()
            spark.position = tile_position[i]
            spark.name = 'spark'+str(i)

            spark.normal = load("res://lock_red.png")
            spark.pressed = load("res://star_09.png")
            spark.z_index = 99

func _ready():
    tile = FCTile.new()     

Please help. Thanks in advance.

Godot version 3.2.2
in Engine by (100 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.