Web
Analytics
Log In  

0

Does anyone have some advice on how to make a character warp smoothly to the opposite side of the screen? I tried taking a stab at it myself here in my platformer, based off Johannes Richter's game from Picozine #2, and while it's perfectly functional, it looks a little awkward.

Basically I'm looking to have the character appear at the other edge of the screen, but when he falls from the top or walks in from the left, he appears 5 or 6 pixels from the edge, rather than right on the edge of the screen.

I hope what I'm saying makes sense, sorry if it's worded a bit unclearly...

wrap teleport platformer
P#32935 2016-12-02 21:00 ( Edited 2016-12-03 01:01)

::

I haven't checked your code, but from what you're saying, you might have forgotten to allow for the sprite's width & height either when you wrap, or render - sprites are positioned based on the top left corner, which is why things look ok when they move off to the right or bottom, as it's only wrapping around when the top left corner goes offscreen. Not sure what's happening with the extra offset after wrapping around, but it's likely to be related.

Here's a demo that might help:

 -- width & height of the character, from the top left corner
spritewidth, spriteheight = 8,8

-- character position
x,y=7,47

function _update()
x = (x + 0.71) % (128+spritewidth)
y = (y + 0.53) % (128+spriteheight)
end

function _draw()
cls()
spr(0,x-spritewidth,y-spriteheight)
print("x: "..x)
print("y: "..y)
end

Nice game by the way :)

P#32944 2016-12-02 23:04 ( Edited 2016-12-03 00:58)

::

@Catatafish Thank you so much!! That makes sense, it's probably looking for the corner like you mentioned and not the center of the sprite. I'll give it a look and post back if I figure it out! And I'm glad you liked my game so far! :)

P#32945 2016-12-03 00:11

::

Cart [#32946#] | Copy | Code | 2016-12-03 | Link
1

Got it figured out! Took a similar approach to what you suggested, except I used half of the sprite height/width for the offsets. (Had to adjust some of the collisions accordingly)

P#32947 2016-12-03 01:01

Log in to post a comment

user:
password:

New User | Account Help
:: New User
X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2018-07-16 01:16 | 0.282s | 1572k | Q:22