flashing screen

BlitzMax Forums/BlitzMax Beginners Area/flashing screen

Hi there,

I'm very new to BlitzMax and I am learning how to code in it from things on the internet, but it is very tough.

When I compile and test this, the screen flashes.


-


' -------------------- '
' Meltdown Source Code '
' Eric Vaughn 2006 '
' -------------------- '

' Initialize Window

Graphics 400, 300, 16

HideMouse

' Load Images

player:TImage = LoadImage("images/player.bmp")

' Draw Images

Cls

DrawImage(player, 10, 10)

' Main Loop

While Not KeyHit(KEY_ESCAPE)

' Draw Screen

Flip

Wend

ShowMouse


-


How do I stop the flashing?

Thanks.

Move the While Not KeyHit(KEY_ESCAPE) back so that it comes after the player:TImage=LoadImage and before the Cls.

You're clearing the screen and drawing an image once, and from that point on you're just flipping the buffers for no good reason. You have to draw what you want seen every frame.

Ok it works now, thanks!

Here's some help, I fixed your code and made some changes so many objects can be handled instead of just one.

Copy and Paste for BMAX (Just change the [,] backets for B3D )
' -------------------- '
' Meltdown Source Code '
' Eric Vaughn 2006 '
' -------------------- '

' Maximum number of Sprites (Moveable objects)
Const maxSprite=10

Global Sprite[maxSprite+1],Sprite_alive[maxSprite+1]
Global Sprite_x[maxSprite+1],Sprite_y[maxSprite+1]

' Initialize Window
Graphics 400, 300, 16

HideMouse


' Load Images

Sprite[1] = LoadImage("images/player.bmp")
Sprite_x[1]=50
Sprite_y[1]=74
Sprite_alive[1]=True


' Main Loop

While Not KeyHit(KEY_ESCAPE)
Cls

' Code to draw Backgroud goes here....

' Code to move Sprites goes here...
If KeyDown(KEY_J) And Sprite_x[1]>0 Then Sprite_x[1]=Sprite_x[1]-1
If KeyDown(KEY_L) And Sprite_x[1]<400 Then Sprite_x[1]=Sprite_x[1]+1
If KeyDown(KEY_I) And Sprite_x[1]>0 Then Sprite_y[1]=Sprite_y[1]-1
If KeyDown(KEY_K) And Sprite_x[1]<300 Then Sprite_y[1]=Sprite_y[1]+1


' Draw Images
For i = 1 To maxSprite
If Sprite_alive[i]=True
DrawImage(Sprite[i], Sprite_x[i], Sprite_y[i])
EndIf
Next

Flip
Wend


In this example there are four images on the screen using data, image 1 is controlled by I,J,K,L

No Doubt in your game you will want more than one image

' -------------------- '
' Meltdown Source Code '
' Eric Vaughn 2006 '
' -------------------- '

' Maximum number of Sprites (Moveable objects)
Const maxSprite=10

Global Sprite[maxSprite+1],Sprite_alive[maxSprite+1]
Global Sprite_x[maxSprite+1],Sprite_y[maxSprite+1]


' Initialize Window

Graphics 400, 300, 16

HideMouse


' Load Images
i=0
Repeat
i=i+1
ReadData file$,Sprite_x[i],Sprite_y[i],Sprite_Alive[i]
Sprite[i] = LoadImage(file$) 
Until file$="end"

DefData "images/player.bmp",50,74,True
DefData "images/player.bmp",4,4,True
DefData "images/player.bmp",150,174,True
DefData "images/player.bmp",250,274,True
DefData "end",0,0,0



' Main Loop

While Not KeyHit(KEY_ESCAPE)

Cls

' Code to draw Backgroud goes here....

' Code to move Sprites goes here...
If KeyDown(KEY_J) And Sprite_x[1]>0 Then Sprite_x[1]=Sprite_x[1]-1
If KeyDown(KEY_L) And Sprite_x[1]<400 Then Sprite_x[1]=Sprite_x[1]+1
If KeyDown(KEY_I) And Sprite_x[1]>0 Then Sprite_y[1]=Sprite_y[1]-1
If KeyDown(KEY_K) And Sprite_x[1]<300 Then Sprite_y[1]=Sprite_y[1]+1




' Draw Images

For i = 1 To maxSprite
If Sprite_alive[i]=True
DrawImage(Sprite[i], Sprite_x[i], Sprite_y[i])
EndIf
Next

Flip
Wend


This one has moving Images and One controlled by the keyboard... The basics of any game.

I have tested this in BMAX, it should only need the brackets changed with the arrays to make it work in B3D.

' -------------------- '
' Meltdown Source Code '
' Eric Vaughn 2006 '
' -------------------- '

' Maximum number of Sprites (Moveable objects)
Const maxSprite=10

Global Sprite[maxSprite+1],Sprite_alive[maxSprite+1]
Global Sprite_x[maxSprite+1],Sprite_y[maxSprite+1]
Global Sprite_x_d[maxSprite+1],Sprite_y_d[maxSprite+1]

' Initialize Window

Graphics 400, 300, 16
HideMouse

' Load Images
i=0
Repeat
i=i+1
ReadData file$,Sprite_x[i],Sprite_y[i],Sprite_x_d[i],Sprite_y_d[i],Sprite_Alive[i]
Sprite[i] = LoadImage(file$)
Until file$="end"

DefData "images/player.bmp",50,74,0,0,True
DefData "images/player.bmp",4,4,1,0,True
DefData "images/player.bmp",150,174,-1,1,True
DefData "images/player.bmp",250,274,0,1,True
DefData "end",0,0,0,0,0



' Main Loop

While Not KeyHit(KEY_ESCAPE)

Cls

' Code to draw Backgroud goes here....

' Code to move Sprites goes here...
If KeyDown(KEY_J) And Sprite_x[1]>0 Then Sprite_x[1]=Sprite_x[1]-1
If KeyDown(KEY_L) And Sprite_x[1]<400 Then Sprite_x[1]=Sprite_x[1]+1
If KeyDown(KEY_I) And Sprite_x[1]>0 Then Sprite_y[1]=Sprite_y[1]-1
If KeyDown(KEY_K) And Sprite_x[1]<300 Then Sprite_y[1]=Sprite_y[1]+1


' Draw Images

For i = 1 To maxSprite
If Sprite_alive[i]=True

' Exclude Player 1 from moving here if you want
If i>1
Sprite_x[i]=Sprite_x[i]+Sprite_x_d[i]
Sprite_y[i]=Sprite_y[i]+Sprite_y_d[i]

If Sprite_x[i]<0
Sprite_x[i]=0
Sprite_x_d[i]=0.0-Sprite_x_d[i]
EndIf

If Sprite_y[i]<0
Sprite_y[i]=0
Sprite_y_d[i]=0.0-Sprite_y_d[i]
EndIf

If Sprite_x[i]>400
Sprite_x[i]=400
Sprite_x_d[i]=0.0-Sprite_x_d[i]
EndIf

If Sprite_y[i]>300
Sprite_y[i]=300
Sprite_y_d[i]=0.0-Sprite_y_d[i]
EndIf

EndIf

DrawImage(Sprite[i], Sprite_x[i], Sprite_y[i])
EndIf
Next

Flip
Wend