Computer Science Canada

Sprites

Author:  maiku [ Mon Mar 13, 2006 10:22 pm ]
Post subject:  Sprites

!!!

I can't figure what a sprite is, let alone how to use it.....I'm a total noob

I believe a sprite is an image that I use in my program, like the main character, and if I'm wrong, please correct me!

If I'm right, then someone please tell me what command I use to do this, because the turing help guide isn't exactly very specific...I need an example, or a fake example...
Please???

Author:  Dan [ Tue Mar 14, 2006 1:53 am ]
Post subject: 

Sprites only work in versons of turing less then 4.0.1 or greater then 4.0.4c. And even in 4.0.5 they are ify.

What they are is an image witch can be moved with out destoying the backgorund image. However this is not the best way to do this and in the new versons of turing you should be using View.Update and offscreen graphicsks mode to do animation.

For more information on both subjects please use the search function or look threw the tutorals. Or you could post your questions here, i guses =p.

Author:  Imm0rtal [ Tue Mar 14, 2006 2:00 am ]
Post subject: 

Sprites are usually the graphics used for different "people" IE: the characters you control/interact with.. Often times you get a sprite "sheet" which has different positions for each possible move the user would make..

EXAMPLE:
http://www.northcastle.co.uk/archive/vault/sprites/link2.gif

In Turing the sprite functions give you control over linking these images and then depending on a getch statement you can move them around..

I personally do not use the sprite functions.. Thats not how I started my current project and I had no intention of switching over.

Test:

THE BELOW CODE IS SLOPPY:
One reason is your not releasing pictures your done with.. so after 1000 steps your program will crash. Also there are a number other reasons why this is sloppy but for the sake of easy to follow code I like it. You will need 12 pictures total.

3 Different pictures for him walking UP, DOWN, LEFT, RIGHT (Think Zelda)
Each picture should be named as such:
UP1.bmp
UP2.bmp
UP3.bmp
DOWN1.bmp
ect...

Goodluck


code:

View.Set ("offscreenonly")
setscreen ("graphics:vga")
setscreen ("nocursor")
var keypress : string (1)
var spriteID := Pic.FileNew ("RIGHT1.bmp")
var corX, corY : int := 220
var StepCount : int := 1

Pic.Draw (spriteID, 220, 220, picMerge)


loop
        getch (keypress)  % MAIN ACTION GETCH COMMAND
       



        if (keypress) = (KEY_UP_ARROW) then
            corY := corY + 5
            if StepCount = 1 then
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("UP1.bmp")
                StepCount := StepCount + 1
            elsif StepCount = 2 then
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("UP2.bmp")
                StepCount := StepCount + 1
            else
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("UP3.bmp")
                StepCount := 1
            end if

        elsif (keypress) = (KEY_RIGHT_ARROW) then         %Key Right Arrow
            corX := corX + 5
            if StepCount = 1 then
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("RIGHT1.bmp")
                StepCount := StepCount + 1
            elsif StepCount = 2 then
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("RIGHT2.bmp")
                StepCount := StepCount + 1
            else
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("RIGHT3.bmp")
                StepCount := 1
            end if

        elsif (keypress) = (KEY_LEFT_ARROW) then         %Key Left Arrow
            corX := corX - 5
            if StepCount = 1 then
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("LEFT1.bmp")
                StepCount := StepCount + 1
            elsif StepCount = 2 then
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("LEFT2.bmp")
                StepCount := StepCount + 1
            else
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("LEFT3.bmp")
                StepCount := 1
            end if

        elsif (keypress) = (KEY_DOWN_ARROW) then         %Key Down Arrow
            corY := corY - 5
            if StepCount = 1 then
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("DOWN1.bmp")
                StepCount := StepCount + 1
            elsif StepCount = 2 then
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("DOWN2.bmp")
                StepCount := StepCount + 1
            else
                Pic.Free (spriteID)
                spriteID := Pic.FileNew ("DOWN3.bmp")
                StepCount := 1
            end if

        end if


       
        %DEBUG:::
        color (3)
        colorback (255)
        cls
        Pic.Draw (spriteID, corX, corY, picMerge) % DRAW SPRITE
        View.Update
end loop
Twisted Evil

Author:  maiku [ Tue Mar 14, 2006 12:29 pm ]
Post subject:  Thanks....???

Thanks for the info guys

If you think I'm kinda dumb, you'd be guessing right....

I use Turing 4.0.5 so sprites hould work, but I'm still a little confused

Any more info would help but I think I got it

THANKS! Very Happy

Author:  [Gandalf] [ Tue Mar 14, 2006 6:54 pm ]
Post subject: 

Sprites in Turing 4.0.5 are only either using the Pic module, or else using a third party library, like DanSprite or BacchusSprite. You do not have the ability to use the Sprite module, but sprite graphics manipulation is quite possible using the Pic module, as long as you redraw the background at every frame.

Author:  maiku [ Thu Mar 23, 2006 4:01 pm ]
Post subject:  Sprites

Confused ok.....

This kinda helped......It took me this long to figure it all out, and I noticed that I'm not getting any good information, everyone si just complaining that I shouldn't use sprites......But honestly, It's the way I want to do it.....So ANYONE PLEASE TELL ME HOW!!!!!

I think I'm doing it right, but i got mad and deleted my code.....the problem was that my sprites weren't appearing

Help anyone???

Author:  Imm0rtal [ Thu Mar 23, 2006 6:41 pm ]
Post subject: 

I would have to see your source code to tell you what was wrong with it.. OH YEA! you deleted it.. smooooth.

My source code would work find and it is reccomended you use it. You asked for our help and we gave it to you. If it is too complicated to copy and paste my source code into turing.. Get 9 pictures with the proper names. Then perhaps your in the wrong forum.

Sorry but we can't make it any simpler.. Confused

Author:  Imm0rtal [ Thu Mar 23, 2006 6:42 pm ]
Post subject: 

Make that 12 pictures

Author:  rizzix [ Thu Mar 23, 2006 7:58 pm ]
Post subject: 

Imm0rtal easy on the double post.

Author:  maiku [ Fri Mar 24, 2006 3:33 pm ]
Post subject: 

I am thankful for your help, and no, its not too complicated to copy your code into turing, but i have almost the exact same program, but a bit smoother

And that last post really made no sense what so ever........

But thats anyways

Author:  maiku [ Fri Mar 24, 2006 3:35 pm ]
Post subject: 

Here's my coding program, zipped

Author:  Imm0rtal [ Fri Mar 24, 2006 6:10 pm ]
Post subject: 

I got an error when running the program. Laughing

Author:  [Gandalf] [ Sat Mar 25, 2006 12:34 am ]
Post subject: 

I don't. And I don't see the problem, the code works fine on both Turing 4.0.5 and Turing 4.1. There are many ways I would suggest improving the code (ie. split it up into procedures/functions, only use one delay in the loop, etc) but it seems to work for your purposes. You must ask a question first before getting an answer.

Author:  maiku [ Sun Mar 26, 2006 8:21 am ]
Post subject: 

The program does work, just make sure you have the folder 'chrono' in the same location as the .t file

I was wondering if someone could change my coding, or redo my coding, so that It is done with the Sprite module, and not Pic

Oh, and there needs to be a lot of delays, just because of the way the images are set up. The character (chrono) takes a step, but he always returns to a standing still position facing the way that he just moved

Author:  Imm0rtal [ Sun Mar 26, 2006 11:29 am ]
Post subject: 

You should get rid of the delays... they make a slight pause everytime you press a key that is very annoying..

also if you want him to face the same way after you move him.. that shouldn't be very difficult at all. Smile

Author:  maiku [ Sun Mar 26, 2006 11:35 am ]
Post subject: 

The thing is that I may be using this for my programing class summative, so I don't want to do it the best way because my teacher will probably know that I didn't do it myself.

And if anyone could give me and tips on doing sprites, or if they could rewrite my coding using sprites, it would be much appreciated Razz

I wouldn't mind if someone just told me how to use sprites, like the order of the commands, like importing pic, setting height, and then making it appear

THANKS!

Author:  Imm0rtal [ Sun Mar 26, 2006 6:51 pm ]
Post subject: 

maiku wrote:
The thing is that I may be using this for my programing class summative, so I don't want to do it the best way because my teacher will probably know that I didn't do it myself.


Maybe you should stop getting us to do your homework and she will have more faith in you..

maiku wrote:

And if anyone could give me and tips on doing sprites, or if they could rewrite my coding using sprites, it would be much appreciated Razz


Help > Turing Reference (or F9) > Search (or "S") > Then type "Sprite."

Bam all the knowledge you need on sprites.. Doesn't change the fact that is not recomended you use them.


: