'Code module
#Region Project Attributes
#ApplicationLabel: B4i Joystick
#Version: 1.0.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait
#iPadOrientations: Portrait
#Target: iPhone
#MinVersion: 9
#PlistExtra: <key>UIViewControllerBasedStatusBarAppearance</key><false/>
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Private GameSize As Size
Private GameView As SKView
Private GameScene As SKScene
Private sprNub As SKSpriteNode
Private sprNubConstraint As SKConstraint
Private newRange As SKRange
Private nubX, nubY As Float
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
NavControl.ShowPage(Page1)
Nav.NavigationBarVisible = False
'hide status bar
Dim no As NativeObject = App
no.RunMethod("setStatusBarHidden:animated:", Array(True, False))
GameView.Initialize("GameView")
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
GameSize.Initialize(Width,Height)
SetUpScene(GameSize)
GameView.PresentScene(GameScene)
Page1.RootPanel.AddView(GameView,0,0,Width,Height)
End Sub
Private Sub SetUpScene(aSize As Size) As SKScene
GameScene.Initialize("GameScene")
GameScene.SceneWithSize(aSize)
GameScene.ScaleMode = GameScene.SKSceneScaleModeAspectFill
GameScene.BackgroundColor=Colors.Black
Dim sprNubTex As SKTexture
sprNubTex.TextureWithImageNamed("redball.png")
nubX = 100
nubY = 100
newRange.Initialize
newRange.RangeWithUpperLimit(100)
sprNubConstraint.Initialize
sprNubConstraint.DistanceToPointInNode(newRange,CreatePoint(nubX,nubY), GameScene)
sprNub.Initialize("sprNub")
sprNub.SpriteNodeWithTexture(sprNubTex)
sprNub.Position=CreatePoint(nubX,nubY)
sprNub.Constraints.Add(sprNubConstraint)
GameScene.AddChild(sprNub)
End Sub
Sub GameScene_ToucheBegan (aTouch As Touch)
End Sub
Sub GameScene_ToucheMoved (aTouch As Touch)
Dim TouchLocation As Point = aTouch.LocationInNode(GameScene)
sprNub.Position = TouchLocation
End Sub
Sub GameScene_ToucheEnded (aTouch As Touch)
Dim ska As SKAction
ska.MoveTo(CreatePoint(nubY,nubX),.3)
sprNub.RunAction(ska)
End Sub
Sub sprNub_TouchBegan (aTouch As Touch)
End Sub
Private Sub Application_Background
End Sub
Sub CreateRange(variancex As Float) As SKRange
Dim aRange As SKRange
aRange.RangeWithConstantValue(variancex)
Return aRange
End Sub
Sub CreatePoint(X As Float, Y As Float) As Point
Dim aPoint As Point
aPoint.Initialize(X,Y)
Return aPoint
End Sub
Sub CreateVector(Dx As Float,Dy As Float) As Vector
Dim aVector As Vector
aVector.Initialize(Dx,Dy)
Return aVector
End Sub
Sub CreateSize(Width As Float, Height As Float) As Size
Dim aSize As Size
aSize.Initialize(Width,Height)
Return aSize
End Sub