
-----------------------------------
Paul
Tue Apr 20, 2004 3:55 pm

[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:

var pic1 : int
pic1 := Pic.FileNew ("nameofPic.bmp")


Then we turn the image into a Sprite:

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?


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.


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.


Sprite.Show (spriteID)

Makes the sprite visible.


Sprite.Hide (spriteID)

Makes the sprite invisible


Sprite.ChangePic (spriteID, picID)

Change the sprite to a new image.


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.


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:

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.

-----------------------------------
Delos
Tue Apr 20, 2004 4:42 pm


-----------------------------------
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.

-----------------------------------
Paul
Tue Apr 20, 2004 4:57 pm


-----------------------------------
or I could DL an old version of it just to see it work.

-----------------------------------
Delos
Tue Apr 20, 2004 6:48 pm


-----------------------------------
To counter that...

Older versions + View.Update != true

Ergo:

Sprites == "rather choppy and visually irritating".

 :D

-----------------------------------
Paul
Tue Apr 20, 2004 6:49 pm


-----------------------------------
hmm bah, I just don't wanna see my filled up section of brain space go to waste learning this.

-----------------------------------
Cervantes
Tue Apr 20, 2004 7:40 pm


-----------------------------------
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. :?  So easy, yet so seemingly pointless. :think:

-----------------------------------
Dan
Tue Apr 20, 2004 9:23 pm


-----------------------------------
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:

-----------------------------------
Pickles
Tue Apr 27, 2004 3:27 pm

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.. :)

-----------------------------------
Paul
Tue Apr 27, 2004 4:03 pm


-----------------------------------
Woot! After all these comments, finally someone found use for it...
I feel happy now.  :lol:

-----------------------------------
white_dragon
Tue May 04, 2004 1:59 pm


-----------------------------------
lol.  do we ever use sprites anyway? like in 4.05 we never seem to use it

-----------------------------------
Paul
Tue May 04, 2004 2:00 pm


-----------------------------------
it doesn't work in 4.0.3 or 4.0.4 or 4.0.5.

-----------------------------------
Dan
Tue May 04, 2004 3:33 pm


-----------------------------------
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.

-----------------------------------
Paul
Tue May 04, 2004 3:39 pm


-----------------------------------
My teacher might make us use dansprite, because of me ;)

-----------------------------------
Dan
Tue May 04, 2004 9:21 pm


-----------------------------------
lol, i better fix them then

-----------------------------------
PhOeNiX-47
Tue May 18, 2004 6:04 pm


-----------------------------------
Wait, I'm confused! So you can't use this tutorial in 4.04c?

-----------------------------------
Paul
Tue May 18, 2004 6:17 pm


-----------------------------------
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

-----------------------------------
P2BC1414
Tue Dec 21, 2004 10:28 am


-----------------------------------
Is that sample supposed to work just like that? or do I have to change some things?

-----------------------------------
DKNiGHTX
Sun Jan 14, 2007 6:07 pm

RE:[Tutorial] Sprites
-----------------------------------
Sprites are in Turing 4.1 again.  Thanks for this.

-----------------------------------
rcbhs
Wed Dec 12, 2007 8:31 pm

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

-----------------------------------
LaZ3R
Wed Dec 12, 2007 10:51 pm

RE:[Tutorial] Sprites
-----------------------------------
You just revived a 3 year old thread... Dear GOD O_O

-----------------------------------
StealthArcher
Thu Dec 13, 2007 12:56 am

RE:[Tutorial] Sprites
-----------------------------------
Actually, it's only technically 11 months old.  But still...

-----------------------------------
rcbhs
Thu Dec 13, 2007 11:01 pm

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.

-----------------------------------
Lawlly
Fri Dec 14, 2007 6:53 pm

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?


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


-----------------------------------
rcbhs
Wed Dec 19, 2007 9:17 am

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) =/

-----------------------------------
Lawlly
Wed Dec 19, 2007 7:12 pm

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.

-----------------------------------
Gackt
Thu Dec 20, 2007 10:11 am

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.

-----------------------------------
rcbhs
Thu Dec 20, 2007 2:02 pm

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  :cry:  

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.

-----------------------------------
FlamingKatana
Mon Jan 28, 2008 1:22 pm

RE:[Tutorial] Sprites
-----------------------------------
Um so how do i exactly make sprites move with key board?
It wont work 