Canvas.paint

[quote=211491:@Alwyn Bester]O, ok, will have to try that some time.

I suppose that says a lot about backward compatibility when it comes to Microsoft products.[/quote]

Indeed. I launched it from the command prompt though. Not sure if it would work by double click.

i think nibbles was the program with the most wonderfully named sub routine - sparklepause

[quote=211488:@Alwyn Bester]Yes, remember it being ASCII.

So do you have a virtual machine set up with MS-DOS then?[/quote]

Nope… just opened the nibbles.bas file…

[quote=211272:@Alexander van der Linden]’ coordinates are stored as “x,y”
[/quote]
Instead of using a string , try using pair.

Something like:

Snakepositions(i).append (15:10)

[code]For i As Integer = 0 To Snakepositions.Ubound
If i = 0 Then
g.ForeColor=Preferences.SnakeHeadColor
Else
g.ForeColor= CalcGradient(0,i,SnakePositions.Ubound,&c00800000,&cC6FFC600)
End If
g.FillRect(Snakepositions(i).left,Snakepositions(i).right, SnakeUnit, SnakeUnit)

Next[/code]

[quote=211603:@jim mckay]Instead of using a string , try using pair.

Something like:

Snakepositions(i).append (15:10)

[code]For i As Integer = 0 To Snakepositions.Ubound
If i = 0 Then
g.ForeColor=Preferences.SnakeHeadColor
Else
g.ForeColor= CalcGradient(0,i,SnakePositions.Ubound,&c00800000,&cC6FFC600)
End If
g.FillRect(Snakepositions(i).left,Snakepositions(i).right, SnakeUnit, SnakeUnit)

Next[/code][/quote]
No, Xojo.Core.Point is the best option.

Hi Alexander,

Here are a few things to try to increase the speed:

  1. The timer in Xojo Windows does not seem to work well and is approximate, which gives graphics the ‘bumpy’ movement. Try and use ticks instead.
  2. Manual double-buffering of a picture in Windows works better.
  3. Lower the screen size. There will be a point where the screen is just too small. Try different sizes to view the ‘optimal’ smooth movement.

Just for fun, measure the actual frames per second that are being drawn. When the timer fires at 50 milliseconds, there should be 20 frames per second. It seems like your video is much slower than that. Here is a link which shows 15, 30, and 60 fps

Eugene
I Wish I Knew How To… Program the Canvas Control with Xojo Desktop

Thanks for taking the time to post a video Alexander. Unfortunately I don’t have Flash so I haven’t watched it but from others comments it sounds like a framerate issue.

This is a very good idea. You can paste this code at the top of your Paint event to get an approximate frames per second.

static frameCount As integer = 0 static startTime As double = Microseconds frameCount = frameCount + 1 dim thisTime As double = Microseconds dim deltaTime As double = thisTime - startTime if deltaTime > 1000000 then System.DebugLog("fps " + Format(frameCount/(deltaTime/1000000), "0.000")) frameCount = 0 startTime = thisTime '- (deltaTime-1000000) end

I’ve started my own snake game and 20fps is too fast for me. This is where each frame the snake moves 1 unit block. This javascript version (JavaScript Snake) uses a 75millisec timer, about 13.3fps, and moves 1 block at a time too. 15-10 fps is what I find playable.

If you’re doing some kind of animation between block steps it gets trickier. On Macs (what I’m using) the typical screen refresh rate is 60fps, so that’s the smoothest you can get. 30fps should be smooth too, that’s every other screen refresh, but syncing your drawing to the screens refresh is not really doable in Xojo, at least on Mac without plugins. Trying to draw every other screen refresh you’ll get mostly that with an occasional sequential drawing or skipping 2 refreshes instead of 1. Similar gaps if trying to draw at 60fps. Depending on your animation this may be noticeable. In my OpenGL apps I draw at 90fps to make sure the 60 drawings each second are different/animated.

Also, are you playing sounds? I’ve seen that cause draw stuttering but seems to be fixed in newer Xojos and maybe only a Mac issue.

This snake game could make a good XojoWars 2. Program your snake and either have solo competitions where the longest wins (plus shortest time in case of tie) or have 2, 3 or 4 dueling snakes in the pit that try to trap each other.

Hi,

Thanks all for your suggestions. In fact, the snake moves less bumpy than in the vid because the low framerate of the video (5fps) causes more bumpiness than really occurs.

The snake units are 16*16 pixel blocks so the snake moves by every timertick 16 pixels. I was thinking about drawing the first 16 pixelblock as lines in a loop. So depending on the direction I use a 0-16 for-next loop in which I use the .DrawLine method to ‘fill’ the first block with lines.

I will implement the pairs solution tomorrow. As a matter of fact in my first tryouts I used a 2 dimensional array, but it seems I abandoned that.

I do use sounds and it looks like there is a initial delay when the first sound gets played but that does not repeat as the sound is cached I think.