I have started making my game after running through some XNA tutorials but have run into a problem.
Firstly Here is my class for creating blocks:
Next this is my code which i am using to set up new blocks in a 2dimensional array:Code:Imports Microsoft.Xna.Framework Imports Microsoft.Xna.Framework.Graphics Public Class Block 'Define Block Objects' Public BlockSB As SpriteBatch = New SpriteBatch(Device) Public BlockTex As Texture2D = Nothing Public BlockRect As Rectangle = Nothing Public BlockTexCreationParams As TextureCreationParameters = TextureCreationParameters.Default 'Define Block Variables' Public CanShoot As Boolean = True Public BlockSize As New Size(25, 25) Public BlockColor As String Public BlockPosition As Point Public Sub CreateBlock() BlockTex = Texture2D.FromFile(Device, "../../Resources/" & BlockColor & "Block.png", BlockTexCreationParams) BlockRect.Height = BlockSize.Height BlockRect.Width = BlockSize.Width BlockRect.X = BlockPosition.X BlockRect.Y = BlockPosition.Y End Sub Public Sub New(ByVal InitialColor As String, ByVal InitialPosition As Point) BlockColor = InitialColor BlockPosition = InitialPosition End Sub End Class
Then this is my code for rendering graphics:Code:Private Sub SetUpInitialBlocks() Dim Color As String = "Black" 'First Row' For i As Integer = 0 To 9 Blocks(i, 0) = New Block(Color, StartLoc) Blocks(i, 0).CreateBlock() If Color = "Black" Then Color = "Red" Else Color = "Black" End If Next End Sub
When it gets to rendering the blocks in the render sub i am getting the following error message referring to the block i am trying to draw:Code:Private Sub Render() If Device Is Nothing Then Return 'Clear The Back Buffer To Black' Device.Clear(ClearOptions.Target, Microsoft.Xna.Framework.Graphics.Color.Black, 1.0F, 0) 'Draw All Non Block Textures' NonBlockSB.Begin(SpriteBlendMode.AlphaBlend) NonBlockSB.Draw(FrameTex, FrameRect, Color.White) NonBlockSB.Draw(GameBoardTex, GameBoardRect, Color.White) NonBlockSB.End() 'Draw Starting Blocks' For X As Integer = 0 To 9 For Y As Integer = 0 To 14 Blocks(X, Y).BlockSB.Begin(SpriteBlendMode.AlphaBlend) Blocks(X, Y).BlockSB.Draw(Blocks(X, Y).BlockTex, Blocks(X, Y).BlockRect, Color.White) Blocks(X, Y).BlockSB.End() Next Y Next X Device.Present() End Sub
Im not sure why its throwing this message as i have the SetUpInitialBlocks Sub which is used to create the new blocks.Object reference not set to an instance of an object.
I may be doing something completely wrong here as i have only just started with the XNA as advised above so if anyone has any suggestions i would appreciate it greatly.
Thanks in advance![]()


Reply With Quote
