Page 1 of 1

Whats wrong with this code?

Posted: Mon Dec 05, 2005 10:40 pm
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?

Posted: Mon Dec 05, 2005 10:52 pm
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..

Posted: Tue Dec 06, 2005 7:59 am
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...

Posted: Tue Dec 06, 2005 6:53 pm
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?

Posted: Thu Dec 08, 2005 11:55 pm
by netmaestro
You have too many FlipBuffers() in there, you can only have one per loop iteration or it will flash badly.

Posted: Fri Dec 09, 2005 5:55 pm
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.

Posted: Fri Dec 09, 2005 7:35 pm
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

Posted: Mon Dec 12, 2005 8:07 am
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.