If it helps, i've started the code off like so:
SetWindowTitle( "movement" )
SetWindowSize( screenW, screenH, 0 )
screenW = 1366
screenH = 768
// set display properties
SetVirtualResolution( screenW, screenH )
SetOrientationAllowed( 1, 1, 1, 1 )
LoadImage(1,"ball.png")
ball = createsprite(1)
speed = 20
do
setspriteposition(ball, x, y)
x=x+GetDirectionX()*speed
y=y+GetDirectionY()*speed
First time using the Code button, so hope that came out right lol. Now i'm about to do those 'if' statements. That's where i'm struggling.
The above code is different to the original, i decided to start again.
EDIT - Ok, so if i hold the RIGHT arrow key down, for lets say 4 seconds. The ball stays still throughout, but when i come to reverse the direction, then ball sticks for those same 4 seconds before moving, so somehow, i'm still going yet the ball's stationary? Hope you understand what i mean.
EDIT again: Ok, so looks like Mike's code was correct. First time i tried it, the ball would just stick forever, but now for some reason it works. I used the following code:
if getspritex(ball) > screenW
setspritex(ball,screenW)
x = screenW
endif
If you see anything wrong with the code, let me know, and thanks again guys. Unsure why it didn't work the first time Mike, but since i've restarted i now get the desired results!
EDIT = Somehow the ball no longer has any window boundries and just exits the screen lol. I really shouldn't take breaks. Going to re-read about window size, and virtual resolutions, as that's where the problems coming from now.
It works, how i want it to work with the following code:
SetWindowTitle( "movement" )
SetWindowSize( 1366, 768, 0 )
screenW = 1366
screenH = 768
// set display properties
SetVirtualResolution( screenW, screenH)
SetOrientationAllowed( 1, 1, 1, 1 )
LoadImage(1,"ball.png")
ball = createsprite(1)
speed = 10
do
setspriteposition(ball, x, y)
x=x+GetDirectionX()*speed
y=y+GetDirectionY()*speed
if getspritex(ball) > 1300
setspritex(ball, 1300)
x = 1300
endif
if getspritex(ball) < 0
setspritex(ball, 0)
x=0
endif
if getspritey(ball) > 700
setspritey(ball, 700)
y = 700
endif
if getspritey(ball) < 0
setspritey(ball, 0)
y=0
endif
Question is; Why do i have to type in the actual numbers? I.e. if getspritex(ball) > 700 instead of: if getspritex(ball) > screenW. If i put in 'ScreenW' the ball has no boundry. Glad i sorted out the delay though, cause that was giving me a headache (Thanks again Mike)
Khadin