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...
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 :)
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)
Log in to post a comment