Posted: Thu Feb 19, 2009 6:46 am Post subject: Can't get my sprite moving.
Hello.
I'm new to the forums, and new to Turing. I'm currently working on making a small game. The only problem is I don't know how to get my sprite moving. I've been looking at tutorials for the past four hours straight and I don't know what to do to fix it. I've tried the Sprite.Animate command and I've tried the entire loop -> Input.KeyDown thing.
The bit looks like this . . .
Turing:
var x: int:=0 var y: int:=0 var x_velocity :int:=0 var y_velocity:int:=0 var pic :=Pic.FileNew("kksprite.bmp") var chars :arraycharofboolean loop Pic.Draw(pic,40,40,picCopy)
All well and good, it draws the sprite but it won't move.
Any help is greatly appreciated.
Mod Edit: Remember to use syntax tags! Thanks
code:
[syntax="turing"]Code Here[/syntax]
Sponsor Sponsor
copthesaint
Posted: Thu Feb 19, 2009 7:09 am Post subject: RE:Can\'t get my sprite moving.
Razgriz This isn't spritz first thing. If it was you wouldn't be using the delay. Now the reason it isn't moving is because you forgot to draws your picture at the y and x value. Instead you draw it at 40 x, and 40 y. Also if you want to, Make The background of whatever picture that is white then use picMerge instead of picCopy. This will make the white invisible.
Razgriz
Posted: Thu Feb 19, 2009 10:24 am Post subject: RE:Can\'t get my sprite moving.
I don't understand what you mean in your post.
Primarily, as I said at the beginning, I am *new* to Turing and currently have no @#$%ing idea what you mean when you say "If it was you wouldn't be using the delay. [...] at the y and x value."
Secondly, using picMerge did absolutely nothing, as it looks 100% the same as it did when I used picDraw.
Note that I don't WANT the background to be white.
That's why it's green.
DemonWasp
Posted: Thu Feb 19, 2009 10:47 am Post subject: RE:Can\'t get my sprite moving.
The problem with your code (in the second post) is that you're updating the screen, THEN drawing the picture to the back-buffer.
What you're implementing there is called "double buffering". All drawing commands (including pictures, the Draw package and sprites) are drawn solely to the back-buffer, which is drawn to the screen when you say View.Update().
The correct way of doing this is as follows:
Turing:
% Set up the screen for double-buffering (requires use of View.Update) setscreen("offscreenonly")
% Update variables here. This is where you would use Input.KeyDown.
% Draw the scene here. This is where you would draw any background images, then any middle-ground elements, then any foreground elements, such as the following: Pic.Draw(pic,240,120,picMerge)
% Force the back-buffer to be drawn to the screen. View.Update endloop
Razgriz
Posted: Thu Feb 19, 2009 11:02 am Post subject: RE:Can\'t get my sprite moving.
Okay, I am now thorougly confused.
So; if anyone could, please take this portion of my code and edit or at least comment on where I have gone wrong, because you've lost me on this.
Turing:
colorback(green) cls setscreen("offscreenonly") loop var pic :int:=Pic.FileNew("krystalsprite.gif") var x: int:=0 var y: int:=0 var x_velocity :int:=0 var y_velocity:int:=0 var chars :arraycharofboolean loop Pic.Draw(pic,40,40,picCopy)
The line to draw the character. When you say Pic.Draw(pic,40,40,picCopy), you are telling the program to ALWAYS draw the picture at 40,40. you should be using the variables for the characters location instead of a constant.
Razgriz
Posted: Thu Feb 19, 2009 11:09 am Post subject: RE:Can\'t get my sprite moving.
Ohh.
Thanks.
*High fives the first person who made sense to me*
Razgriz
Posted: Thu Feb 19, 2009 12:02 pm Post subject: RE:Can\'t get my sprite moving.
And, now, through two hours of looking I can't get the background to move with the character. It's a birds-eye view game, of course.
Can someone tell me two things:
1 - How to get rid of that @#$%ed white box around my sprite (Yes, I AM USING picMerge!)
and 2 - How to get the background to move.
Any help is appreciated.
Thanks.
-Krystal
Sponsor Sponsor
DemonWasp
Posted: Thu Feb 19, 2009 2:45 pm Post subject: RE:Can\'t get my sprite moving.
1. Are you sure that the white background is actually white and not some off-white colour? If it's not exactly white, it won't be treated as transparent, IIRC.
2. What do you mean by having the background move? Is the background some sort of large image you're going to load and draw, or what?
Razgriz
Posted: Thu Feb 19, 2009 7:05 pm Post subject: Re: Can't get my sprite moving.
*All of that is aside, I have it working now.
But I could use some help with a collision detection map.
Attached is a map just used for testing itself... anyone who can help me with how to work a collision map working (Preferable with 0's being ground that can be moved across, and 1's being blocks, walls, etc.)
bg.GIF
Description:
Filesize:
28.73 KB
Viewed:
118 Time(s)
Razgriz
Posted: Thu Feb 19, 2009 7:06 pm Post subject: Re: Can't get my sprite moving.
That aside, I would also need to know where to put that in relation to my drawn pic, background and movement keys...
code looks like:
Turing:
%I don't know where I would put the collision map, or what the command to use it in the first place is. var pic2:int:=Pic.FileNew("intropic.gif") var bgWidth :=Pic.Width(pic2) var bgHeight :=Pic.Height(pic2) var picWidth :=Pic.Width(pic2) var picHeight :=Pic.Width(pic2) var picX :=(picWidth - maxx)div2 var picY :=(picHeight - maxy)div2 var pix: int:=0 var piy: int:=0 Pic.Draw(pic2, -pix, -piy, picCopy) color(black) locate(24,10) put name, ": Wh-Where am I?" delay(2000) cls Pic.Draw(pic2, -pix, -piy, picCopy) locate(24,1) put"MOM: A bombshell went off. You blacked out, and your fathers' whereabouts are unknown." delay(5000) cls Pic.Draw(pic2, -pix, -piy, picCopy) locate(24,1) put"I'm very worried. The mechs are already starting to press on the military front lines." delay(5000) cls Pic.Draw(pic2, -pix, -piy, picCopy) locate(24,10) put"Please, ", name, ", Find my husband!" delay(2500) cls
colorback(green) cls process playstuff
loop Music.PlayFile("portal - still alive (radio).mp3") endloop end playstuff
fork playstuff
const SPEED :int:=5 var pic :int:=Pic.FileNew("ksprite.gif") var bg :int:=Pic.FileNew("bg.gif") var bgHeight2 :=Pic.Height(bg) var picWidth2 :=Pic.Width(pic) var picHeight2 :=Pic.Height(pic) var bgWidth2 :=Pic.Width(bg) var bgX :=(bgWidth2 - maxx)div2 var bgY :=(bgHeight2 - maxy)div2 var x :int var y2:int
x :=(bgWidth - picWidth)div2
y2 :=(bgHeight - picHeight)div2 var chars :arraycharofboolean loop setscreen("offscreenonly") loop cls Pic.Draw(bg, -bgX, -bgY, picCopy) Pic.Draw(pic, x - bgX, y2 - bgY, picMerge) View.Update
ifhaschthen var ch :string(1) getch(ch) if ch =KEY_UP_ARROWthen
y2 += SPEED
if y2 - bgY + picHeight2 > maxythen
bgY := y2 + picHeight2 - maxy endif elsif ch =KEY_DOWN_ARROWthen
y2 -= SPEED
if y2 < bgY then
bgY := y2
endif elsif ch =KEY_LEFT_ARROWthen
x -= SPEED
if x < bgX then
bgX := x
endif elsif ch =KEY_RIGHT_ARROWthen
x += SPEED
if x - bgX + picWidth2 > maxxthen
bgX := x + picWidth2 - maxx endif endif endif endloop
endloop
Also: I wish to make a key to talk to characters, for example the space bar or enter button
What command is this? There's KEY_DOWN_ARROW and whatnot, as well as KEY_SHIFT which is all I understand of it so far.
What do you do for space bar/enter?
Last but certainly not least, A problem with this is as follows:
All was well with character positioning until I added the background image called 'intropic', which comes in before the actual movement and sprite and all that noise, and all of it works perfectly fine, except instead of in the middle of the map where I want my sprite to start, its off in the middle of nowhere and cannot bee moved until down and left are pushed, and then you have to move back on to the map.
Razgriz
Posted: Fri Feb 20, 2009 10:52 am Post subject: Re: Can't get my sprite moving.
Ah, and I forgot: When I finally understand how to make my character communicate with NPC's, I will need to get the screen to change like other RPG's (Close in view of people(s) speaking). What's the best way to do this?
Insectoid
Posted: Fri Feb 20, 2009 2:26 pm Post subject: RE:Can\'t get my sprite moving.
Procedure.
Razgriz
Posted: Fri Feb 20, 2009 4:45 pm Post subject: Re: RE:Can\'t get my sprite moving.
insectoid @ 20th February 2009 wrote:
Procedure.
Elaborate.
andrew.
Posted: Fri Feb 20, 2009 5:44 pm Post subject: RE:Can\'t get my sprite moving.
Use a procedure:
Turing:
procedure talkScreen
%do stuff end talkScreen
loop %do some stuff
talkScreen % this runs everything in the talkScreen procedure endloop