【发布时间】:2021-07-26 17:09:21
【问题描述】:
我正在尝试制作一个 2d 平台游戏,您可以在其中生成一个对象并尝试在它落下之前在空中跳跃。
问题是当我尝试生成瓷砖时它不会生成光标在哪里 它为我不知道如何摆脱它的位置添加了一个相对值。
您会看到,当我尝试实例化一个场景时,它会考虑光标位置和视口值,但随后发生了一些事情,我发现对象生成得太远了。
see where is the cursor at and where did the tile spawn
-here is how I'm grouping the nodes and scenes-
这是我正在使用的脚本,它在 player1 场景中
extends KinematicBody2D
#
var score : int = 0
export var speed : int = 200
export var jumpforce : int = 600
export var gravity : int = 800
onready var AB1 = preload("res://player1AB.tscn")
var vel :Vector2 = Vector2()
onready var sprite : Sprite = get_node("sprite_idile")
onready var ui : Node = get_node("/root/mainscene1/CanvasLayer/ui")
onready var audioplayer : Node = get_node("/root/mainscene1/Camera2D/audio_player")
func _physics_process(delta):
vel.x = 0
# movement inputs
if Input.is_action_pressed("move_left"):
vel.x -= speed
if Input.is_action_pressed("move_right"):
vel.x += speed
# applying the velcoty
vel = move_and_slide(vel,Vector2.UP)
#apllying gravty
vel.y += gravity * delta
#jump input
if Input.is_action_just_pressed("jump") and is_on_floor():
vel.y -= jumpforce
# where the sprite facing
if vel.x < 0:
sprite.flip_h = true
if vel.x > 0:
sprite.flip_h = false
if Input.is_action_just_pressed("restart"):
death()
func death ():
get_tree().reload_current_scene()
func collect_coin (value):
score += value
ui.set_score_text(score)
audioplayer.play_coin_sfx()
func _input(event):
if event.is_action_pressed("click"):
var ABT1 = AB1.instance()
add_child(ABT1)
var XN = null
XN = get_viewport().get_mouse_position()
ABT1.position = XN
重要的东西
onready var AB1 = preload("res://player1AB.tscn")
func _input(event):
if event.is_action_pressed("click"):
var ABT1 = AB1.instance()
add_child(ABT1)
var XN = null
XN = get_viewport().get_mouse_position()
ABT1.position = XN
Godot 表单中的同样问题,如果可能,请检查一下,以防有人在那里回答
【问题讨论】: