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.

2D All the way! / Problem with controlling my sprite

Author
Message
JoeCory
9
Years of Service
User Offline
Joined: 19th Sep 2014
Location:
Posted: 20th Sep 2014 00:02 Edited at: 22nd Sep 2014 19:03
hi, not sure i this is the right section but i got a problem with my 2D sprite.

i am able to move the sprite but when the x or y co-ord gets to 360 it will reset to 0 and keep moving...

anyone got any idea why this is happening

code below (bad but im new to Db)



MOD EDIT: Better to use code tags.

thanks guys
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Sep 2014 19:04
When you use WRAPVALUE, it wraps around 360 degrees - it's only intended for angles that one.

I am the one who knocks...
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 24th Sep 2014 20:07
Hi, Joe, as VanB said you don't want to be using WRAPVALUE so change you're controls to something like:

if rightkey() = 1 then xpos = xpos + 1

use this format for all the controls / movement and then after the controls / movement code add:

if xpos < 0 then xpos = 0
if xpos > 100 then xpos = 100

I've used 0 and 100 but put your own limits in. Do this for ypos and this should limit the position of the sprite.

Login to post a reply

Server time is: 2024-04-18 22:29:19
Your offset time is: 2024-04-18 22:29:19