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

Username:   Password: 
 RegisterRegister   
 Animation Flickering...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
antiLogic




PostPosted: Wed Jun 10, 2009 1:34 pm   Post subject: Animation Flickering...

What is it you are trying to achieve?
Have the autonomous planes fly and the keyboard control plane fly without flickering

What is the problem you are having?
The autonomous planes flicker whenever the keyboard control plane stops moving. Also, the animation in general is a bit choppy.

Describe what you have tried to solve this problem
I've tried having 2 procedures draw the plane step by step at the same time using a fork procedure. I know forks are problematic but its the best way for me to attack my problem.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:

setscreen ("graphics:800;600")
View.Set ("offscreenonly")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var pic := Pic.FileNew ("plane_sprite.bmp")
var picRotated : array 0 .. 35 of int
for i : 0 .. 35
    picRotated (i) := Pic.Rotate (pic, i * 10, Pic.Width (pic) div 2, Pic.Height (pic) div 2)
end for
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Picture declaration and array to hold rotated images
proc plane_flight
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    var r : int := Rand.Int (0, 35)
    var chars : array char of boolean
    var tmpShip : int := picRotated (r)
    var ctr : int := r
    var x, y : real := Rand.Int (20, 400)
    loop
        delay (20)
        %Exit when plane reaches border
        exit when x >= 600 or x <= 0 or y <= 0 or y >= 800
        x += cosd ((ctr mod 36) * 10 + 90) * 5
        y += sind ((ctr mod 36) * 10 + 90) * 5
        Pic.SetTransparentColor (tmpShip, white)
        %Pic.ScreenLoad ("airport.bmp", 0, 0, picCopy)
        Pic.Draw (tmpShip, round (x), round (y), picMerge)
        % var picNew := Pic.New (0, 0, maxx, maxy)
        % Pic.SetTransparentColor (picNew, white)
        % Pic.ScreenLoad ("airport.bmp", 0, 0, picCopy)
        % Pic.Draw (picNew, 0, 0, picMerge)
        % Pic.Free (picNew)
        View.Update
    end loop

    %    Pic.ScreenLoad ("airport.bmp", 0, 0, picCopy)
end plane_flight

proc plane_control
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    var chars : array char of boolean
    var tmpShip := picRotated (0)
    var ctr := 0
    var landingCTR : int := 0
    var x, y : real := Rand.Int (20, 400)

    loop
        var dlay : int := 20
        exit when landingCTR = 10
        Input.KeyDown (chars)
        if chars (KEY_RIGHT_ARROW) then
            ctr -= 1
            tmpShip := picRotated (ctr mod 36)
        end if
        if chars (KEY_LEFT_ARROW) then
            ctr += 1
            tmpShip := picRotated (ctr mod 36)
        end if
        if chars ('s') then
            dlay := 75
        end if
        if chars (KEY_UP_ARROW) then
            delay (dlay)
            x += cosd ((ctr mod 36) * 10 + 90) * 5
            y += sind ((ctr mod 36) * 10 + 90) * 5
        end if
        %%%%%CHECKS IF PLANE IS WITHIN LANDING ZONE
        if chars ('l') and x > 0 and x < 300 and y > 0 and y < 400 then
            delay (10)
            landingCTR += 1
        end if

        Pic.SetTransparentColor (tmpShip, white)
        Pic.ScreenLoad ("airport.bmp", 0, 0, picCopy)
        Pic.Draw (tmpShip, round (x), round (y), picMerge)
        % exit when x > 100 and x < 1000 and y > 100 and y < 200
        View.Update
    end loop
end plane_control


proc refresh
    % var picNew := Pic.New (0, 0, maxx, maxy)
    % Pic.SetTransparentColor (picNew, white)
    % Pic.ScreenLoad ("airport.bmp", 0, 0, picCopy)
    % Pic.Draw (picNew, 0, 0, picMerge)
    % Pic.Free (picNew)
    View.Update
end refresh

process processrefresh
    loop
        refresh
        delay (10)
    end loop
end processrefresh

process processplane_control
    plane_control
end processplane_control

process processplane_flight
    loop
        plane_flight
        delay (5000)
    end loop
end processplane_flight

fork processplane_control
fork processplane_flight
fork processplane_flight
%fork processrefresh


Please specify what version of Turing you are using
4.1.1



plane_sprite.bmp
 Description:
The plane sprite
 Filesize:  7.82 KB
 Viewed:  1488 Time(s)

plane_sprite.bmp


Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Jun 10, 2009 4:50 pm   Post subject: RE:Animation Flickering...

You have 3 View.Updates in your code, which is a problem. The entire point of View.Update is to have it in only one place.

I figure that
code:

loop
        refresh
        delay (10)
    end loop

is causing major problems, as it would randomly draw partially rendered screens.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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: