Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / 2D Movement/Screen help

Author
Message
Beyond the Humans Knowledge
15
Years of Service
User Offline
Joined: 27th Oct 2010
Location:
Posted: 25th Dec 2010 04:14
I have this for now, real simple code. I cant figure out how to make it to where if my sprite touches the edge of the screen, he stops.

load image "floor.png",2
x#=0
y#=0
box 10,10,10,10,rgb(255,0,0),rgb(255,0,0),rgb(255,0,0),rgb(255,0,0),
do
sprite 2,50,50,2
sprite 1,x#,y#,1
if keystate(200)=1 then dec y#,1
if keystate(208)=1 then inc y#,1
if keystate(205)=1 then inc x#,1
if keystate(203)=1 then dec x#,1
if y# => 0
keystate(200)=0
endif


sync
loop


I tried using

[/code]
if y# > screen height then keystate(200) = 0
[code]

but with no hope, he doesnt stop.

btw, my sprite is a tile and
200 = up
208 = down
203 = left
205 = right

onhcet d(-_-)b techno
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 25th Dec 2010 05:55 Edited at: 25th Dec 2010 05:58
Use the 'Edit Post' to get your code above inside a code tag
I see you tried to, it's almost right, take a minute to do that please.
-code-
program
-/code-
replacing - dashes above with [ ] square brackets

In your program...keystate(200)=0 doesn't work, it only works with an 'IF' statement, such as if keystate(200)=0 then...
now...try this code to limit your sprite to the screen edges

Login to post a reply

Server time is: 2026-07-21 20:36:24
Your offset time is: 2026-07-21 20:36:24