'Code module
#Region Project Attributes
#ApplicationLabel: MyTemplate
#Version: 1.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait
#iPadOrientations: Portrait
#Target: iPhone, iPad
#ATSEnabled: True
#MinVersion: 8
#PlistExtra:<key>UIStatusBarStyle</key><string>UIStatusBarStyleLightContent</string>
#PlistExtra: <key>GADIsAdManagerApp</key><true/>
#End Region
Sub Process_Globals
Public App As Application
Public NavControl As NavigationController
Private xui As XUI
Private page1 As Page
Private Panel1 As Panel
Private cvs As B4XCanvas
Private gameSize As Size
Private gameView As SKView
Private gameScene As SKScene
Private pacmantex As SKTexture
Dim pacman As SKSpriteNode
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
NavControl.ToolBarVisible = False
NavControl.NavigationBarVisible = False
gameView.Initialize("GameView")
gameView.ShowsFPS = True
gameView.ShowsNodeCount = True
Dim PagesManager As B4XPagesManager
PagesManager.Initialize(NavControl)
page1.Initialize("Page1")
page1.RootPanel.LoadLayout("1")
Nav.ShowPage(page1)
Nav.NavigationBarVisible = False
cvs.Initialize(Panel1)
Dim no As NativeObject = Panel1
no.SetField("multipleTouchEnabled", True)
End Sub
#Region Delegates
Private Sub Application_Background
B4XPages.Delegate.Activity_Pause
End Sub
Private Sub Application_Foreground
B4XPages.Delegate.Activity_Resume
End Sub
#End Region
Sub SetUpScene(aSize As Size) As SKScene
gameScene.Initialize("GameScene")
gameScene.SceneWithSize(aSize)
gameScene.ScaleMode = gameScene.SKSceneScaleModeAspectFill
pacmantex.Initialize
pacmantex.TextureWithImageNamed("pacman.png")
pacmantex.FilteringMode = pacmantex.SKTextureFilteringNearest
Return gameScene
End Sub
Sub GameScene_Update (CurrentTime As Int)
gameScene.RemoveAllChildren
pacman.Initialize("spex")
pacman.SpriteNodeWithTexture(pacmantex)
pacman.SetScale(1)
pacman.Position = CreatePoint( 200,200 )
gameScene.AddChild(pacman)
End Sub
Sub CreatePoint(X As Float, Y As Float) As Point
Dim aPoint As Point
aPoint.Initialize(X,Y)
Return aPoint
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
Log( "Viewportsize: "&Width&" "&Height)
gameSize.Initialize(Width,Height)
SetUpScene(gameSize)
gameView.PresentScene(gameScene)
page1.RootPanel.AddView(gameView,0,0,Width,Height)
Panel1.Width = Width
Panel1.Height = Height
Panel1.BringToFront '***********************************
End Sub
Private Sub Panel1_MultiTouchBegan(touches As Object) As Boolean
Log("****** touch began")
Return True
End Sub
Private Sub Panel1_MultiTouchEnded(touches As Object) As Boolean
Log( "****** touch ended" )
Return True
End Sub
#if OBJC
- (NSArray*)UITouchToPoint:(UITouch*)t :(UIView*)view {
CGPoint p = [t locationInView:view];
return @[@(p.x), @(p.y)];
}
@end
@implementation B4IPanelView (override)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if ([B4IObjectWrapper raiseEvent:self :@"_multitouchbegan:" :@[[touches allObjects]]] == false)
[super touchesMoved:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if ([B4IObjectWrapper raiseEvent:self :@"_multitouchmoved:" :@[[touches allObjects]]] == false)
[super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ([B4IObjectWrapper raiseEvent:self :@"_multitouchended:" :@[[touches allObjects]]] == false)
[super touchesMoved:touches withEvent:event];
}
#End If