Easy jump example

Share your advanced PureBasic knowledge/code with the community.
ChebbyShabby
Enthusiast
Enthusiast
Posts: 121
Joined: Mon Jun 26, 2006 10:47 am

Easy jump example

Post by ChebbyShabby »

if you ever wanted to make your sprite jump with simulated physics, i've whipped up a quick example here: http://www.MailFreeOnline.com/uploader/7004BA98.zip

and for the slightly more advanced user (involves platforms) -- VERY buggy, quickly done:
http://www.MailFreeOnline.com/uploader/02ABDBBE.zip

(push space bar to jump)
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Code: Select all

If OpenScreen(640, 480, 32, "Eraser") 
  LoadSprite(0, "Square.bmp") ;Change this to the location of your sprite 

  SetFrameRate(60) <------------- insert this line here

  Repeat 
    FlipBuffers() 
Might I suggest a small change to your code.

See the line above. :)

Other than that, very good. Thanks for sharing.
ChebbyShabby
Enthusiast
Enthusiast
Posts: 121
Joined: Mon Jun 26, 2006 10:47 am

Post by ChebbyShabby »

ah yes... the frame rate. my bad
User avatar
Michael Vogel
Addict
Addict
Posts: 2811
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

the link is dead :evil:
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

I'm curious, why do you suggest SetFrameRate(), Derek?
Good programmers don't comment their code. It was hard to write, should be hard to read.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Because the example was moving so fast that it needed to be slowed down. Could of put a delay(1) in the loop or flipbuffers(1) I suppose.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

on most systems you can leave the SetFrameRate() out,
but on some systems it will move too fast without it.

its a rough solution, but it works.

but since FlipBuffers() will use 100%CPU while waiting for the next frame,
the better solution would be to put the whole movement under time-control.

best solution would be seperate threads.
one is timer-controlled and does the movement of the objects,
a second does the display and just runs on maximum framerate, or with a little delay...
oh... and have a nice day.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

It was just a quick fix without having to go into timing issues and such, the example was only a quick little program and didn't warrant any major overhauls. Just something to slow it down a bit.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Double post - sorry. :oops:
Last edited by Derek on Fri Dec 29, 2006 8:31 pm, edited 1 time in total.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Thanks, Derek
Good programmers don't comment their code. It was hard to write, should be hard to read.
Post Reply