Allow for different animated backdrops

This commit is contained in:
JappaWakka 2023-10-05 13:36:02 +02:00
parent ecc0b8400a
commit 3468db7f21
2 changed files with 43 additions and 2 deletions

View File

@ -66,11 +66,13 @@
Water Water
Grass Grass
Texture Texture
Animation
End Enum End Enum
Private _vertices As New List(Of VertexPositionNormalTangentTexture) Private _vertices As New List(Of VertexPositionNormalTangentTexture)
Private _backdropType As BackdropTypes = BackdropTypes.Grass Private _backdropType As BackdropTypes = BackdropTypes.Grass
Private _backdropTexture As Texture2D = Nothing Private _backdropTexture As Texture2D = Nothing
Private _customTexture As Texture2D = Nothing
Private _worldMatrix As Matrix = Matrix.Identity Private _worldMatrix As Matrix = Matrix.Identity
Private _position As Vector3 Private _position As Vector3
Private _rotation As Vector3 Private _rotation As Vector3
@ -79,6 +81,7 @@
Private _height As Integer = 0 Private _height As Integer = 0
Dim WaterAnimation As Animation Dim WaterAnimation As Animation
Dim CustomAnimation As Animation
Private _waterAnimationDelay As Single = CSng(1 / Water.WaterSpeed) Private _waterAnimationDelay As Single = CSng(1 / Water.WaterSpeed)
Private _waterAnimationIndex As Integer = 0 Private _waterAnimationIndex As Integer = 0
@ -89,7 +92,7 @@
Me.New(BackdropType, Position, Rotation, Width, Height, Nothing) Me.New(BackdropType, Position, Rotation, Width, Height, Nothing)
End Sub End Sub
Public Sub New(ByVal BackdropType As String, ByVal Position As Vector3, ByVal Rotation As Vector3, ByVal Width As Integer, ByVal Height As Integer, ByVal BackdropTexture As Texture2D) Public Sub New(ByVal BackdropType As String, ByVal Position As Vector3, ByVal Rotation As Vector3, ByVal Width As Integer, ByVal Height As Integer, ByVal BackdropTexture As Texture2D, Optional ByVal AnimationSpeed As Integer = Nothing, Optional FrameCount As Integer = Nothing)
_shader = Content.Load(Of Effect)("Effects\BackdropShader") _shader = Content.Load(Of Effect)("Effects\BackdropShader")
_vertices.Add(New VertexPositionNormalTangentTexture(New Vector3(0, 0, 0), New Vector3(-1, 0, 0), New Vector3(0, 1, 0), New Vector2(0, 0))) _vertices.Add(New VertexPositionNormalTangentTexture(New Vector3(0, 0, 0), New Vector3(-1, 0, 0), New Vector3(0, 1, 0), New Vector2(0, 0)))
@ -114,6 +117,28 @@
Me._backdropType = BackdropTypes.Grass Me._backdropType = BackdropTypes.Grass
Case "texture" Case "texture"
Me._backdropType = BackdropTypes.Texture Me._backdropType = BackdropTypes.Texture
Case "animation"
Me._backdropType = BackdropTypes.Animation
_customTexture = BackdropTexture
Dim _animationspeed As Integer
Dim _frameCount As Integer
If AnimationSpeed = Nothing Then
_animationspeed = Water.WaterSpeed
Else
_animationspeed = AnimationSpeed
End If
If FrameCount = Nothing Then
_frameCount = 3
Else
_frameCount = FrameCount
End If
Dim AnimationSize As Size = New Size(CInt(_customTexture.Width / _frameCount), CInt(_customTexture.Height))
CustomAnimation = New Animation(_customTexture, 1, _frameCount, AnimationSize.Width, AnimationSize.Height, _animationspeed, 0, 0)
_backdropTexture = TextureManager.GetTexture(_customTexture, CustomAnimation.TextureRectangle)
End Select End Select
Me.Update() Me.Update()
@ -149,6 +174,19 @@
_backdropTexture = TextureManager.GetTexture("Backdrops\Grass", New Rectangle(x, 0, GrassSize.Width, GrassSize.Height)) _backdropTexture = TextureManager.GetTexture("Backdrops\Grass", New Rectangle(x, 0, GrassSize.Width, GrassSize.Height))
Me._setTexture = True Me._setTexture = True
End If End If
Case BackdropTypes.Animation
If Core.GameOptions.GraphicStyle = 1 Then
If Not CustomAnimation Is Nothing Then
CustomAnimation.Update(0.005)
_backdropTexture = TextureManager.GetTexture(_customTexture, CustomAnimation.TextureRectangle)
End If
Else
If Me._setTexture = False Then
_backdropTexture = TextureManager.GetTexture(_customTexture, CustomAnimation.TextureRectangle)
Me._setTexture = True
End If
End If
End Select End Select
End Sub End Sub

View File

@ -1205,6 +1205,9 @@
Dim TextureRectangle As Rectangle = CType(GetTag(Tags, "Texture"), Rectangle) Dim TextureRectangle As Rectangle = CType(GetTag(Tags, "Texture"), Rectangle)
Dim Texture As Texture2D = TextureManager.GetTexture(TexturePath, TextureRectangle) Dim Texture As Texture2D = TextureManager.GetTexture(TexturePath, TextureRectangle)
Dim AnimationSpeed As Integer = CInt(GetTag(Tags, "AnimationSpeed"))
Dim FrameCount As Integer = CInt(GetTag(Tags, "FrameCount"))
Dim trigger As String = "" Dim trigger As String = ""
Dim isTriggered As Boolean = True Dim isTriggered As Boolean = True
@ -1223,7 +1226,7 @@
End Select End Select
If isTriggered = True Then If isTriggered = True Then
Screen.Level.BackdropRenderer.AddBackdrop(New BackdropRenderer.Backdrop(BackdropType, Position, Rotation, Width, Height, Texture)) Screen.Level.BackdropRenderer.AddBackdrop(New BackdropRenderer.Backdrop(BackdropType, Position, Rotation, Width, Height, Texture, AnimationSpeed, FrameCount))
End If End If
End Sub End Sub