Why is my program jerky?

BlitzMax Forums/BlitzMax Beginners Area/Why is my program jerky?

Rico(Posted 2008) [#1]
I have written a simple program - just to get something happening in BlitzMax. I was using the old Blitz basic, and I can't work out how to get more than one command on ths same line in BMax. I used to do x=0:y=0:xv=1:yv=1 for example, but now the ':' is not accepted. Also my program is very jerky, so I am sure I have not done something I should have. I would really appreciate some help.

Would someone please recommend a 2D image creator program to make sprites and levels (like the old Dpaint on the Amiga) and also a SIMPLE music creator program (bit like NoiseTracker on the Amiga). I used to have an Amiga, just in case you were in any doubt :)

Thank you - Rico (my program is listed below)

P.S. I use to do lots of If x<0 Then x=10:xv=10:flag=True (all on one line) but its really wasting space doing an if, endif structure. How can I do this in BlitzMax?

--------------------------------------------------------------
' bounces a white box around the screen
Graphics 800,600,16

Cls

DrawRect 0,0,32,32

Local image=CreateImage(32,32)
GrabImage image,0,0
SetImageHandle image,0,0

xpos=0
ypos=0
xv=1
yv=1
Cls
While Not KeyDown(KEY_ESCAPE)

	'Update  Position
	xpos=xpos+xv
	ypos=ypos+yv
	If xpos>768
	   xpos=768
	   xv=-xv
	EndIf
	If xpos<0 
		 xpos=0
		xv=-xv
	EndIf
	If ypos>568
	    ypos=568
	    yv=-yv
	EndIf
	If ypos<0
	    ypos=0
	    yv=-yv
	EndIf
	
	
	DrawImage image,xpos,ypos

	Flip
	Cls
Wend


Moderator Note: Please use [code ] / [codebox ] tags when posting code on the forums. What are the forum codes?


GfK(Posted 2008) [#2]
Use ; instead of :.

For graphics, Try Gimp (free) or Paintshop (not free).

For audio, FL Studio (not free).


Who was John Galt?(Posted 2008) [#3]
Rico - do yourself a favour and indent it. It makes it so much easier to maintain once it gets bigger.

Your code looks alright. Just check the graphics command to make sure you're not setting it to 16 frames per second. I can't remember the format.


Rico(Posted 2008) [#4]
Do you need to disable anything to get smooth programs - e.g Virus checker etc. Or does Blitz automatically take over the system?

Rico


Perturbatio(Posted 2008) [#5]
you might want to investigate delta timing


Who was John Galt?(Posted 2008) [#6]
Rico-

I do see a jerk every second or so. There is nothing wrong with your program as such.I have seen this exact same thing in both my own blitz games and ones written by others. Never used to get it on my CRT monitor and it seems to be something to do with LCDs. I use an LCD tv for my monitor. I never found a satisfactory solution and I would wager that delta timing wouldn't fix the problem.


TomToad(Posted 2008) [#7]
What version of BlitzMAX are you using? When I first got blitzMax, I noticed a bit of jerkiness for the first few seconds of program execution. It disappeared with an upgrade.
The latest stable version is 1.28


Who was John Galt?(Posted 2008) [#8]
Mine's the latest and it's not just in the first few seconds.


MGE(Posted 2008) [#9]
Rico - Your program is behaving normal for a loop that does no delta timing or frame averaging. Blitzmax behaves just like any other development language when it comes to jitters, etc, etc.

PC's are different nowdays and the mutlitasking they do is more "tasking" on the os more than ever. Years ago it was easy to get games running smoothly because end users didn't have a zillion im's, virus checkers, etc, etc, running in the background, and the os itself wasn't as demanding.

Even on today's best gaming pc, you will see jitters every now and then during the game. In 3d games it's less aparrent because your eyes are focused on the "scene" instead of a small 2d character.

What you can do....

a) Nothing, just code your game. Seriously, it's ok for slight jitters once in a while. 99% of the casual market is used to this now days.

b) Research delta timing.
c) Research frame based timing with tweening.
d) Research vsync, refresh rate, and how that affects your game frame rate.

Again, if you're just doing this for fun, stick with option A. But if you want to seriously explore PC game design then you should spend a few weeks researching B-D. This is a quirk among all pc games and is not language dependent. Good luck with your coding!


Grey Alien(Posted 2008) [#10]
I concur with MGE.


Rico(Posted 2008) [#11]
I've just changed 'Flip' to 'Flip 1' and it works very smoothly. Needed to wait for the vertical blank, I think it was flipping buffers too quickly before.
I've got the latest version of Max (I just bought it!)

Thank you for everyones's help. I'll definitely look into delta timing. The LCD does definitely cause blurring on faster moving objects. I think they are improving, but are not as good as CRTs yet. If you want to play 2d games then CRTs offer the best quality

Thanks again - Buzz :) (feeling happy now!)


Htbaa(Posted 2008) [#12]
Fast moving objects don't do too well on TFT with a slow(er) refresh rate. In my current 2D shoot 'm up everything goes very smoothly on my main computer, but a certain form of blur is in effect when playing on my 3 year old laptop.

It's not that big of a deal though, but you do see the difference.


iamdaman13(Posted 2008) [#13]
setting backbuffer as active buffer made it smooth for me, otherwise it's jerky


tonyg(Posted 2008) [#14]
Setting backbuffer as active buffer made it smooth for me, otherwise it's jerky
How do you *NOT* set the backbuffer as the active buffer in Bmax?


MGE(Posted 2008) [#15]
"setting backbuffer as active buffer made it smooth for me, otherwise it's jerky"

Huh?


Perturbatio(Posted 2008) [#16]
He's a B3D user, he just wandered down the wrong street...


iamdaman13(Posted 2008) [#17]
Sorry. I did try the code in a bmax demo as well, but it was jerky compared to trying it in b3d. I thought bmax was supposed to handle 2d better than b3d.


Rico(Posted 2008) [#18]
Phew - That was a long time ago I posted that! My games going very nicely now - its smooth and everything! - and I can use forum codes now! :)
iamdaman13 - did you try doing 'flip 1' instead of 'flip'? Thats what fixed it for me. It makes the flip happen on the next vertical blank. Other than that, virus checkers and other processes can sometimes slow things down, so make sure nothing else is running in the background.


iamdaman13(Posted 2008) [#19]
Thanks! Flip 1 worked for me in the bmax demo. I'm still trying to decide if I should get bmax for 2d games, as I've been making them with b3d so far.