Page 1 of 1

WRAP command

Posted: Wed Oct 05, 2011 11:06 pm
by tolkien
Hello.
I´m trying to do a simple task with tables.
I have a table with sinus values.
Then I assign a value of that table to a group o chars to can move them.
Until here it,s all ok but along I´m through the table there are a moment it finish and i cant restart it correctly.

I suppose that I have to use the WRAP command but i dont understat it very well.

Any help?

Thanks.

Re: WRAP command

Posted: Thu Oct 06, 2011 12:20 am
by jalih
How about a little example:

Say you have an 320x200 screen and want your game object to be able wrap out from other side of the screen, when going off the screen boundaries:

You can just do something like this to your game objects x and y coordinates:

Code: Select all

x = x + dx  ; update x position
x = Wrap(x, 0, 320)  ; keep within screen boundaries, wrap to other side if necessary

y = y + dy  ; update y position
y = Wrap(y, 0, 200)  ; keep within screen boundaries, wrap to other side if necessary
We really don't need to use Wrap() function at all, a little bit of math gives us:

Code: Select all

x = x + dx  ; update x position
x = (x + 320) % 320   ; keep within screen boundaries, wrap to other side if necessary

y = y + dy  ; update y position
y = (y + 200) % 200   ; keep within screen boundaries, wrap to other side if necessary
Does this example help at all? ;)

Re: WRAP command

Posted: Thu Oct 06, 2011 7:04 am
by tolkien
Thanks very much.
Im going tu rewrite my rutine but you explained it perfectly.
Thanks again jalih.