Whats wrong with this code?

Advanced game related topics
Hydrate
Enthusiast
Enthusiast
Posts: 436
Joined: Mon May 16, 2005 9:37 pm
Contact:

Whats wrong with this code?

Post by Hydrate »

Code: Select all

Procedure StartScreen(Delay.l)
Delay(Delay)
If UsePNGImageDecoder()
LoadSprite(#SpriteHouseCollision,"Data\Backgrounds\Koriki Forest\House - Link\LinkhouseCollision.png")
LoadSprite(#SpriteHouse0,"Data\Backgrounds\Koriki Forest\House - Link\LinkhouseBottom.png")
LoadSprite(#SpriteHouse1,"Data\Backgrounds\Koriki Forest\House - Link\LinkhouseTop.png")
EndIf

ClearScreen(0,0,0)
Repeat
FlipBuffers()
TransparentSpriteColor(#SpriteHouseCollision,255,0,255)
TransparentSpriteColor(#SpriteHouse1,255,0,255)
DisplaySprite(#SpriteHouseCollision,0,0)
DisplaySprite(#SpriteHouse0,0,0)
DisplaySprite(#SpriteHouse1,0,0)
Delay(Delay)
Until ExitRoom=1
FlipBuffers()
ClearScreen(0,0,0)
 
EndProcedure

Procedure StartAdvert(Delay.l)
Delay(Delay)
If UsePNGImageDecoder()
LoadSprite(#SpriteFendez,"Data\Sprites\Startup\FendezLogo.png")
LoadSprite(#SpriteLogo,"Data\Sprites\Startup\Logo2.png")
LoadSprite(#SpriteLogoBG,"Data\Sprites\Startup\TitleScreenBG.png")
LoadSprite(#SpritePressEnter,"Data\Sprites\Startup\PressEnter.png")
EndIf

DisplaySprite(#SpriteFendez,0,0)
PlayMovie(#SoundStart,WindowID())
FlipBuffers()
Delay(1200)

FreeMovie(#SoundStart)

Repeat
FlipBuffers()
TransparentSpriteColor(#SpriteLogo,255,0,255)
TransparentSpriteColor(#SpritePressEnter,255,0,255)
DisplaySprite(#SpriteLogoBG,0,0)
DisplayTransparentSprite(#SpriteLogo,75,20)
If Flash=#True
DisplayTransparentSprite(#SpritePressEnter,75,20)
Flash=#False
Else
Flash=#True
EndIf

Delay(1000)
If MovieStatus()=0
PlayMovie(#SoundIntroduction,WindowID())
EndIf
Until GameSarted=1
StopMovie()
FlipBuffers()
ClearScreen(0,0,0)
EndProcedure
It just goes to a black screen when i try and start the game, why?
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

You might wanna do a Flipbuffers() after you've drawn the sprites as they are drawn on the currently NOT seen screen buffer..
Hydrate
Enthusiast
Enthusiast
Posts: 436
Joined: Mon May 16, 2005 9:37 pm
Contact:

Post by Hydrate »

Pupil wrote:You might wanna do a Flipbuffers() after you've drawn the sprites as they are drawn on the currently NOT seen screen buffer..
Did that, but it still just shows a black screen...
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Are you sure this is the part where the error is? I don't see any opening of screens etc. To be honest i don't quite understand how your code is supposed to work, are you running these procedures in a thread or something?

Just covering the obvious, have you checked that the sprites are loaded properly?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You have too many FlipBuffers() in there, you can only have one per loop iteration or it will flash badly.
Last edited by netmaestro on Wed Feb 22, 2006 6:22 am, edited 2 times in total.
BERESHEIT
Hydrate
Enthusiast
Enthusiast
Posts: 436
Joined: Mon May 16, 2005 9:37 pm
Contact:

Post by Hydrate »

Are you sure this is the part where the error is? I don't see any opening of screens etc. To be honest i don't quite understand how your code is supposed to work, are you running these procedures in a thread or something?

Just covering the obvious, have you checked that the sprites are loaded properly?
These procedures are being loaded in a thread.

Code: Select all

Case #MenuOpen
OpenAccountWindow()
If Password$=AccountPassword$
FreeMovie(#SoundIntroduction)
KillThread(ThreadIntro)
GameSarted=1
ThreadLinkHouse=CreateThread(@StartScreen(),200)
EndIf
The above is the code for loading the second part which isnt loading, i have checked the sprites, and they are loading fine.
Your code has two flipbuffers() in the loop. There should only be one. You are drawing - flipping - clearing - flipping. You should clear and flip, then start your repeat..until loop, in which you will clear - draw - flip - wait.
Thats how it was origionally, i changed it because it just was not displaying the images, i thought i must have been doing that wrong.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Game code skeleton:

Use only 1 FlipBuffers()!!!

Code: Select all

Repeat
  
  If IsScreenActive()
    ClearScreen(0,0,0)
    
    DoGraphics()
    DoInput()
    DoAI()
    DoMovie()

  Else
    Delay(50) ; Alt+Tab, Let's snooze
  EndIf
  
  FlipBuffers()
ForEver
Hydrate
Enthusiast
Enthusiast
Posts: 436
Joined: Mon May 16, 2005 9:37 pm
Contact:

Post by Hydrate »

Num3 wrote:Game code skeleton:

Use only 1 FlipBuffers()!!!

Code: Select all

Repeat
  
  If IsScreenActive()
    ClearScreen(0,0,0)
    
    DoGraphics()
    DoInput()
    DoAI()
    DoMovie()

  Else
    Delay(50) ; Alt+Tab, Let's snooze
  EndIf
  
  FlipBuffers()
ForEver
Thank you very very much, it works well now.
Post Reply