Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | PRSoluções |
Hi,
I have some problems with my game because of position of something like background and spawn enemies.
I make a code to always show background on full screen to don’t show that gray mark.
And i think the same problem happen on game, because on macbook if i don’t resize if place correctly, but if i resize it place it wrong.
I think that all problems are related to wrong calc. My function to calc background position:
extends Node2D
func _ready():
var viewportWidth = get_viewport().size.x
var viewportHeight = get_viewport().size.y
var scale = viewportWidth / $Background.texture.get_size().y
$Background.set_position(Vector2(viewportWidth/2, viewportHeight/2))
$Background.set_scale(Vector2(scale, scale))
print("[MainMenu] Viewport size: ", viewportWidth, "/", viewportHeight)
func _on_ButtonStart_pressed():
get_tree().change_scene("res://Scenes/Stage1.tscn")
AND now my code in game to position my enemy spawn:
func spawn():
var spawn = enemy1.instance()
var vp_size = get_viewport().size
var spawn_size = spawn.get_node("Sprite").frames.get_frame("normal", 0).get_size()
var pos_x = (spawn_size.y / 2) + vp_size.x
var pos_y = rand_range((spawn_size.y / 2), (vp_size.y - (spawn_size.y / 2)))
spawn.position = Vector2(pos_x, pos_y)
add_child(spawn)
print("[Game] Spawn at: ", pos_x, "/", pos_y)
Can anyone help me understand it?
Im using latest version of godot.
I have published my game with this problem. If anyone can help me will be nice.
Download here for iOS and Android:
https://flyforcoins.prsolucoes.com/
Thanks.
PRSoluções | 2020-03-09 04:45