newbie question...

Blitz3D Forums/Blitz3D Beginners Area/newbie question...

ngi(Posted 2004) [#1]
well this might seem like a very newbie question... but I just started 2 days ago with some book I bought.

Graphics 300,400,0,2

Type luis
Field x,y
Field image
Field dirx
End Type


Global player.luis = New luis
player\image = LoadImage ("pingui.bmp")
ScaleImage player\image,.20,.20
While Not KeyDown(1)
Cls
DrawImage player\image,player\x,player\y
testpingui()
player\x = player\x + player\dirx
Flip
Wend

Function testpingui()
player\x = 100
player\y = 100
player\dirx = Rand (-1,1)
If player\x < 0 Or player\x > 290
player\dirx = -player\dirx
EndIf
End Function


All i want is to make this image move right and left , and when it gets out of screen , reverse direction, but all i get is the image shaking or something , whats up with that!!! any help plz.


N(Posted 2004) [#2]
I think the "player\dirx = Rand (-1,1)" is the reason. You're calling this every loop, so the direction is getting reset every frame, which would cause shaking (assuming the random number didn't somehow turn up 1 the whole time).


Shambler(Posted 2004) [#3]
Ok here is a working version with as little alteration as possible

Graphics 300,400,0,2 

Type luis 
Field x,y 
Field image 
Field dirx 
End Type 


Global player.luis = New luis 
player\image = LoadImage ("pingui.bmp") 
ScaleImage player\image,.20,.20 
;position pingui and set the start direction here
player\x = 100 
player\y = 100 
player\dirx = 1 

While Not KeyDown(1) 
Cls 
DrawImage player\image,player\x,player\y 
testpingui() 
player\x = player\x + player\dirx 
Flip 
Wend 

Function testpingui() 
If player\x < 0 Or player\x > 290 
player\dirx = -player\dirx 
EndIf 
End Function 


Note that Rand(-1,1) might have returned 0 and so resulted in no movement at all.


PowerPC603(Posted 2004) [#4]
You also forgot to set the BackBuffer.

Enter this below the Graphics command:

SetBuffer BackBuffer()


Ross C(Posted 2004) [#5]
Could be using BlitzPlus, which doesn't require to set it...i think :)


ngi(Posted 2004) [#6]
thx !=)