boundary exports multiply at _ready() instead of _physics_process()
This commit is contained in:
parent
e0c4bf6077
commit
f9edce3778
1 changed files with 8 additions and 4 deletions
|
@ -13,6 +13,10 @@ export var flip_sprite = true
|
|||
onready var startpos = position
|
||||
onready var sprite = $AnimatedSprite
|
||||
|
||||
func _ready():
|
||||
left_up_boundry *= 8
|
||||
right_down_boundry *= 8
|
||||
|
||||
func _physics_process(delta):
|
||||
if move_direction == 0:
|
||||
move_side_to_side(delta)
|
||||
|
@ -22,10 +26,10 @@ func move_side_to_side(delta):
|
|||
#Move
|
||||
position.x += direction * (speed * delta)
|
||||
#Switch dir
|
||||
if position.x >= startpos.x + (right_down_boundry * 8):
|
||||
if position.x >= startpos.x + (right_down_boundry):
|
||||
direction = -1
|
||||
if flip_sprite == true: sprite.scale.x = -1
|
||||
if position.x <= startpos.x + (-left_up_boundry * 8):
|
||||
if position.x <= startpos.x + (-left_up_boundry):
|
||||
direction = 1
|
||||
if flip_sprite == true: sprite.scale.x = 1
|
||||
|
||||
|
@ -33,9 +37,9 @@ func move_up_and_down(delta):
|
|||
#Move
|
||||
position.y += direction * (speed * delta)
|
||||
#Switch dir
|
||||
if position.y >= startpos.y + (right_down_boundry * 8):
|
||||
if position.y >= startpos.y + (right_down_boundry):
|
||||
direction = -1
|
||||
if flip_sprite == true: sprite.scale.y = 1
|
||||
if position.y <= startpos.y + (-left_up_boundry * 8):
|
||||
if position.y <= startpos.y + (-left_up_boundry):
|
||||
direction = 1
|
||||
if flip_sprite == true: sprite.scale.y = -1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue