Results 1 to 5 of 5

Thread: XNA transparancy

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    XNA transparancy

    hello,

    im making a game with XNA, but when I draw diffrent layers it's not drawing them transparancy, why? (just run the game and you'll see)

    thanks in advanced,

    jimpie
    Attached Files Attached Files

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: XNA transparancy

    It would be alot easier if you just posted the code in your Draw-method. Alot of people are reluctant to download an entire zipped project.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    Re: XNA transparancy

    Quote Originally Posted by Atheist View Post
    It would be alot easier if you just posted the code in your Draw-method. Alot of people are reluctant to download an entire zipped project.
    Code:
    Imports System.Windows.Forms
    
    Public Class frmMain
    
        Public GDevice As GraphicsDevice
        Public OurContent As clsContent.GameContent
    
        Public test As Texture2D
    
        Public SBatch As SpriteBatch
    
        Public Function InitalizeGraphics(ByRef Surface As PictureBox) As Boolean
    
            Dim retValue As Boolean
    
            Try
                Dim PParam As New PresentationParameters
                PParam.PresentationInterval = PresentInterval.Immediate
                PParam.DeviceWindowHandle = Surface.Handle
                PParam.IsFullScreen = False
    
                Dim GAdapter As GraphicsAdapter = GraphicsAdapter.Adapters.Item(0)
                GDevice = New GraphicsDevice(GAdapter, GraphicsProfile.HiDef, PParam)
    
                OurContent = New clsContent.GameContent(GDevice)
                OurContent.Content.RootDirectory = "Content"
    
                SBatch = New SpriteBatch(GDevice)
    
                LoadGraphics()
    
                retValue = True
    
            Catch ex As Exception
    
                retValue = False
    
            End Try
    
            Return retValue
    
        End Function
    
        Public Sub LoadGraphics()
    
            test = OurContent.Content.Load(Of Texture2D)("2")
    
        End Sub
        Private Sub frmMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    
            '' 
            P(MyIndex).Map = 1
    
    
            For x = 0 To 50
                For y = 0 To 50
                    Tile(1, x, y, LAYER_GROUND).X = 0
                    Tile(1, x, y, LAYER_GROUND).Y = 0
                    Tile(1, 3, 7, LAYER_MASK).X = 7
                    Tile(1, 3, 7, LAYER_MASK).Y = 0
                Next
            Next
    
            For i = 0 To 50
                Map(i).X = 50
                Map(i).Y = 50
            Next
    
            '' 
    
            Me.Show()
    
            If InitalizeGraphics(PBGame) = False Then
                MessageBox.Show("Error while initializing graphics")
                End
            End If
    
            Call GameLoop()
    
        End Sub
    
        Private Sub GameLoop()
    
            Dim IsRunning As Boolean = True
    
            Do While IsRunning
    
                GDevice.Clear(Color.CornflowerBlue)
    
                'GROUND LAYER
                SBatch.Begin()
                For X = 0 To Map(P(MyIndex).Map).X
                    For Y = 0 To Map(P(MyIndex).Map).Y
                        SBatch.Draw(test, New Rectangle(X * 32, Y * 32, 32, 32), New Rectangle(Tile(P(MyIndex).Map, X, Y, LAYER_GROUND).X * 32, Tile(P(MyIndex).Map, X, Y, LAYER_GROUND).Y * 32, 32, 32), Color.White)
                    Next
                Next
                SBatch.End()
                'END GROUND
    
                'MASK LAYER
                SBatch.Begin()
                For X = 0 To Map(P(MyIndex).Map).X
                    For Y = 0 To Map(P(MyIndex).Map).Y
                        SBatch.Draw(test, New Rectangle(X * 32, Y * 32, 32, 32), New Rectangle(Tile(P(MyIndex).Map, X, Y, LAYER_MASK).X * 32, Tile(P(MyIndex).Map, X, Y, LAYER_MASK).Y * 32, 32, 32), Color.White)
                    Next
                Next
                SBatch.End()
                'END MASK
    
                GDevice.Present()
    
                Application.DoEvents()
            Loop
    
        End Sub
    
    End Class
    Code:
    Public Class clsContent
    
        Public Class GameContent
    
            Public Content As ContentManager
            Private ServiceHelper As New ServiceHelper
    
            Public Sub New(GraphicsDevice As GraphicsDevice)
                ServiceHelper.GraphicsDeviceService(GraphicsDevice)
                Me.Content = New Content.ContentManager(ServiceHelper)
                Me.Content.RootDirectory = "Content"
            End Sub
    
        End Class
    
        Public Class ServiceHelper
            Implements IServiceProvider
            Implements IGraphicsDeviceService
    
            Public Function GetService(ByVal serviceType As System.Type) As Object Implements System.IServiceProvider.GetService
                Return Me
            End Function
    
            Public Event DeviceCreated(ByVal sender As Object, ByVal e As System.EventArgs) Implements Microsoft.Xna.Framework.Graphics.IGraphicsDeviceService.DeviceCreated
            Public Event DeviceDisposing(ByVal sender As Object, ByVal e As System.EventArgs) Implements Microsoft.Xna.Framework.Graphics.IGraphicsDeviceService.DeviceDisposing
            Public Event DeviceReset(ByVal sender As Object, ByVal e As System.EventArgs) Implements Microsoft.Xna.Framework.Graphics.IGraphicsDeviceService.DeviceReset
            Public Event DeviceResetting(ByVal sender As Object, ByVal e As System.EventArgs) Implements Microsoft.Xna.Framework.Graphics.IGraphicsDeviceService.DeviceResetting
    
            Private _gd As GraphicsDevice
    
            Public Sub GraphicsDeviceService(ByVal gd As GraphicsDevice)
                _gd = gd
            End Sub
    
            Public ReadOnly Property GraphicsDevice() As Microsoft.Xna.Framework.Graphics.GraphicsDevice Implements Microsoft.Xna.Framework.Graphics.IGraphicsDeviceService.GraphicsDevice
                Get
                    Return _gd
                End Get
            End Property
        End Class
    
    End Class

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: XNA transparancy

    Take a look at the SpriteBatch.Begin overloads, specifically this one.
    The BlendState object determines how alpha blending is handled when rendering. Pass BlendState.AlphaBlend (or null, which defaults to AlphaBlend).

    I assume you have confirmed that the textures do contain an alpha channel?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    Re: XNA transparancy

    Quote Originally Posted by Atheist View Post
    Take a look at the SpriteBatch.Begin overloads, specifically this one.
    The BlendState object determines how alpha blending is handled when rendering. Pass BlendState.AlphaBlend (or null, which defaults to AlphaBlend).

    I assume you have confirmed that the textures do contain an alpha channel?
    Yes, they have a transparancy background.

    now I've changed this in my code:

    Code:
    SBatch.Begin
    to

    Code:
                SBatch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend)
    and it helped ^_^

    thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width