Computer Science Canada

[Tutorial] Sprites

Author:  Paul [ Tue Apr 20, 2004 3:55 pm ]
Post subject:  [Tutorial] Sprites

Hm... dunno if there is anything on sprites, I could only find DanSprite, heres what my teacher taught us, a really simple tutorial:
I just learned this and came up with an example, but we couldn't test it in class, cause sprites don't work, I expected it to work in 4.0.5, but it doesn't? I dunno. The example is at the bottom, dunno why it doesn't work.

- What is a Sprite?
A sprite is a picture. Each Sprite has a location (x and y) and a height (the height is the third dimension. Imagine it coming out of the screen). You use the height feature to overlap pictures.

- How do I create a Sprite?
You must first load a image into your program:
code:

var pic1 : int
pic1 := Pic.FileNew ("nameofPic.bmp")


Then we turn the image into a Sprite:
code:

var sprite1 : int
sprite1 := Sprite.New (pic1)


By default, Sprites are invisible and they do not have a location. So the next thing you have to do is give the Sprite a location, a height, and make it visible. We do this by using other Sprite commands.

- What are the other Sprite commands?

code:

Sprite.SetPosition (spriteID, x, y, centered)

Move the sprite to x, y. If centered = true then (x,y) is the center of the sprite. If centered = false then (x,y) is the lower left corner of the sprite.

code:

Sprite.SetHeight (spriteID, h)

The background has a height of 0. Sprites that have negative height will be behind the background. Sprites that have positive heights will be infront of the background. A sprite of height 2 will be infront of a sprite of height 1.

code:

Sprite.Show (spriteID)

Makes the sprite visible.

code:

Sprite.Hide (spriteID)

Makes the sprite invisible

code:

Sprite.ChangePic (spriteID, picID)

Change the sprite to a new image.

code:

Sprite.Animate (spriteID, picID, x, y, centered)

This is like calling ChangePic and SetPosition at the same time. It changes the image and location of the sprite.

code:

Sprite.Free (spriteID)

Use this at the end of ur program when you no longer need the sprite. It frees up memory.

Note: Any part of original image that has colour of 0 will become transparent.


Example:
code:

var pic1 : int := Pic.FileNew ("missile.bmp")
var sprite1 : int := Sprite.New (pic1)
var x, y : int := 0
var centered : boolean := false
var chars : array char of boolean
for a : 1 .. maxx by 5
    drawline (a, 0, a, maxy, black)
end for
Sprite.SetHeight (sprite1, 1)

loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        y += 5
    end if
    if chars (KEY_DOWN_ARROW) then
        y -= 5
    end if
    if chars (KEY_LEFT_ARROW) then
        x -= 5
    end if
    if chars (KEY_RIGHT_ARROW) then
        x += 5
    end if
    Sprite.SetPosition (sprite1, x, y, centered)
    Sprite.Show (sprite1)

end loop

Well I just wanted to share that, I don't even know if the above is done right, am I suppose to have Sprite.Show in the loop? I have 4.0.5 and I couldn't get it to display.

Author:  Delos [ Tue Apr 20, 2004 4:42 pm ]
Post subject: 

Oh boy...

Here we go again.

Do you know why DanSprite was made? That's right. Because Sprites do not exist yet....in the current implementation of Turing.

Yes, that's right. Though this entire tutuorial may be quite accurate...it amounts to very little seeing as none of it would work.

Good job on the effort...but if you so dearly want to make a Sprites Tutorial, make one on DanSprites instead...those actually work.

Author:  Paul [ Tue Apr 20, 2004 4:57 pm ]
Post subject: 

or I could DL an old version of it just to see it work.

Author:  Delos [ Tue Apr 20, 2004 6:48 pm ]
Post subject: 

To counter that...

Older versions + View.Update != true

Ergo:

Sprites == "rather choppy and visually irritating".

Very Happy

Author:  Paul [ Tue Apr 20, 2004 6:49 pm ]
Post subject: 

hmm bah, I just don't wanna see my filled up section of brain space go to waste learning this.

Author:  Cervantes [ Tue Apr 20, 2004 7:40 pm ]
Post subject: 

Not only am I surprised that your teacher tought you anything, I'm surprised that your teacher tought you something that doesn't work. Eh

Good job on the tutorial though. +25 BITS

EDIT: Hey, learning about perminatly invisible sprites reminds me of the so called "mental gymnastics" of math class, learning about imaginary numbers. Confused So easy, yet so seemingly pointless. Thinking

Author:  Dan [ Tue Apr 20, 2004 9:23 pm ]
Post subject: 

just to cleaer some things up sprites do not work in turing 4.0.5 or any other verson of turing 4.x.

sprites do work in truing 3.x but they are buggy when it comes to compling progames that have sprites in them (ushely you have to resart turing and make compiling the code the 1st thing you do b4 you run it or anything other then open the file).

for turing 4.x there are a few 3rd parity sprite moduales one being mine (DanSprites) and the other being rizzix's. both are open sorce and free to uses.

mine can be found on the dTeam page or you can take this link right to it here: http://www.compsci.ca/mx/index.php?page=58

P.S. my sprites are ment to use view.update Wink

Author:  Pickles [ Tue Apr 27, 2004 3:27 pm ]
Post subject:  Great stuff

Thanks, Using 3.1 1 and had only a vague idea as to waht a sprite was and no idea on how to use them.. your tutorial made me make a critical part of my game movement, not flash.. Smile

Author:  Paul [ Tue Apr 27, 2004 4:03 pm ]
Post subject: 

Woot! After all these comments, finally someone found use for it...
I feel happy now. Laughing

Author:  white_dragon [ Tue May 04, 2004 1:59 pm ]
Post subject: 

lol. do we ever use sprites anyway? like in 4.05 we never seem to use it

Author:  Paul [ Tue May 04, 2004 2:00 pm ]
Post subject: 

it doesn't work in 4.0.3 or 4.0.4 or 4.0.5.

Author:  Dan [ Tue May 04, 2004 3:33 pm ]
Post subject: 

it dose not wokring in any 4.x verson, they where droped when they whent from 3 to 4.

i think the reason for this is that turing 3.x used to realy just be c++ where they translated the turing code in to c++ code then compiled it. But with the 4 update i think they tried to make there own language and thos lost some of the featuchers that c++ gave it, like full screen and sprites.

i am still working on danSprites tho to make them better with the colsiones. i am plaing two diffrent versons of danSprites, witch u may be seeing in the near futucher if i ever get some time off school work.

Author:  Paul [ Tue May 04, 2004 3:39 pm ]
Post subject: 

My teacher might make us use dansprite, because of me Wink

Author:  Dan [ Tue May 04, 2004 9:21 pm ]
Post subject: 

lol, i better fix them then

Author:  PhOeNiX-47 [ Tue May 18, 2004 6:04 pm ]
Post subject: 

Wait, I'm confused! So you can't use this tutorial in 4.04c?

Author:  Paul [ Tue May 18, 2004 6:17 pm ]
Post subject: 

in 4.0.4 and 4.0.3 there'd be an error, in 4.0.5 there'd be no error but ur sprite would not show, sprites right now work for 3.11

Author:  P2BC1414 [ Tue Dec 21, 2004 10:28 am ]
Post subject: 

Is that sample supposed to work just like that? or do I have to change some things?

Author:  DKNiGHTX [ Sun Jan 14, 2007 6:07 pm ]
Post subject:  RE:[Tutorial] Sprites

Sprites are in Turing 4.1 again. Thanks for this.

Author:  rcbhs [ Wed Dec 12, 2007 8:31 pm ]
Post subject:  Re: [Tutorial] Sprites

I was asuming that code was to make the sprite move, yet whenever I press a button the sprite just disappears, any help here? (I have the latest version of turing off o holtsoft

Author:  LaZ3R [ Wed Dec 12, 2007 10:51 pm ]
Post subject:  RE:[Tutorial] Sprites

You just revived a 3 year old thread... Dear GOD O_O

Author:  StealthArcher [ Thu Dec 13, 2007 12:56 am ]
Post subject:  RE:[Tutorial] Sprites

Actually, it's only technically 11 months old. But still...

Author:  rcbhs [ Thu Dec 13, 2007 11:01 pm ]
Post subject:  Re: [Tutorial] Sprites

lol yeah its old but I saw it, had a question so I asked. Anyways I got it to work but I did it differently.

Author:  Lawlly [ Fri Dec 14, 2007 6:53 pm ]
Post subject:  Re: [Tutorial] Sprites

I've managed to make the picture appear, though it doesn't move. It just changes position.

RCBHS can you show me how you got it to work?

code:

var pic1 : int := Pic.FileNew ("Robot_Base.jpg")
var sprite1 : int := Sprite.New (pic1)
var x, y : int := 100
var centered : boolean := false
var chars : array char of boolean


Sprite.SetHeight (sprite1, 1)
Sprite.SetPosition (sprite1, x, y, centered)
Sprite.Show (sprite1)

loop

    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        Sprite.Animate (sprite1, pic1, x, y + 100, centered)
    elsif chars (KEY_DOWN_ARROW) then
        Sprite.Animate (sprite1, pic1, x, y - 100, centered)
    elsif chars (KEY_LEFT_ARROW) then
        Sprite.Animate (sprite1, pic1, x - 100, y, centered)
    elsif chars (KEY_RIGHT_ARROW) then
        Sprite.Animate (sprite1, pic1, x + 100, y, centered)
    end if

end loop

Author:  rcbhs [ Wed Dec 19, 2007 9:17 am ]
Post subject:  Re: [Tutorial] Sprites

Eh I did it wrong, I cannot get my sprite moving for Input.KeyDown. I can get it working with hasch but thats not very efficient. I also don't know how to get my character to animate properly (I want him to look like hes running) =/

Author:  Lawlly [ Wed Dec 19, 2007 7:12 pm ]
Post subject:  Re: [Tutorial] Sprites

I got my sprites to move.

I also got my sprites to animate.

I also got my sprites to move while animating.


Ill post how to do it later, or perhaps make my own tutorial but right now i'm busy into my project so it might be awhile.

Author:  Gackt [ Thu Dec 20, 2007 10:11 am ]
Post subject:  Re: [Tutorial] Sprites

I dont know if this is correct, But here is my sprite Set up thing. I kinda need alot of help on it. And i posted it in the Help forum to.

Author:  rcbhs [ Thu Dec 20, 2007 2:02 pm ]
Post subject:  Re: [Tutorial] Sprites

Ok so I got my sprites to animate and such (only know how to go from one picture to another an back (using a boolen variable and making it show a certain sprite when im pressing a cetrtain arrow key, then showing another when not pressing the key) my problem is that if I go diagonally (which i only wanna be able to do when I jump) it alternates between the two directional sprites and looks horrible Crying or Very sad

I'd like to be able to use about 6 different sprites for my run so it looks nice and fluent so if anybody can help me with that, I'd appreciate it. Also if anybody can teach me how to create a nice, fluent jump that'd be awesome.

Author:  FlamingKatana [ Mon Jan 28, 2008 1:22 pm ]
Post subject:  RE:[Tutorial] Sprites

Um so how do i exactly make sprites move with key board?
It wont work <_<.. .

Oh yeah and I joined today lol

to learn how to use Turing.

Author:  daklezardo [ Sat Feb 23, 2008 8:34 pm ]
Post subject:  Re: [Tutorial] Sprites

works in turing 4.1.1 ask me for download

Author:  daklezardo [ Sat Feb 23, 2008 8:46 pm ]
Post subject:  Re: [Tutorial] Sprites

works well in turing 4.1.1

Author:  sarm2005 [ Mon Mar 10, 2008 6:32 pm ]
Post subject:  Re: [Tutorial] Sprites

Is there anyway to rotate a sprite?

Author:  riveryu [ Wed Mar 12, 2008 9:56 pm ]
Post subject:  RE:[Tutorial] Sprites

I dont think there is a way to rotate a sprite.
You would have to rotate the picture used to create that sprite and redisplay it...
Maybe you can rotate the background instead in a game but thats cheating...

Author:  Sean [ Thu Mar 13, 2008 7:02 am ]
Post subject:  Re: [Tutorial] Sprites

We've already answered this before. There is no way to rotate spirtes, you would have to use Pic.Rotate.

Author:  Mackie [ Thu Mar 13, 2008 10:56 am ]
Post subject:  RE:[Tutorial] Sprites

No Vilament, this is a sprite. Not an image.

Author:  CreatedByGabe [ Sun Jun 28, 2015 7:40 pm ]
Post subject:  RE:[Tutorial] Sprites

WOW! Thanks bro! Im making a video-game with turing and this will really help!

Author:  CreatedByGabe [ Sun Jun 28, 2015 8:02 pm ]
Post subject:  RE:[Tutorial] Sprites

Is the code up top not working??
Use this one:

code:

var pic1 : int := Pic.FileNew ("BossDude.bmp")
var sprite1 : int := Sprite.New (pic1)
var x, y : int := 0
var centered : boolean := false
var characters :string (1)

Sprite.SetHeight (sprite1, 1)

loop
setscreen ("nocursor")
getch (characters)
    if characters = KEY_UP_ARROW then
        y += 10
    end if
    if characters = KEY_DOWN_ARROW then
        y -= 10
    end if
    if characters = KEY_LEFT_ARROW then
        x -= 10
    end if
    if characters = KEY_RIGHT_ARROW then
        x += 10
    end if
    Sprite.SetPosition (sprite1, x, y, centered)
    Sprite.Show (sprite1)

end loop


: