Page 1 of 1
Screen wrapping effect
Posted: Sat Jan 30, 2021 2:26 am
by TheAutomator
Okay, why is this not working on 4 corners of the screen at the same time but only 3?
tr, bl, br, ... no tl?? (tl = top left)
Can't 'wrap' my head around this one:
Code: Select all
If X < 0 : X = #w : EndIf
If X > #w : X = 0 : EndIf
X + vx
If Y < 0 : Y = #h : EndIf
If Y > #h : Y = 0 : EndIf
Y - vy
If X + SpriteWidth(0) > #w
DisplayTransparentSprite(0, X - #w, Y)
EndIf
If Y + SpriteHeight(0) > #h
DisplayTransparentSprite(0, X, Y - #h)
EndIf
DisplayTransparentSprite(0, X, Y)
(#w and #h are window size)
Re: Screen wrapping effect
Posted: Sat Jan 30, 2021 8:52 am
by #NULL
Not sure what you want to do. If you try to prepare a small working code example to show it, then most likely you will find the answer yourself by doing so.

EnableExplicit might also help.
Re: Screen wrapping effect
Posted: Sat Jan 30, 2021 8:58 am
by #NULL
It could be your types aren't right. if Y is an integer and vy is a float of 0.3, then 0.3 will be converted to integer 0.0 before addition, so Y won't change.
Re: Screen wrapping effect
Posted: Sat Jan 30, 2021 11:51 am
by fluent
Have a look at this - Hope it helps
Code: Select all
InitSprite():InitKeyboard()
#W=640 : #H=480
vx = 4 : vy = 4
OpenScreen(#W,#H,32,"PB")
CreateSprite(0,50,50)
StartDrawing(SpriteOutput(0))
Circle(25,25,24,$0033CC)
StopDrawing()
Repeat:FlipBuffers()
ClearScreen(0)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Right)
If X < 0 : X = #w : EndIf
If X > #w : X = 0 : EndIf
X + vx
EndIf
If KeyboardPushed(#PB_Key_Left)
If X < 0 : X = #w : EndIf
If X > #w : X = 0 : EndIf
X - vx
EndIf
If KeyboardPushed(#PB_Key_Up)
If Y < 0 : Y = #h : EndIf
If Y > #h : Y = 0 : EndIf
Y - vy
EndIf
If KeyboardPushed(#PB_Key_Down)
If Y < 0 : Y = #h : EndIf
If Y > #h : Y = 0 : EndIf
Y + vy
EndIf
If X + SpriteWidth(0) > #w
DisplayTransparentSprite(0, X - #w, Y)
EndIf
If Y + SpriteHeight(0) > #h
DisplayTransparentSprite(0, X, Y - #h)
EndIf
DisplayTransparentSprite(0, X, Y)
Until KeyboardPushed(#PB_Key_Escape)
Re: Screen wrapping effect
Posted: Sat Jan 30, 2021 2:05 pm
by TheAutomator
Open the code of fluent, bring the ball to the corner, look at the top left corner, no ball there...
That's what i was talking about :)
Re: Screen wrapping effect
Posted: Sat Jan 30, 2021 2:39 pm
by Mijikai
TheAutomator wrote:Open the code of fluent, bring the ball to the corner, look at the top left corner, no ball there...
That's what i was talking about

You have to render 2 objects for the transition phase.
Re: Screen wrapping effect
Posted: Sat Jan 30, 2021 3:43 pm
by fluent
Fixed
Code: Select all
InitSprite():InitKeyboard()
#W=640 : #H=480
vx = 2 : vy = 2
OpenScreen(#W,#H,32,"PB")
CreateSprite(0,50,50)
StartDrawing(SpriteOutput(0))
Circle(25,25,24,$CC7755)
StopDrawing()
Repeat:FlipBuffers()
ClearScreen(0)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Right)
If X < 0 : X = #w : EndIf
If X > #w : X = 0 : EndIf
X + vx
EndIf
If KeyboardPushed(#PB_Key_Left)
If X < 0 : X = #w : EndIf
If X > #w : X = 0 : EndIf
X - vx
EndIf
If KeyboardPushed(#PB_Key_Up)
If Y < 0 : Y = #h : EndIf
If Y > #h : Y = 0 : EndIf
Y - vy
EndIf
If KeyboardPushed(#PB_Key_Down)
If Y < 0 : Y = #h : EndIf
If Y > #h : Y = 0 : EndIf
Y + vy
EndIf
If X + SpriteWidth(0) > #w
DisplayTransparentSprite(0, X - #w, Y)
EndIf
If Y + SpriteHeight(0) > #h
DisplayTransparentSprite(0, X, Y - #h)
EndIf
If X + SpriteWidth(0) > #w and Y + SpriteHeight(0) > #h
DisplayTransparentSprite(0, X - #w, Y - #h)
EndIf
DisplayTransparentSprite(0, X, Y)
Until KeyboardPushed(#PB_Key_Escape)
Re: Screen wrapping effect
Posted: Sat Jan 30, 2021 4:30 pm
by TheAutomator
Code: Select all
If Y + SpriteHeight(0) > #h
DisplayTransparentSprite(0, X, Y - #h)
EndIf
If X + SpriteWidth(0) > #w ; <------- good enough
DisplayTransparentSprite(0, X - #w, Y - #h)
DisplayTransparentSprite(0, X - #w, Y)
EndIf
DisplayTransparentSprite(0, X, Y)
This seems to work fine on it's own too :)
Not sure if this is the way but it works for now, thanks!
Re: Screen wrapping effect
Posted: Sun Jan 31, 2021 8:18 am
by fluent
I've simplified the code even more.
In fact we can get rid of those IF statements, turns out they are not needed at all!
Code: Select all
InitSprite():InitKeyboard()
#W=640 : #H=480
vx = 2 : vy = 2
OpenScreen(#W,#H,32,"PB")
CreateSprite(0,50,50)
StartDrawing(SpriteOutput(0))
Circle(25,25,24,$CC7755)
StopDrawing()
Repeat:FlipBuffers()
ClearScreen(0)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Right)
X + vx
If X >= #w : X = 0 : EndIf
EndIf
If KeyboardPushed(#PB_Key_Left)
X - vx
If X <= 0 : X = #w : EndIf
EndIf
If KeyboardPushed(#PB_Key_Up)
Y - vy
If Y <= 0 : Y = #h : EndIf
EndIf
If KeyboardPushed(#PB_Key_Down)
Y + vy
If Y >= #h : Y = 0 : EndIf
EndIf
DisplayTransparentSprite(0, X - #w, Y)
DisplayTransparentSprite(0, X, Y - #h)
DisplayTransparentSprite(0, X - #w, Y - #h)
DisplayTransparentSprite(0, X, Y)
Until KeyboardPushed(#PB_Key_Escape)
Re: Screen wrapping effect
Posted: Sun Jan 31, 2021 5:16 pm
by TheAutomator
fluent wrote:I've simplified the code even more.
In fact we can get rid of those IF statements, turns out they are not needed at all!
yeah but isn't that unnecessary work for the computer while the ship isn't required to be drawn on the sides?
edit: that was stupid of me, then we would fall back on
If X + SpriteWidth(0) > #w and Y + SpriteHeight(0) > #h...