B4i Library iSpriteKit- 2D game engine

JanPRO

Well-Known Member
Licensed User
Name: iSpriteKit

Version: 1.0.2

Description: iSpriteKit is a wrapper of Apple's SpriteKit Framework which allows you to create 2D games.

Notes/Tips:
Download "iSpriteKit 1.02.zip": http://bit.ly/2fuueNo

Please report bugs and other things which bothers you (maybe method names, descriptions etc.) to improve this library :)
 
Last edited:

ilan

Expert
Licensed User
iSpriteKit is a huge addition to b4i.

I tried your flappy clone example and it is working great.

Thank you very much @JanPRO :)

(if it is not to much work for you could you maybe put some comments in your flappy clone example?? And maybe use some audio files (background music + sounds)?? Thanks :))
 

strat

Active Member
Licensed User
On my Ipod Touch 5, this library didn't work. OS version is 8.4.1
I opened and tested a new blank project, then, selected only iSprite from Libraries without adding any iSprite component into the Globals., app stopped working.
 

Hypnos

Active Member
Licensed User
Thanks for your great work JanPRO!

I tried your example on iPhone 6 and iPad3, it's working on iPhone but can't start on iPad 3, do you know the reason?
 

JanPRO

Well-Known Member
Licensed User
Hi,
thank you for the feedback :)

@ilan
In the next days I am going to improve the examples.

@strat & @Hypnos
The library uses features that are only supported by iOS 9+.
Hypnos, please check the iOS version on your iPad.

I recommend everbody to add the following line to the project:
B4X:
#MinVersion: 9.0
 

MallyUK

Member
Licensed User
Are constraints working in this version? I've been trying to set a DistanceToPoint constraint (for a virtual joystick) but can't seem to get it to work.
 

JanPRO

Well-Known Member
Licensed User
Hi,
you can use the LocationInNode method of Touch.
Note: the whole GameScene is a SKNode.

B4X:
Sub GameScene_ToucheBegan (aTouch As Touch)
    Dim X As Float = aTouch.LocationInNode(GameScene).X
    Dim Y As Float = aTouch.LocationInNode(GameScene).Y
End Sub
Jan
 

MallyUK

Member
Licensed User
Can you post your code?
I've tried loads of different ways to set a constraint, this is my last attempt.. but I still get an "Object was not initialized (NSArray)" error. I've tried using an array (as the apple docs suggest), a list, and like this.. where am I going wrong? :(

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

MallyUK

Member
Licensed User
Hi,
change this line
B4X:
sprNub.Constraints.Add(sprNubConstraint)
to
B4X:
sprNub.Constraints = Array(sprNubConstraint)
Jan
Eureka! So near and yet so far :) Thank you JanPRO for you assistance, and for this brilliant library!
 

JanPRO

Well-Known Member
Licensed User
Hi,
Yes, it's still a beta, but you can submit an app with iSpriteKit without any problems.
Currently my free time is very limited, but I know I have promised you to update the examples. I will try to do it this week :)

Jan
 

ilan

Expert
Licensed User
Hi @JanPRO
Sorry to ask again but could you find some time to update your examples? (Sound, comments)?

Are you going to release a finished version of your lib or will it stay a beta?

I really want to learn spritekit and make some great ios games but it is very difficult for me to understand your examples.

Thank you , ilan :)
 
Top