Log In  

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...

P#32935 2016-12-02 21:00 ( Edited 2016-12-03 06: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 05: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 ( Edited 2016-12-03 05:11)
1

Cart #32946 | 2016-12-03 | Code ▽ | Embed ▽ | No License
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 ( Edited 2016-12-03 06:01)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-16 10:18:19 | 0.013s | Q:15