Screen wrapping effect

Advanced game related topics
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Screen wrapping effect

Post 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)
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Screen wrapping effect

Post 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. :wink: EnableExplicit might also help.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Screen wrapping effect

Post 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.
fluent
User
User
Posts: 68
Joined: Sun Jan 24, 2021 10:57 am

Re: Screen wrapping effect

Post 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)
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: Screen wrapping effect

Post 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 :)
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Screen wrapping effect

Post 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.
fluent
User
User
Posts: 68
Joined: Sun Jan 24, 2021 10:57 am

Re: Screen wrapping effect

Post 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)
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: Screen wrapping effect

Post 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!
fluent
User
User
Posts: 68
Joined: Sun Jan 24, 2021 10:57 am

Re: Screen wrapping effect

Post 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)
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: Screen wrapping effect

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