iOS Question Multi-touch in Sprite Kit

Space

Member
Licensed User
Hi,

I have no plan how to identify multiple finger touch events.

I can recognize a single touch:

Code:
Sub GameScene_ToucheBegan (aTouch As Touch)
    Log( "start  "&aTouch )
End Sub

atouch is a single click. But what if I touch the screen with two fingers?

I found this in the apple documentation:
Code:
   override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
      for touch in touches {
         createViewForTouch(touch: touch)
      }
   }


Touches is handed over which is a list.
But in b4i spritekit only one touch is passed?

I'm stuck again

thanks
 

Space

Member
Licensed User
Small example uploaded.

I tried multitouch with spritekit and normal touch events.

Both negative results
 

Attachments

  • test.zip
    3.2 KB · Views: 134
Upvote 0

Space

Member
Licensed User
OK. Have now tried a lot, poked in the dark but found no solution.
Apparently multitouch really doesn't work from SpriteKit.
(What I find a bit strange, it would have been better to leave out input right away. I only know really simple games that don't need multitouch at all)

So I found
https://www.b4x.com/android/forum/threads/multitouch-event.87027/#content
where Erel presents a multi-touch solution

His project works for me.
But when I try to integrate it into my SpriteKit project, unfortunately it doesn't work.

B4X:
Sub Process_Globals
    Public App As Application
    Public NavControl As NavigationController
    
    Private xui As XUI
    
    Private page1 As Page
    
    Private gameSize As Size
    Private gameView As SKView
    Private gameScene As SKScene
    
    Private Panel1 As Panel
    Private cvs As B4XCanvas
End Sub


Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    NavControl.ToolBarVisible = False
    NavControl.NavigationBarVisible = False
    
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(NavControl)
    
    gameView.Initialize("GameView")
    gameView.ShowsFPS = True
    gameView.ShowsNodeCount = True

    page1.Initialize("Page1")
    Nav.ShowPage(page1)
    Nav.NavigationBarVisible = False
    Panel1.Initialize("Panel1")
    
    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


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


Sub SetUpScene(aSize As Size) As SKScene
    gameScene.Initialize("GameScene")
    gameScene.SceneWithSize(aSize)
    gameScene.ScaleMode = gameScene.SKSceneScaleModeAspectFill
    Return gameScene
End Sub


Sub GameScene_Update (CurrentTime As Int)
    Log("running")
End Sub


Sub Panel1_Resize (Width As Float, Height As Float)
    cvs.Resize(Width, Height)
End Sub


Private Sub Panel1_MultiTouchBegan(touches As Object) As Boolean
    Log("****** touch began")
    Return True
End Sub

Private Sub Panel1_MultiTouchMoved(touches As Object) As Boolean
    Log("****** touch moved")
    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

Please if anyone could show me the error.
I've already wasted days with it to get something as simple as multitouch.
This can not be.

Please
 
Upvote 0

Space

Member
Licensed User
Unfortunately it still doesn't work. Now either SpriteKit content is displayed, or multitouch works.

Switch between with line 109 (marked with ******)

So now I just need to know how to get Panel1, which is responsible for multi-touch, to be transparent.

B4X:
'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
 

Attachments

  • anothertest.zip
    5.1 KB · Views: 112
Upvote 0
Top