Computer Science Canada

[tutorial] Smooth Animation / Moving Background

Author:  Tony [ Fri Dec 20, 2002 4:17 pm ]
Post subject:  [tutorial] Smooth Animation / Moving Background

This source file was send to me by Tom West, it is well commented and shows an interesting aspect of how you can smoothly move your images and how you can move your background image.

Note Works only in 4.x

Download the file attached.

Author:  FwuffyTheBunny [ Wed Apr 09, 2003 10:07 am ]
Post subject: 

Word...

Author:  ShadowStorm [ Fri Apr 25, 2003 9:43 am ]
Post subject: 

i'm quite new to Turing and i need a little help on this... the screen keeps on flickering and i can't get a clean/smooth animation

code:

setscreen ( "graphics:1000;700")
var x,y : int
var sky : int
var ship : int
var backgroundPictureWidth, backgroundPictureHeight : int
var backgroundPictureX, backgroundPictureY : int

ship := Pic.FileNew ("c5.bmp")
sky := Pic.FileNew ("sky.jpg")
backgroundPictureWidth := Pic.Width (sky)
backgroundPictureHeight := Pic.Height (sky)
backgroundPictureX := (backgroundPictureWidth - (maxx + 1)) div 2
backgroundPictureY := (backgroundPictureHeight - (maxy + 1)) div 2



x:=100
y:=100
var chars : array char of boolean
        loop
       
        Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                y:=y+15
            end if
            if chars (KEY_RIGHT_ARROW) then
                x:=x+15
            end if
            if chars (KEY_LEFT_ARROW) then
                x:=x-15
            end if
            if chars (KEY_DOWN_ARROW) then
                y:=y-15
            end if
            cls
            Pic.Draw (sky, -backgroundPictureX, -backgroundPictureY, picCopy)
            Pic.Draw(ship,x,y,picMerge)
            View.Update
        end loop


thanx..

Author:  Prince [ Fri Apr 25, 2003 10:05 am ]
Post subject: 

does neone wanna b nice enuf to send me turing 4 seeing as how my skool doesnt wanna use it and theres no other way of me gettin it Smile... im missin out on too many great programs Sad

Author:  jamez [ Fri Apr 25, 2003 1:05 pm ]
Post subject: 

code:


setscreen ( "graphics:1000;700,offscreenonly")
var x,y : int
var sky : int
var ship : int
var backgroundPictureWidth, backgroundPictureHeight : int
var backgroundPictureX, backgroundPictureY : int

ship := Pic.FileNew ("c5.bmp")
sky := Pic.FileNew ("sky.jpg")
backgroundPictureWidth := Pic.Width (sky)
backgroundPictureHeight := Pic.Height (sky)
backgroundPictureX := (backgroundPictureWidth - (maxx + 1)) div 2
backgroundPictureY := (backgroundPictureHeight - (maxy + 1)) div 2



x:=100
y:=100
var chars : array char of boolean
        loop
       
        Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                y:=y+15
            end if
            if chars (KEY_RIGHT_ARROW) then
                x:=x+15
            end if
            if chars (KEY_LEFT_ARROW) then
                x:=x-15
            end if
            if chars (KEY_DOWN_ARROW) then
                y:=y-15
            end if
View.Update
delay(10)
            cls
            Pic.Draw (sky, -backgroundPictureX, -backgroundPictureY, picCopy)
            Pic.Draw(ship,x,y,picMerge)
            View.Update
        end loop

Author:  ShadowStorm [ Fri Apr 25, 2003 3:17 pm ]
Post subject: 

thanx alot man... Very Happy

Author:  hello [ Sun May 11, 2003 2:40 pm ]
Post subject:  Smooth Moving Background

This is what i did and it seems to work very well

u can start off with the background

have two pic ids both of the same picture or different pictures

then for each id have a separate y value so when its in the loop it can change

within the loop
draw the first picture in screen
and then draw the next picture off screen above the first one

then have both y values decrease or increase in the same amount

have two if statements checking for each y value
if the y value is less than the negative of the length of y of the window
set the y value to the positive of the y length of the window
and draw it

Author:  ¿§¥JÃ¥mës¥§¿ [ Mon Aug 25, 2003 1:13 pm ]
Post subject: 

jamez wut did you change in that program?
I can see that U addad the View.Update but I tryed that in my program and it didn't work Confused Do you have to hav all the Draw commaneds in bettewn the View.Update? because in my program there not does that matter?

Author:  Tony [ Mon Aug 25, 2003 4:49 pm ]
Post subject: 

you gotta have
code:

View.Set("offscreenonly")


at top of your program. Then:

loop
draw something
draw something else
..
View.Update
end loop

Author:  ¿§¥JÃ¥mës¥§¿ [ Mon Aug 25, 2003 5:35 pm ]
Post subject:  Thanx

thanx alot that did the trick and I was right I had to put all my pics togeter in on spot. Thanx Tony!!! Very Happy 8)

Author:  HeTeRiC [ Sat Nov 22, 2003 3:53 pm ]
Post subject: 

code:
if jupiterX - MARGIN < 0 then
        jupiterX := MARGIN
    elsif jupiterX + jupiterWidth > spaceWidth - MARGIN then
        jupiterX := spaceWidth - MARGIN - jupiterWidth
    end if


k i know that this tell the prog to move the background insted of the
jupiter pic, but how would you make the jupiter pic just stop??
(like hitting a wall in a game)
i've only been learning this fer like 7 hours so if this is extremly easy just call me stupid Wink

Author:  Tony [ Sat Nov 22, 2003 3:58 pm ]
Post subject: 

to stop, you just don't allow the picture to move pass 0. such as
code:

var x:int := maxx

loop

Draw.Oval(x,100,5,5,red)
if x-5 < 0 then
%you've hit the wall, can't move pass
exit %exits loop
else
%otherwise still space in front to move
x:=x-5 %move 5 pixels to the left
delay(25)
end if

end loop

Author:  HeTeRiC [ Sat Nov 22, 2003 4:17 pm ]
Post subject: 

Wow that was fast!
Thank You Burn
"one more thing!"
how do you stop it from moving past the point then still be able to move the object.
(move star around box but non let if exit box?)
i just need to know how to stop if from moving while still being able to controll it in other directions
thnaks again

Author:  HeTeRiC [ Sat Nov 22, 2003 6:49 pm ]
Post subject: 

whoops!!
Found it somewhere else
nevermind
thanx anyways

Author:  bevoyleick [ Wed Mar 17, 2004 9:59 am ]
Post subject: 

is there anyway that Turing can load faster?? i mean, i made this "space invaders" program for my comp sci proj, but as more and more aliens come down, the entire game just becomes slower and slower. (aliens are .jpg files)

Author:  AsianSensation [ Wed Mar 17, 2004 2:26 pm ]
Post subject: 

currently, no. There isnt anyway for you to make it faster.

However, there are methods you can use to reduce the intensity of this problem. Regulate the amount of frames per seconds in your program will make it run at a smooth pace. So it won't be really fast in the beginning and crawling at the end.

Pic.Free the pictures that you are not using, so if the enemy flew off the screen, or died, Pic.Free it, and don't draw it anymore. This will free up the memory, so you don't have to deal with so many pictures.

Another thing, limit the amount of stuff on screen. A space game with like 30 something objects on the screen at the same time isn't that bad, and it will run very smooth. Unless you have huge pictures and gigantic amount of pictures on the screen at a time, like 100+, then there shouldn't be a problem.

Author:  hq78 [ Mon Jan 10, 2005 4:18 pm ]
Post subject: 

how do you make the background picture bigger... like a lot bigger!

Author:  Cervantes [ Mon Jan 10, 2005 8:42 pm ]
Post subject: 

Pic.Scale might be of use to you.

Author:  Forumer [ Wed Dec 03, 2008 8:04 am ]
Post subject: 

ShadowStorm @ Fri Apr 25, 2003 9:43 am wrote:
i'm quite new to Turing and i need a little help on this... the screen keeps on flickering and i can't get a clean/smooth animation

code:

setscreen ( "graphics:1000;700")
var x,y : int
var sky : int
var ship : int
var backgroundPictureWidth, backgroundPictureHeight : int
var backgroundPictureX, backgroundPictureY : int

ship := Pic.FileNew ("c5.bmp")
sky := Pic.FileNew ("sky.jpg")
backgroundPictureWidth := Pic.Width (sky)
backgroundPictureHeight := Pic.Height (sky)
backgroundPictureX := (backgroundPictureWidth - (maxx + 1)) div 2
backgroundPictureY := (backgroundPictureHeight - (maxy + 1)) div 2



x:=100
y:=100
var chars : array char of boolean
        loop
       
        Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                y:=y+15
            end if
            if chars (KEY_RIGHT_ARROW) then
                x:=x+15
            end if
            if chars (KEY_LEFT_ARROW) then
                x:=x-15
            end if
            if chars (KEY_DOWN_ARROW) then
                y:=y-15
            end if
            cls
            Pic.Draw (sky, -backgroundPictureX, -backgroundPictureY, picCopy)
            Pic.Draw(ship,x,y,picMerge)
            View.Update
        end loop


thanx..


code:

setscreen ( "offscreenonly,graphics:1000;700")
var x,y : int
var sky : int
var ship : int
var backgroundPictureWidth, backgroundPictureHeight : int
var backgroundPictureX, backgroundPictureY : int

ship := Pic.FileNew ("c5.bmp")
sky := Pic.FileNew ("sky.jpg")
backgroundPictureWidth := Pic.Width (sky)
backgroundPictureHeight := Pic.Height (sky)
backgroundPictureX := (backgroundPictureWidth - (maxx + 1)) div 2
backgroundPictureY := (backgroundPictureHeight - (maxy + 1)) div 2



x:=100
y:=100
var chars : array char of boolean
        loop
       
        Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                y:=y+15
            end if
            if chars (KEY_RIGHT_ARROW) then
                x:=x+15
            end if
            if chars (KEY_LEFT_ARROW) then
                x:=x-15
            end if
            if chars (KEY_DOWN_ARROW) then
                y:=y-15
            end if
            cls
            Pic.Draw (sky, -backgroundPictureX, -backgroundPictureY, picCopy)
            Pic.Draw(ship,x,y,picMerge)
            View.Update
        end loop


fixed it for ya

Author:  Parker [ Wed Dec 03, 2008 8:35 am ]
Post subject:  RE:[tutorial] Smooth Animation / Moving Background

Forumer, please check the date of the post. Yes, you may have fixed that but I doubt he was still trying to figure it out 3 years later Razz

The date of each post is located right above the text.

Author:  rcbhs [ Wed Dec 03, 2008 3:42 pm ]
Post subject:  Re: [tutorial] Smooth Animation / Moving Background

Umm, a solution i can think of is that you may not be freeing memory where you can. IE. Your done with a sprite and it won't be used again, then sprite.free it.

Author:  Parker [ Thu Dec 04, 2008 8:40 am ]
Post subject:  RE:[tutorial] Smooth Animation / Moving Background

rcbhs, just like I posted just before you, the code you are referring to was done like 3 years ago, and they aren't still trying to figure it out to this day (I hope). Please check the date of when it was posted before you post.

The date of each post is located above the text.

Author:  Flipmc [ Wed Jan 07, 2009 6:07 pm ]
Post subject:  RE:[tutorial] Smooth Animation / Moving Background

Awesome man, thanks alot for this.

Author:  livingheaven [ Sat May 29, 2010 8:51 pm ]
Post subject:  RE:[tutorial] Smooth Animation / Moving Background

NICE.

Author:  Insectoid [ Sat May 29, 2010 9:04 pm ]
Post subject:  RE:[tutorial] Smooth Animation / Moving Background

Was that single word really worth re-resurrecting an eight-year-old thread with over a year since the last post?

Author:  Unnamed.t [ Sat May 29, 2010 9:20 pm ]
Post subject:  Re: [tutorial] Smooth Animation / Moving Background

@livingheaven

I know I'm not any kind of Compsci admin but, please don't bring up threads that are over a year old for no apparent reason (LIKE JUST SAYING NICE). It isn't recommended to bring these posts up at all, except if there is a proper reason to do so, for example: you just found out a way to make Turing animations even smoother or faster.

What you did is called Necro posting and you will probably get banned soon if you continue to do this. I recommend that you review the compsci rules.

Author:  supaphreek [ Sun May 30, 2010 10:28 am ]
Post subject: 

HeTeRiC @ Sat Nov 22, 2003 4:17 pm wrote:
Wow that was fast!
Thank You Burn
"one more thing!"
how do you stop it from moving past the point then still be able to move the object.
(move star around box but non let if exit box?)
i just need to know how to stop if from moving while still being able to controll it in other directions
thnaks again


What you could do is find whatever variable is loading the x and y position of jupiter. Then using that, you can have an if statement like

if x > 500 then
x := 500
end if


This will say that if the x point of the image is above 500, it will make it to 500 Razz

Author:  Insectoid [ Sun May 30, 2010 10:55 am ]
Post subject:  RE:[tutorial] Smooth Animation / Moving Background

Supaphreek, will you please check the date of the post you're quoting? That person either ditched CS years ago or has acquired a degree by now. It's even worse that you posted this DIRECTLY AFTER someone else was reprimanded for necroing this very thread.

Author:  Tony [ Sun May 30, 2010 11:18 am ]
Post subject:  RE:[tutorial] Smooth Animation / Moving Background

You guys are ridiculous. Locked.


: