如何在不受玩家时刻影响的情况下为视差层添加动作?例如在后面的云

问题描述 投票:0回答:1

我正在研究具有三个视差层(天空,山脉和云)天空和山地层根据视差层的运动比例属性移动的2D平台游戏,并且我在云层中添加了一个脚本以便它继续向一个方向移动即使玩家空闲或不移动,也就是从右到左。但我遇到的问题是,当玩家移动或跳跃时,云也会获得跳跃效果并继续跟随玩家。无论玩家的时刻如何,如何使云向一个方向移动?我的云脚本:

extends ParallaxBackground

var dst = 0

func _ready():
    set_process(true)
    pass 

func _process(delta):
    dst -= 50 *delta
    set_scroll_offset(Vector2(dst,0))

this is image for reference

parallax godot gdscript
1个回答
0
投票

我假设在这样的游戏中,你将相机连接到播放器,因此它可以跟随玩家的移动。你有可能让云成为相机或播放器的孩子吗?据我了解,侧滚动游戏中的视差背景因此构成:

Node2D
 |_ParallaxBackground    #Base background layer 
 | |_Sprite
 | |_ParallaxLayer        # Middle-back layer (moves at own speed - defined by you)
 | | |_Sprite
 | |_ParallaxLayer2        # Middle-Fore layer (moves at own speed - defined by you)
 | | |_Sprite
 | |_ParallaxLayer3        # Foreground layer (moves at own speed - defined by you)
 |   |_Sprite
 |_KinematicBody2D         #Player Physics/movement
   |_CollisionShape2D      #player collision
   | |_Sprite              #Player image
   |_Camera2D              #camera attached to player (follows player movement)

从这个结构中可以看出,视差层(及其运动)与播放器/摄像机分开。您应该能够分别控制所有视差层的速度(包括云层),而不会受到玩家移动的任何影响。

我将是第一个承认,我不是专家,因为我对Godot很新,我只是尽力提供有用的建议,尽管我对发动机的知识不够全面。话虽如此,请告诉我这个解决方案是否适合您,因为这些知识将有助于加强我对Godot的理解并提高我帮助他人的能力。

© www.soinside.com 2019 - 2024. All rights reserved.