Usuario
Consulta animar Sprite

Pregunta
-
Hola! como estan? estoy practicando este tema del XNA y actualmente estoy haciendo un juego para la facu, lo unico que me esta faltando es darle un poco de animacion a las naves y no se como hacerlo, he probado algunas maneras de algunos libros que encontre pero no me sale bien. tambien me falta hacerle un menu de inicio pero bueno.... eso lo hare despues. alguien me podra ayudar y mas o menos mostrarme como puedo animar esta nave=????. espero me puedan ayudar! muchas gracias.
saludos
viernes, 22 de enero de 2016 13:39
Todas las respuestas
-
Bueno no pude subir la foto porque no se valido mi email todavia. la idea es un sprite de 1 columna por 6 dibujos hacia abajo, deberia cambiar cada sprite desde el primero hasta abajo simulando que la nave vuela. ni bien pueda subir la foto les muestro. saludos!viernes, 22 de enero de 2016 13:47
-
hola, mira yo me manejo con estas dos clases que me cree para hacer "juegos rapidos" yo programo en vb.net y xna fijate si porlomenos pordes sacar una idea:
Public Class cls_graphic
Public Class cls_animation
Public textureName As String
Public texture As Texture2D
Public position As Vector2
Public sourceRectangle As Microsoft.Xna.Framework.Rectangle
Public color As Microsoft.Xna.Framework.Color
Public rotation As Single
Public scale As Vector2
Public effects As Microsoft.Xna.Framework.Graphics.SpriteEffects
Public origin As Vector2
Public order As Single
Public Sub New()
End Sub
Public Sub New(ByVal prm_textureName As String)
textureName = prm_textureName
texture = Nothing
position = Vector2.Zero
sourceRectangle = Rectangle.Empty
color = Microsoft.Xna.Framework.Color.White
rotation = 0
scale = New Vector2(1, 1)
effects = SpriteEffects.None
origin = Vector2.Zero
End Sub
Public Sub New(ByVal prm_texture As Texture2D)
textureName = ""
texture = prm_texture
position = Vector2.Zero
sourceRectangle = Rectangle.Empty
color = Microsoft.Xna.Framework.Color.White
rotation = 0
scale = New Vector2(1, 1)
effects = SpriteEffects.None
origin = Vector2.Zero
End Sub
Public Overridable Sub Load(ByRef prm_content As Microsoft.Xna.Framework.Content.ContentManager)
texture = prm_content.Load(Of Texture2D)(textureName)
sourceRectangle.Width = texture.Width
sourceRectangle.Height = texture.Height
End Sub
Public Overridable Sub UnloadContent()
End Sub
Public Overridable Sub Update()
End Sub
Public Overridable Sub Draw(ByRef prm_batch As Microsoft.Xna.Framework.Graphics.SpriteBatch)
'prm_batch.Draw(texture, position, sourceRectangle, color, rotation, origin, scale, effects, order)
prm_batch.Draw(texture, position, sourceRectangle, color, rotation, origin, scale, effects, order)
End Sub
Public Sub Initialize()
End Sub
End Class
Inherits cls_graphic
Public frameCount As Integer
Public timePerFrame As Single
Public frame As Integer
Public animationType As enu_animationType
Public state As Boolean
Public frameWidth As Single
Private val_totalElapsed As Single
Private val_frameSum As Integer
Private val_lastTick As Single
Public Enum enu_animationType As Integer
cyclic = 0
repeat = 1
random = 2
once = 3
manual = 4
End Enum
Public Sub New(ByVal prm_textureName As String)
MyBase.New(prm_textureName)
frameCount = 1
timePerFrame = 0.05
frame = 0
val_totalElapsed = 0
animationType = enu_animationType.cyclic
val_frameSum = 1
state = True
End Sub
Public Sub New(ByVal prm_texture As Texture2D)
MyBase.New(prm_texture)
texture = prm_texture
position = Vector2.Zero
sourceRectangle = Rectangle.Empty
color = Microsoft.Xna.Framework.Color.White
rotation = 0
scale = New Vector2(1, 1)
effects = SpriteEffects.None
origin = Vector2.Zero
frameCount = 1
timePerFrame = 0.05
frame = 0
val_totalElapsed = 0
animationType = enu_animationType.cyclic
val_frameSum = 1
state = True
End Sub
Public Sub New(ByVal prm_teturename As String, ByVal prm_framecount As Integer, ByVal prm_timePerFrame As Single, Optional ByVal prm_animationType As enu_animationType = enu_animationType.cyclic)
MyBase.New(prm_teturename)
frameCount = prm_framecount
timePerFrame = prm_timePerFrame
animationType = prm_animationType
val_frameSum = 1
state = True
val_lastTick = System.Environment.TickCount
End Sub
Public Sub New(ByVal prm_teturename As String, ByVal prm_framecount As Integer, ByVal prm_timePerFrame As Single, ByVal prm_sourceTop As Integer, prm_soucerHeight As Integer, Optional ByVal prm_animationType As enu_animationType = enu_animationType.cyclic)
Me.New(prm_teturename, prm_framecount, prm_timePerFrame, prm_animationType)
sourceRectangle = New Rectangle(0, prm_sourceTop, 0, prm_soucerHeight)
End Sub
Public Overrides Sub Load(ByRef prm_content As Microsoft.Xna.Framework.Content.ContentManager)
MyBase.Load(prm_content)
frameWidth = CInt(sourceRectangle.Width / frameCount)
sourceRectangle.Width = CInt(frameWidth)
End Sub
Public Overrides Sub Update()
If state Then
sourceRectangle.X = CInt(frameWidth * frame)
val_totalElapsed += System.Environment.TickCount - val_lastTick 'CSng(prm_gameTime.ElapsedGameTime.TotalSeconds)
If val_totalElapsed > timePerFrame Then
Select Case animationType
Case enu_animationType.cyclic
frame += val_frameSum
frame = frame Mod frameCount
Case enu_animationType.repeat
frame += val_frameSum
If frame = frameCount - 1 Or frame = 0 Then
val_frameSum = val_frameSum * (-1)
ElseIf frameCount = 1 Then
frame = 0
End If
Case enu_animationType.random
frame += val_frameSum
Dim rnd As New Random
frame = rnd.Next(0, frameCount)
Case enu_animationType.once
frame += val_frameSum
If frame >= frameCount Then
animationStop()
End If
End Select
val_totalElapsed = 0
End If
End If
val_lastTick = System.Environment.TickCount
End Sub
Public Overrides Sub Draw(ByRef prm_batch As SpriteBatch)
MyBase.Draw(prm_batch)
End Sub
Public Overridable Sub animationPlay(Optional prm_frame As Integer = -1)
If prm_frame <> -1 Then frame = prm_frame
state = True
End Sub
Public Overridable Sub animationStop(Optional prm_frame As Integer = -1)
If prm_frame <> -1 Then frame = prm_frame
state = False
End Sub
End Class
lunes, 22 de febrero de 2016 5:14