Handle multiple resolutions in most demos

This makes demos render correctly on hiDPI displays,
while also demonstrating how to handle multiple resolutions.

The 3D in 2D demo now uses "3D No-Effects" for the 3D viewport,
which is faster to render. Thanks to this, 4× MSAA is now enabled
for a better result.

The background loading demo now uses mipmaps for better-looking images.

The material testers demo now samples mouse input in a
resolution-independent manner when panning.

Default clear colors were also changed in some projects for visual
consistency with the project's theme.
This commit is contained in:
Hugo Locurcio
2019-07-20 12:36:37 +02:00
parent eb814782c6
commit a45b84a5ad
249 changed files with 1488 additions and 562 deletions

View File

@@ -3,6 +3,9 @@
importer="texture"
type="StreamTexture"
path="res://.import/ball.png-9a4ca347acb7532f6ae347744a6b04f7.stex"
metadata={
"vram_texture": false
}
[deps]
@@ -17,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2

View File

@@ -3,6 +3,9 @@
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]

View File

@@ -9,7 +9,7 @@ func _player_connected(_id):
#someone connected, start the game!
var pong = load("res://pong.tscn").instance()
pong.connect("game_finished", self, "_end_game", [], CONNECT_DEFERRED) # connect deferred so we can safely erase it from the callback
get_tree().get_root().add_child(pong)
hide()
@@ -24,20 +24,20 @@ func _player_disconnected(_id):
func _connected_ok():
# will not use this one
pass
# callback from SceneTree, only for clients (not server)
# callback from SceneTree, only for clients (not server)
func _connected_fail():
_set_status("Couldn't connect",false)
get_tree().set_network_peer(null) #remove peer
get_node("panel/join").set_disabled(false)
get_node("panel/host").set_disabled(false)
func _server_disconnected():
_end_game("Server disconnected")
##### Game creation functions ######
func _end_game(with_error=""):
@@ -45,16 +45,16 @@ func _end_game(with_error=""):
#erase pong scene
get_node("/root/pong").free() # erase immediately, otherwise network might show errors (this is why we connected deferred above)
show()
get_tree().set_network_peer(null) #remove peer
get_node("panel/join").set_disabled(false)
get_node("panel/host").set_disabled(false)
_set_status(with_error, false)
func _set_status(text, isok):
#simple way to show status
#simple way to show status
if isok:
get_node("panel/status_ok").set_text(text)
get_node("panel/status_fail").set_text("")
@@ -70,7 +70,7 @@ func _on_host_pressed():
#is another server running?
_set_status("Can't host, address in use.",false)
return
get_tree().set_network_peer(host)
get_node("panel/join").set_disabled(true)
get_node("panel/host").set_disabled(true)
@@ -81,17 +81,17 @@ func _on_join_pressed():
if not ip.is_valid_ip_address():
_set_status("IP address is invalid", false)
return
var host = NetworkedMultiplayerENet.new()
host.set_compression_mode(NetworkedMultiplayerENet.COMPRESS_RANGE_CODER)
host.create_client(ip, DEFAULT_PORT)
get_tree().set_network_peer(host)
_set_status("Connecting..", true)
### INITIALIZER ####
func _ready():
# connect all the callbacks related to networking
get_tree().connect("network_peer_connected", self, "_player_connected")
@@ -99,4 +99,4 @@ func _ready():
get_tree().connect("connected_to_server", self, "_connected_ok")
get_tree().connect("connection_failed", self, "_connected_fail")
get_tree().connect("server_disconnected", self, "_server_disconnected")

View File

@@ -3,11 +3,20 @@
[ext_resource path="res://lobby.gd" type="Script" id=1]
[node name="lobby" type="Control"]
margin_right = 40.0
margin_bottom = 40.0
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -320.0
margin_top = -200.0
margin_right = 320.0
margin_bottom = 200.0
size_flags_horizontal = 2
size_flags_vertical = 2
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="title" type="Label" parent="."]
margin_left = 210.0
@@ -83,6 +92,5 @@ size_flags_horizontal = 2
size_flags_vertical = 0
custom_colors/font_color = Color( 1, 0, 0, 1 )
align = 1
[connection signal="pressed" from="panel/host" to="." method="_on_host_pressed"]
[connection signal="pressed" from="panel/join" to="." method="_on_join_pressed"]

View File

@@ -3,6 +3,9 @@
importer="texture"
type="StreamTexture"
path="res://.import/paddle.png-0e798fb0912613386507c9904d5cc01a.stex"
metadata={
"vram_texture": false
}
[deps]
@@ -17,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2

View File

@@ -12,36 +12,36 @@ sync func update_score(add_to_left):
score_left += 1
get_node("score_left").set_text(str(score_left))
else:
score_right += 1
get_node("score_right").set_text(str(score_right))
var game_ended = false
if score_left == SCORE_TO_WIN:
get_node("winner_left").show()
game_ended = true
elif score_right == SCORE_TO_WIN:
get_node("winner_right").show()
game_ended = true
if game_ended:
get_node("exit_game").show()
get_node("ball").rpc("stop")
func _on_exit_game_pressed():
emit_signal("game_finished")
emit_signal("game_finished")
func _ready():
# by default, all nodes in server inherit from master
# while all nodes in clients inherit from puppet
if get_tree().is_network_server():
if get_tree().is_network_server():
#if in the server, get control of player 2 to the other peeer, this function is tree recursive by default
get_node("player2").set_network_master(get_tree().get_network_connected_peers()[0])
else:
#if in the client, give control of player 2 to itself, this function is tree recursive by default
get_node("player2").set_network_master(get_tree().get_network_unique_id())
#let each paddle know which one is left, too
get_node("player1").left = true
get_node("player2").left = false

View File

@@ -2,29 +2,37 @@
[ext_resource path="res://pong.gd" type="Script" id=1]
[ext_resource path="res://separator.png" type="Texture" id=2]
[ext_resource path="res://paddle.tscn" type="PackedScene" id=3]
[ext_resource path="res://ball.tscn" type="PackedScene" id=4]
[ext_resource path="res://ball.tscn" type="PackedScene" id=3]
[ext_resource path="res://paddle.tscn" type="PackedScene" id=4]
[node name="pong" type="Node2D"]
script = ExtResource( 1 )
[node name="ColorRect" type="ColorRect" parent="."]
margin_right = 640.0
margin_bottom = 400.0
color = Color( 0.141176, 0.152941, 0.164706, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="separator" type="Sprite" parent="."]
position = Vector2( 320, 200 )
texture = ExtResource( 2 )
[node name="player1" parent="." instance=ExtResource( 3 )]
[node name="player1" parent="." instance=ExtResource( 4 )]
position = Vector2( 32.49, 188.622 )
[node name="sprite" parent="player1" index="0"]
self_modulate = Color( 1, 0, 0.960938, 1 )
[node name="player2" parent="." instance=ExtResource( 3 )]
[node name="player2" parent="." instance=ExtResource( 4 )]
position = Vector2( 608.88, 188.622 )
[node name="sprite" parent="player2" index="0"]
self_modulate = Color( 0, 0.929688, 1, 1 )
[node name="ball" parent="." instance=ExtResource( 4 )]
[node name="ball" parent="." instance=ExtResource( 3 )]
position = Vector2( 320.387, 189.525 )
[node name="score_left" type="Label" parent="."]
@@ -77,6 +85,9 @@ size_flags_horizontal = 2
size_flags_vertical = 2
text = "Exit Game"
[node name="Camera2D" type="Camera2D" parent="."]
offset = Vector2( 320, 200 )
current = true
[connection signal="pressed" from="exit_game" to="." method="_on_exit_game_pressed"]
[editable path="player1"]

View File

@@ -27,6 +27,8 @@ gdscript/warnings/return_value_discarded=false
window/size/width=640
window/size/height=400
window/stretch/mode="2d"
window/stretch/aspect="expand"
stretch_2d=true
[gdnative]
@@ -48,4 +50,5 @@ move_up={
[rendering]
quality/2d/use_pixel_snap=true
viewport/default_clear_color=Color( 0, 0, 0, 1 )

View File

@@ -3,6 +3,9 @@
importer="texture"
type="StreamTexture"
path="res://.import/separator.png-f981c8489b9148e2e1dc63398273da74.stex"
metadata={
"vram_texture": false
}
[deps]
@@ -17,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2