Raster Bar in BlitzMax?

BlitzMax Forums/BlitzMax Beginners Area/Raster Bar in BlitzMax?

Hotshot2005(Posted 2005) [#1]
hiya all....

I try to create Raster Bar but it doesnt show on the screen....what I am doing wrong?

[CODE]
Graphics 640,480,0
' set randomizer
SeedRnd MilliSecs()

' bar generation And control variables
Global barHeight = 256
Global barHeightHalf = barHeight
Global barSpeed = 2
Global barPosition = 0

' Create Image For Raster Bars
'---------------------------------------------------
For i = 0 To 15
SetColor i * 16, 0, 0
DrawLine 0, i, 640, i
DrawLine 0, 31 - i, 640, 31 - i
Next

SetAlpha 0.75
Local barImage1=CreateImage(640,32,1,DYNAMICIMAGE|ALPHABLEND)

GrabImage barImage1,0,0


For i = 0 To 15
SetColor 0, i * 16, 0
DrawLine 0, i, 640, i
DrawLine 0, 31 - i, 640, 31 - i
Next
Local barImage2=CreateImage(640,32,1,DYNAMICIMAGE|ALPHABLEND)

GrabImage barImage2,0,0

For i = 0 To 15
SetColor 0, 0, i * 16
DrawLine 0, i, 640, i
DrawLine 0, 31 - i, 640, 31 - i
Next

Local barImage3=CreateImage(640,32,1,DYNAMICIMAGE|ALPHABLEND)
GrabImage barImage3,0,0

While Not KeyHit(1)
Cls
j = 0
angletemp = angle
For i = 0 To 7
Select j
Case 0
DrawImage barImage1, 0, 240 + Sin( angletemp ) * 80
Case 1
DrawImage barImage2, 0, 240 + Sin( angletemp ) * 80
Case 2
DrawImage barImage3, 0, 240 + Sin( angletemp ) * 80
End Select
j = j + 1
If j > 2 Then j = 0
angletemp = angletemp + 8
Next
angle = angle + 1
If angle > 359 Then angle = angle - 360

DrawImage barsImage, 0, barPosition
barPosition = barPosition - barSpeed
Flip
Cls
Wend
End
[/CODE]


SillyPutty(Posted 2005) [#2]
hey pretty cool :)

here is the fixed code :)

you were referencing barsImage, which did not exist so I changed it to barImage1

DrawImage barsImage, 0, barPosition 


change to

DrawImage barImage1, 0, barPosition 



here is the full code

SetGraphicsDriver GLMax2DDriver()
Graphics 640,480,0
' set randomizer 
SeedRnd MilliSecs() 

' bar generation And control variables 
Global barHeight = 256 
Global barHeightHalf = barHeight 
Global barSpeed = 2 
Global barPosition = 0 

' Create Image For Raster Bars 
'--------------------------------------------------- 
For i = 0 To 15 
SetColor i * 16, 0, 0 
DrawLine 0, i, 640, i 
DrawLine 0, 31 - i, 640, 31 - i 
Next 

SetAlpha 0.75
Local barImage1=CreateImage(640,32,1,DYNAMICIMAGE|ALPHABLEND)

GrabImage barImage1,0,0


For i = 0 To 15 
SetColor 0, i * 16, 0 
DrawLine 0, i, 640, i 
DrawLine 0, 31 - i, 640, 31 - i 
Next 
Local barImage2=CreateImage(640,32,1,DYNAMICIMAGE|ALPHABLEND)

GrabImage barImage2,0,0

For i = 0 To 15 
SetColor 0, 0, i * 16 
DrawLine 0, i, 640, i 
DrawLine 0, 31 - i, 640, 31 - i 
Next 

Local barImage3=CreateImage(640,32,1,DYNAMICIMAGE|ALPHABLEND)
GrabImage barImage3,0,0

While Not KeyHit(1) 
Cls 
j = 0 
angletemp = angle 
For i = 0 To 7 
Select j 
Case 0 
DrawImage barImage1, 0, 240 + Sin( angletemp ) * 80 
Case 1 
DrawImage barImage2, 0, 240 + Sin( angletemp ) * 80 
Case 2 
DrawImage barImage3, 0, 240 + Sin( angletemp ) * 80 
End Select 
j = j + 1 
If j > 2 Then j = 0 
angletemp = angletemp + 8 
Next 
angle = angle + 1 
If angle > 359 Then angle = angle - 360 

DrawImage barImage1, 0, barPosition 
barPosition = barPosition - barSpeed 
Flip
Cls 
Wend 
End




FlameDuck(Posted 2005) [#3]
If you had switched on the debugger (Program -> Build Options -> Debug Build) it would have told you that you're attempting to access a "Null" object (one that does not exsist yet) in this line:
DrawImage barsImage, 0, barPosition
just comment out the offending line (barsImage is not a valid image).