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.

Newcomers DBPro Corner / making a sprite move slower

Author
Message
Chaosmatt
12
Years of Service
User Offline
Joined: 3rd May 2012
Location:
Posted: 7th Dec 2016 18:30
do
sprite 317,x1,y1,10
if keystate(200) then y1=y1-1
if keystate(208) then y1=y1+1
if keystate(203) then x1=x1-1
if keystate(205) then x1=x1+1

loop

above is the controls I have set up and yes that is sprite number 317! Haha I've used 316 to cover the background.
Anyway back to the question, in relation to the above code, how can I make my players sprite move slower, I have tried 0.1 etc but this causes the code to stop working.
It may be a very simply thing to fix but with my very basic knowledge I am stumped

Thanks in advanced
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 7th Dec 2016 22:17 Edited at: 7th Dec 2016 22:49
The sprite functions x and y parameters are integers. One possible solution is to make the variables x1 and y1 float and pass them to the Sprite function as integers.

do
sprite 317, int(x1#), int(y1#), 10
if keystate(200) then y1#=y1#-0.1
if keystate(208) then y1#=y1#+0.1
if keystate(203) then x1#=x1#-0.1
if keystate(205) then x1#=x1#+0.1
loop
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 15th Dec 2016 14:27 Edited at: 15th Dec 2016 14:30
Another way you could do it is to put in a timer() based delay, like this:



or you could simply put in a wait 10 command. Still another way would be to set a SYNC rate that is slower. It appears that you are running without manually SYNCing, so it would default to 0, which is as fast as the host computer can run it. Here is an example of manually syncing:




So many games to code.....so little time.
Chaosmatt
12
Years of Service
User Offline
Joined: 3rd May 2012
Location:
Posted: 15th Dec 2016 18:46
Thank you both for the replies,

I actually implemented WICKEDX's suggestion first as it happened to be the first reply and it did fix the issue, I am now able to make smaller changes, however the problem I am now having is that the code I was using to make sure the player sprite remained on the screen is now not working and I don't understand why, this is the code I had for it

if x1#=0 then inc x1#,1
if x1#=325 then dec x1#,1
if y1#=0 then inc y1#,1
if y1#=199 then dec y1#,1

could someone explain why that not isn't working any more............

also something I cannot figure out is how to create an inventory system,
Any help on that one?
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 16th Dec 2016 01:53
My reply was just based on the code you provided. Sorry, my head hasn't been in the game as of late.
You should go with a combination of what LBFN suggested. Use timer based movement synchronously with a sync rate of zero. This snippet also will prevent the sprite from going off screen.

Login to post a reply

Server time is: 2024-11-21 09:20:38
Your offset time is: 2024-11-21 09:20:38