Quote: "That is that when it starts to go outside the screen on one side it immediately appears on the other?"
The easiest way in AppGameKit to wrap a sprite around the screen would be to use duplicates of the sprite that are positioned in negative space and update their movement as you update the sprites movement. One for each direction of the screen. This would mean that you would need a total of 4 sprites for every 1 "wrapping" sprite. Alternatively you could just use 2 sprites and calculate the position offset from the other side.
Here's some sample code for the first method (move with the left and right arrow keys):
// Project: WrapScreen
// Created: 2015-08-23
// set window properties
SetWindowTitle( "WrapScreen" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
Global playerId as integer[3]
screenOffset as integer : screenOffset = 0
For i = 0 to 2
playerId[i] = CreateSprite(0)
SetSpriteSize(playerId[i], 20, 20)
if (i = 1)
screenOffset = -GetVirtualWidth()
elseif (i = 2)
screenOffset = GetVirtualWidth()
endif
SetSpritePosition(playerId[i],800 + screenOffset, 500)
Next i
Do
moveX as float : moveX = GetDirectionX()
For i = 0 to 2
SetSpriteX(playerId[i], GetSpriteX(playerId[i]) + moveX * 10)
Next i
Sync()
Loop
Here is some quick sample code I wrote for the second method (move with the left and right arrow keys):
// Project: WrapScreen
// Created: 2015-08-23
// set window properties
SetWindowTitle( "WrapScreen" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
Global playerId as integer[3]
screenOffset as integer : screenOffset = 0
Rem create our two sprites
For i = 0 to 1
playerId[i] = CreateSprite(0)
SetSpriteSize(playerId[i], 20, 20)
SetSpritePosition(playerId[i],800, 500)
Rem make sure the duplicate is invisible
SetSpriteVisible(playerId[i],not i)
Next i
Do
Rem movement for the main sprite
moveX as float : moveX = GetDirectionX()
SetSpriteX(playerId[0], GetSpriteX(playerId[0]) + moveX * 10)
Rem start out with the duplicate inviisible
SetSpriteVisible(playerId[1], 0)
Rem if the player hasn't gone all the way off the right of the screen
if (GetSpriteX(playerId[0]) < GetVirtualWidth())
Rem if the player is partially off the right side of the screen
if (GetSpriteX(playerId[0]) + GetSpriteWidth(playerId[0]) > GetVirtualWidth())
Rem position the duplicate on screen(opposite) by the amount the player is off screen and make the duplicate visible
SetSpriteX(playerId[1], -(GetVirtualWidth() - GetSpriteX(playerId[0])))
SetSpriteVisible(playerId[1], 1)
endif
else
Rem the the main player goes all the way off screen, swap him with the duplicate(which is now on screen)
Rem This was done to make sure that the player sprite stayed consistent
SetSpriteX(playerId[0], GetSpriteX(playerId[1]))
SetSpriteVisible(playerId[1], 0)
endif
Rem if the player hasn't gone all the way off the left of the screen
if (GetSpriteX(playerId[0]) + GetSpriteWidth(playerId[0]) > 0)
Rem if the player is partially off the left side of the screen
if (GetSpriteX(playerId[0]) < 0)
Rem position the duplicate on screen(opposite) by the amount the player is off screen and make the duplicate visible
SetSpriteX(playerId[1], (GetVirtualWidth() + GetSpriteX(playerId[0])))
SetSpriteVisible(playerId[1], 1)
endif
else
Rem the the main player goes all the way off screen, swap him with the duplicate(which is now on screen)
Rem This was done to make sure that the player sprite stayed consistent
SetSpriteX(playerId[0], GetSpriteX(playerId[1]))
SetSpriteVisible(playerId[1], 0)
endif
Sync()
Loop
Sean