diff --git a/arcade/future/splash.py b/arcade/future/splash.py new file mode 100644 index 000000000..07479d697 --- /dev/null +++ b/arcade/future/splash.py @@ -0,0 +1,78 @@ +""" +An experimental splash screen for arcade. + +This is a simple splash screen that shows the arcade logo +for a few seconds before the actual game starts. + +If arcade is properly installed, you can run this script with: +python -m arcade.gui.experimental.splash +""" + +import arcade +from arcade import Sprite, SpriteList, Text, View + + +class ArcadeSplash(View): + """This view shows an arcade splash screen before the actual game starts. + + Args: + view: Next view to show after the splash screen. + duration: The duration of the splash screen in seconds. (Default 3 seconds) + dark_mode: If True, the splash screen will be shown in dark mode. (Default False) + """ + + def __init__(self, view: View, duration: int = 3, dark_mode: bool = False): + super().__init__() + self._next_view = view + self._duration = duration + self._time = 0.0 + self._dark_mode = dark_mode + + _text_color = (255, 255, 255, 255) if dark_mode else (0, 0, 0, 255) + self._bg_color = (0, 0, 0, 255) if dark_mode else arcade.color.WHITE_SMOKE + + self._sprites: SpriteList[Sprite] = SpriteList() + self._logo = Sprite( + arcade.load_texture(":system:/logo.png"), + center_x=self.window.center_x, + center_y=self.window.center_y, + ) + self._logo.size = 300, 300 + self._sprites.append(self._logo) + + self._text = Text( + "Python Arcade", + anchor_x="center", + x=self.window.center_x, + y=self._logo.bottom - 20, + color=_text_color, + font_size=40, + bold=True, + ) + + def on_show_view(self): + """Set background color and reset time.""" + arcade.set_background_color(self._bg_color) + self._time = 0.0 + self._logo.alpha = 0 + + def on_update(self, delta_time: float): + """Update the time and switch to the next view after the duration.""" + self._time += delta_time + if self._time >= self._duration: + self.window.show_view(self._next_view) + + # fade in arcade logo + self._logo.alpha = min(255, int(255 * self._time / self._duration)) + + def on_draw(self): + """Draw the sprites and text.""" + self.clear() + self._sprites.draw() + self._text.draw() + + +if __name__ == "__main__": + window = arcade.Window() + window.show_view(ArcadeSplash(ArcadeSplash(dark_mode=True, view=arcade.View()))) + arcade.run() diff --git a/arcade/gui/widgets/image.py b/arcade/gui/widgets/image.py index 1df3e4151..a38c01e96 100644 --- a/arcade/gui/widgets/image.py +++ b/arcade/gui/widgets/image.py @@ -24,6 +24,10 @@ class UIImage(UIWidget): """ texture: Union[Texture, NinePatchTexture] = Property() # type: ignore + """Texture to show""" + alpha: int = Property(255) # type: ignore + """Alpha value of the texture, value between 0 and 255. + 0 is fully transparent, 255 is fully visible.""" def __init__( self, @@ -41,6 +45,7 @@ def __init__( **kwargs, ) bind(self, "texture", self.trigger_render) + bind(self, "alpha", self.trigger_full_render) @override def do_render(self, surface: Surface): @@ -53,4 +58,5 @@ def do_render(self, surface: Surface): width=self.content_width, height=self.content_height, tex=self.texture, + alpha=self.alpha, ) diff --git a/arcade/resources/system/logo.png b/arcade/resources/system/logo.png new file mode 100644 index 000000000..cb4037010 Binary files /dev/null and b/arcade/resources/system/logo.png differ