Godot Version
Godot 4.5.stable
Question
Im creating my own tile system (because i need greater manipulation over each tile) so i quickly coded this draw function that draws tiles that loop over when they reach the edge of the screen so it creates seamless endless tiles all around. When i hit a specific position in the camera position a row/column of tiles (when the Y is applied) dissapears entirely. Is it a problem with the math? Or is something else happening here.
extends Node2D
const ICON = preload("uid://dlbmoqm541v64") #godot icon
const TILE_SIZE: float = 128
@onready var cam: Camera2D = $"../Cam"
var LevelData = []
func _draw() -> void:
var camPos = cam.position
var frameSize = get_viewport().size
var fillRange = Vector2(1+ceil(frameSize.x/TILE_SIZE),ceil(frameSize.y/TILE_SIZE)) #gets the maximum ammount of tiles that will fill the screen bin both x and y
print(fillRange)
for x in range(fillRange.x):
for y in range(fillRange.y):
var alignX = (-TILE_SIZE/2)+(frameSize.x/2)-round(((x*TILE_SIZE)-camPos.x)/TILE_SIZE)*TILE_SIZE
var alignY = 0 #this is left at 0 because ill copy the X equation above once its refined
draw_texture(ICON, Vector2(alignX,alignY))
func _ready() -> void:
for i in range(100):
LevelData.append(randi_range(0,1)) #right now not used for anything
print(LevelData)
func _process(_delta: float) -> void:
queue_redraw()
Video showing this: (couldnt upload since im a new account) (and apologies if its low qual, keeping the file size low)