Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Frames per seconds, y doesn't it work?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
AsianSensation




PostPosted: Sun Apr 20, 2003 5:03 pm   Post subject: Frames per seconds, y doesn't it work?

I just changed me and SilverSprite's worms game to a real time linear battle game. However, the amount of flashing i am getting, even after using View.Update is unbelieveable. So I looked at the trusty Turing Help, they included a fun game (it comes with turing 4.0.3 i think), in there, the game is not slow at all, and they used "frames per second" to fix the problem. I try to use the same thing(literally, i copy and pasted), but i just can't get it to work. Could someone please help me? Here is the code and pictures that i am using:
code:
var forest := Pic.FileNew ("forest.jpg")
var grass := Pic.FileNew ("grass layer.bmp")
var chars : array char of boolean
var startTime : int
var lastFrameTime : int := 0
var frameTime : int := 0
var lastFrameRate : int := 0
var font1 := Font.New ("Times New Roman:16")
const MAX_FRAME_RATE : int := 30
const MIN_MILLISECS_BETWEEN_FRAMES : int := 1000 div MAX_FRAME_RATE
var backgroundPictureWidth1, backgroundPictureWidth2 : int
var backgroundPictureX1, backgroundPictureX2 : int

procedure DrawScreen
    var frameRate : int

    Pic.Draw (forest, -backgroundPictureX1, 0, picCopy)

    frameRate := 1000 div (Time.Elapsed - frameTime)
    if abs (lastFrameRate - frameRate) > 1 then
        lastFrameRate := frameRate
    end if
    Font.Draw (intstr (lastFrameRate), 0, 370, font1, white)
    frameTime := Time.Elapsed

    Pic.Draw (grass, -backgroundPictureX2, 0, picMerge)

    View.Update
end DrawScreen

backgroundPictureWidth1 := Pic.Width (forest)
backgroundPictureWidth2 := Pic.Width (grass)
backgroundPictureX1 := (backgroundPictureWidth1 - (maxx + 1)) div 2
backgroundPictureX2 := (backgroundPictureWidth2 - (maxx + 1)) div 2

startTime := Time.Elapsed

loop
    Input.KeyDown (chars)
    if chars (KEY_LEFT_ARROW) then
        backgroundPictureX1 += 5
        backgroundPictureX2 += 10
    end if
    if chars (KEY_RIGHT_ARROW) then
        backgroundPictureX1 -= 5
        backgroundPictureX2 -= 10
    end if
    DrawScreen

    if Time.Elapsed - lastFrameTime < MIN_MILLISECS_BETWEEN_FRAMES then
        delay (MIN_MILLISECS_BETWEEN_FRAMES - (Time.Elapsed - lastFrameTime))
    end if
    lastFrameTime := Time.Elapsed
end loop



pics.zip
 Description:

Download
 Filename:  pics.zip
 Filesize:  217.4 KB
 Downloaded:  363 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Sun Apr 20, 2003 5:18 pm   Post subject: (No subject)

Never mind people, caught my mistake right after I posted this. I didn't include nooffscreenonly when I used View.Update. I am such an idiot. *Smaking myself on the head*.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: