Godot 4.3
The game works well on PC but objects won’t spawn in Android
the code:
func generateobs():
#generate ground obsticles
if obsticles.is_empty() or lastobs.position.x < score + randi_range(10,50):
var obs_type = obsticleTypes[randi() % obsticleTypes.size()]
var hardObs = hardObsTypes[randi() % hardObsTypes.size()]
var obs
var max_obs = difficulty + 1
for i in range(randi() % max_obs + 1):
obs = obs_type.instantiate()
var obs_height = obs.get_node("Sprite2D").texture.get_height()
var obs_scale = obs.get_node("Sprite2D").scale
var obs_x : int = screenSize.x + score + 1000 + (i * 100)
var obs_y : int = screenSize.y - groundHeight - (obs_height * obs_scale.y/2) + 5
lastobs = obs
AddObs(obs,obs_x,obs_y)
#random drone chance
if difficulty == MaxDifficulty:
if (randi() % 2) == 0:
obs = Drone.instantiate()
var obs_x : int = screenSize.x + score + 100
var obs_y : int = droneHeight[randi() % droneHeight.size()]
AddObs(obs,obs_x,obs_y)
else:
for i in range(1):
obs = hardObs.instantiate()
var obs_height = obs.get_node("Sprite2D").texture.get_height()
var obs_scale = obs.get_node("Sprite2D").scale
var obs_x : int = screenSize.x + score + 1000 + (i * 100)
var obs_y : int = screenSize.y - groundHeight - (obs_height * obs_scale.y/2) + 5
lastobs = obs
AddObs(obs,obs_x,obs_y)
func AddObs(obs,x,y):
obs.position = Vector2i(x, y)
obs.body_entered.connect(hit_obs)
add_child(obs)
obsticles.append(obs)
Thank you for your time