fix muh drawimage code plz
BlitzMax Forums/BlitzMax Beginners Area/fix muh drawimage code plz
| ||
| blitzmax meganoob here. Still write in blitzplus style. so the problem is : It works for about 2 seconds, then the screen freezes. Its like windows wants to pol it, can't, so decides the program has stalled. If the main loop variable i is reduced below 500, then the problem vanishes. thx
Graphics 1280,1024
a:TImage=LoadImage("image.jpg") ' put in your own image here
showslide(a,1.5,0.0003)
EndGraphics()
End
Function showslide(image:TImage,zoom:Float,zoom_acl:Float)
SetImageHandle (image,ImageWidth(image)/2,ImageHeight(image)/2)
For i=0 To 2000
' zoom=zoom+zoom_acl
' zoom_acl=zoom_acl*0.999
' SetScale zoom,zoom
Cls
DrawImage image,0,0
Flip
Next
End Function
|
| ||
| Does exactly what it should do here. My monitor runs at about 60 frames per second. So I see an unchanging image for a little over half a minute and then the program ends. |
| ||
| looks more likely its my windows config then, which was my original suspicion. Any windows experts here? How do I tell windows not to worry? Maybe some harmless command that pings windows. |
| ||
| fixed. included a createtimer, and waittimer in the loop, which gives windows time to ping the program. They don't tell you stuff like that in the tutorials. Have to learn 1st hand. |
| ||
| Hi, you can use Pollsystem() also. -Henri |
| ||
| put If KeyHit(KEY_ESCAPE) Then Return after the For statement. This will poll the event queue every loop and keep it from getting backed up. It will also give you the ability to exit the slide if you don't want to wait for the time to expire. |
| ||
| Is there a reason it's done like this? This is how I would do it (untested)
Graphics 1280,1024,0,60 '// Window mode @ 60 hertz/fps
'// Slide values
Global slideZoom:Float
Global slideAcl:Float
Global slideTime:Int
Global slideImg:TImage
'// Slides
Global slide1:TImage=LoadImage("image1.jpg")
Global slide2:TImage=LoadImage("image2.jpg")
'-------------------------------------------------
' Main loop
'-------------------------------------------------
While Not ApptTerminate()
Cls
If keyhit(KEY_1) Then PrepareSlide(slide1,2000) '// Zoom, this time 2 seconds and show slide1
If keyhit(KEY_2) Then PrepareSlide(slide2,5000) '// Zoom, this time 5 seconds and show slide2
UpdateSlide()
DrawText "main loop keeps running while zooming see time inc - "+Millisecs(),0,0
Flip
If keyhit(KEY_ESC) Then Exit
Wend
Print "Program was closed with Esc key or [x]"
'-------------------------------------------------
'Functions
'-------------------------------------------------
Function PrepareSlide(image:TImage,displaytime:Int)
slideTime = displaytime+Millisecs()
slideZoom = 0
slideAcl = 0
slideImg = image
SetImageHandle (slideImg,ImageWidth(slideImg)/2,ImageHeight(slideImg)/2)
End Function
Function UpdateSlide()
if slideTime < Millisecs() then Return 0 '// dont update or show slide if slidetime has expired
slideZoom=slideZoom+slideAcl
slideAcl=slideAcl*0.999
SetScale slideZoom,slideZoom
DrawImage image,0,0
SetScale 1.0,1.0 '// reset the scale
End Function
|
| ||
| Hi all, I fell asleep for 2 hrs just woke up, thanks for le epic help. Still looks like new blitzmax users can expect to be well supported from these forums after 11-12 years. @coffee Nice code, I notice you use 2 images. My plan is to try have different images transition by crossfade, like they do in screensavers. |