WRAP command

Find quick help here to get you started with Hollywood
Post Reply
tolkien
Posts: 194
Joined: Sun Oct 17, 2010 10:40 pm
Location: Spain

WRAP command

Post 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.
jalih
Posts: 280
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: WRAP command

Post 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? ;)
tolkien
Posts: 194
Joined: Sun Oct 17, 2010 10:40 pm
Location: Spain

Re: WRAP command

Post by tolkien »

Thanks very much.
Im going tu rewrite my rutine but you explained it perfectly.
Thanks again jalih.
Post Reply