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

Username:   Password: 
 RegisterRegister   
 [Tutorial] Sprites
Index -> Programming, Turing -> Turing Tutorials
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Paul




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Tue Apr 20, 2004 4:42 pm   Post subject: (No 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.
Paul




PostPosted: Tue Apr 20, 2004 4:57 pm   Post subject: (No subject)

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




PostPosted: Tue Apr 20, 2004 6:48 pm   Post subject: (No subject)

To counter that...

Older versions + View.Update != true

Ergo:

Sprites == "rather choppy and visually irritating".

Very Happy
Paul




PostPosted: Tue Apr 20, 2004 6:49 pm   Post subject: (No subject)

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




PostPosted: Tue Apr 20, 2004 7:40 pm   Post subject: (No 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
Dan




PostPosted: Tue Apr 20, 2004 9:23 pm   Post subject: (No 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
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Pickles




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Tue Apr 27, 2004 4:03 pm   Post subject: (No subject)

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




PostPosted: Tue May 04, 2004 1:59 pm   Post subject: (No subject)

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




PostPosted: Tue May 04, 2004 2:00 pm   Post subject: (No subject)

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




PostPosted: Tue May 04, 2004 3:33 pm   Post subject: (No 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.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Paul




PostPosted: Tue May 04, 2004 3:39 pm   Post subject: (No subject)

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




PostPosted: Tue May 04, 2004 9:21 pm   Post subject: (No subject)

lol, i better fix them then
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
PhOeNiX-47




PostPosted: Tue May 18, 2004 6:04 pm   Post subject: (No subject)

Wait, I'm confused! So you can't use this tutorial in 4.04c?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 3  [ 36 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: