Page 1 of 1

Beginner : DrawImage

Posted: Wed Sep 20, 2006 11:34 pm
by surfer_ix
How comes this code doesn't work (my image doesn't appear) :

UsePNGImageDecoder()

If InitSprite()=0 Or InitKeyboard()=0
MessageRequester("Erreur","DirectX",0)
End
EndIf

ScreenWidth.w=1280
ScreenHeight.w=1024
If OpenScreen(ScreenWidth, ScreenHeight, 32, "Our")=0
MessageRequester("Erreur","Impossible "+Str(ScreenWidth)+","+Str(ScreenHeight))
End
EndIf
SetFrameRate(60)

ImgTile = CatchImage(#PB_Any, ?Background)
ImgBackground = CreateImage(#PB_Any, ScreenWidth, ScreenHeight*2)

StartDrawing(ImageOutput(ImgBackground))
DrawImage(ImgTile, 0, 0)
DrawImage(ImgTile, 0, ScreenHeight)
StopDrawing()


ClearScreen(RGB(50,50,50))
FlipBuffers()
ClearScreen(RGB(50,50,50))
FlipBuffers()
;-----------------------------------------------------------------
; boucle principale
Y = ScreenHeight
Repeat
StartDrawing(ScreenOutput())
DrawImage(ImgBackground, 0, 0)
StopDrawing()

FlipBuffers()

Y = Y - 8
If Y<0
Y = ScreenHeight
EndIf

ExamineKeyboard()

Until KeyboardPushed(#PB_Key_Escape)

CloseScreen()
End
;-----------------------------------------------------------------

DataSection
Background: IncludeBinary "Background.png"

Posted: Wed Sep 20, 2006 11:48 pm
by srod
The DrawImage() command requires an imageid rather than an image#.

So change the 3 DrawImage() commands and it should work.

E.g.

Code: Select all

DrawImage(ImageID(ImgTile), 0, 0) 
etc.

Posted: Thu Sep 21, 2006 3:00 am
by netmaestro
Also, you'll need to remove two of the three flipbuffers(), you only need one in your loop.

Wow !

Posted: Thu Sep 21, 2006 6:56 am
by surfer_ix
It has been said the community here is very good.
It's awesome ! Thank you !