Help with Sprites and Getch
Author |
Message |
MichaelM
|
Posted: Thu Jun 21, 2007 2:32 pm Post subject: Help with Sprites and Getch |
|
|
Im making a game with a helicopter that'll move around when you press w,a,s,d. In the animation, the sprite moves up and down to give a better helicopter effect
as it bobs up and down. However, I cant figure out how to get it to move like that even when you arent pressing anything. Heres the code, right now it moves left only. code: |
setscreen ("graphics:1024;768")
var left1, left2, x : int
x := 0
var sprite : int
var ch : string (1)
left1 := Pic.FileNew ("heli-left1.bmp")
left2 := Pic.FileNew ("heli-left2.bmp")
sprite := Sprite.New (left1)
Sprite.SetPosition (sprite, 100, 100, true)
Sprite.SetHeight (sprite, 1)
Sprite.Show (sprite)
loop
if hasch then
getch (ch)
if ch = "a" then
x := x + 10
delay (500)
Sprite.Animate (sprite, left2, 100 - x, 100, false)
delay (500)
Sprite.Animate (sprite, left1, 100 - x, 102, false)
end if
end if
end loop
|
Could someone please show me how to do this, and were to put it in this code, thanks! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Thu Jun 21, 2007 4:10 pm Post subject: RE:Help with Sprites and Getch |
|
|
Well the problem is that your entire animation is wrapped in if hasch, so nothing will happen if no keys are pressed.
Normally Input.KeyDown is recommended for handling input. At least take the animation out of the if structure and run it every time, but if no keys are pressed, x will simply remain itself. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
MichaelM
|
Posted: Thu Jun 21, 2007 4:32 pm Post subject: Re: Help with Sprites and Getch |
|
|
thanks, ill try that, but im running Turing 3.1 or something, so Input.KeyDown and stuff might not work, but ill try it out |
|
|
|
|
|
|
|