Beginner : DrawImage

Just starting out? Need help? Post your questions and find answers here.
surfer_ix
New User
New User
Posts: 5
Joined: Wed Sep 20, 2006 9:54 am
Location: France

Beginner : DrawImage

Post 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"
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Also, you'll need to remove two of the three flipbuffers(), you only need one in your loop.
BERESHEIT
surfer_ix
New User
New User
Posts: 5
Joined: Wed Sep 20, 2006 9:54 am
Location: France

Wow !

Post by surfer_ix »

It has been said the community here is very good.
It's awesome ! Thank you !
Post Reply