B4i Library iSpriteKit- 2D game engine

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:

JanPRO

Well-Known Member
Licensed User

ilan

Expert
Licensed User
hi @JanPRO

i have question please, i would like to add some particles to my game and i see that the right way to do it is using SKEmitterNode.

all tutorials i see in the net require a function "fileNamed"
unfortunately, iSpritekit for b4i does not have such a function for a SKEmitterNode.

what should i use instead?

https://developer.apple.com/documentation/spritekit/skemitternode

i have a *.sks file that i would like to run on my project but how do i connect it to my SKEmitterNode.?

thank you :)

my code:

B4X:
Sub runExplosion(myscene As SKScene, position As Point)
    Dim explosion As SKEmitterNode
    explosion.Initialize("")
    explosion. ??? ("Explosion")
    explosion.Position = position
    myscene.AddChild(explosion)
 
    Sleep(2000)
    explosion.RemoveFromParent
End Sub

(i am including the sks file so you can test it)
 

Attachments

  • Explosion.zip
    2.5 KB · Views: 5

JanPRO

Well-Known Member
Licensed User
Hi,

the fileNamed function is only available in Swift, for Objective-c you have to use a
NSKeyedUnarchiver. Please try the following code (untested, as I am not at home):

B4X:
Sub EmitterNodeWithFile(Dir As String, Name As String) As SKEmitterNode
    Dim NaObj As NativeObject
    Return NaObj.Initialize("NSKeyedUnarchiver").RunMethod("unarchiveObjectWithFile:",File.Combine(Dir,Name))
End Sub

Jan
 

ilan

Expert
Licensed User
Hi,

the fileNamed function is only available in Swift, for Objective-c you have to use a
NSKeyedUnarchiver. Please try the following code (untested, as I am not at home):

B4X:
Sub EmitterNodeWithFile(Dir As String, Name As String) As SKEmitterNode
    Dim NaObj As NativeObject
    Return NaObj.Initialize("NSKeyedUnarchiver").RunMethod("unarchiveObjectWithFile:",File.Combine(Dir,Name))
End Sub

Jan

thanx a lot Jan, the code worked almost i had to put a very small change but now it works.


B4X:
Sub runExplosion(myscene As SKScene, position As Point)
    Dim explosion As SKEmitterNode = EmitterNodeWithFile(File.DirAssets,"Explosion.sks")
    explosion.Position = position
    explosion.SetScale(0.02)
    myscene.AddChild(explosion)
    Sleep(2000)
    explosion.RemoveFromParent
End Sub

Sub EmitterNodeWithFile(Dir As String, Name As String) As SKEmitterNode
    Dim skEmitter As SKEmitterNode
    skEmitter.Initialize("")
    Dim NaObj As NativeObject
    skEmitter = NaObj.Initialize("NSKeyedUnarchiver").RunMethod("unarchiveObjectWithFile:",Array(File.Combine(Dir,Name)))
    Return skEmitter
End Sub

we call it like this:

B4X:
runExplosion(GameScene,aTouch.LocationInNode(GameScene))

thank you very much, it's great to have an objective c expert like you on this forum :)

Btw: Xcode has a very nice Particles creator tool and because i own a mac mini i can do really cool particles with it like smoke, fire, explosion,... and just export to an sks file and use it on my b4i project. :)
 

ilan

Expert
Licensed User
hi @JanPRO

i am not able to build my iSpriteKit projects with b4i 4.3

i am getting: ld: warning: ignoring file ../../Libs/libiSpriteKit.a, missing required architecture x86_64

can you maybe fix it so i can also run it on b4i 4.3?

(with b4i 4.01 its working fine)

thank you
 

ilan

Expert
Licensed User

JanPRO

Well-Known Member
Licensed User
Hi,
at some point I will definitely add TileMapNodes to SpriteKit. As I already said, iOS 10 support TileMaps. However, it's not possible to load tmx files, so currently you depend on Xcode's Tile Map Editor. There are some experimental libraries which create a TileMapNode from a tmx file, probably in the future there will be better support of Tiled for SpriteKit (at least I hope so).

I really appreciate your interest and help and look forward to your module :)

Jan
 

ilan

Expert
Licensed User
Hallo @JanPRO, any chance you will update iSpritekit to enable multi-Touch?

i tried to add 2 sknodes and use them as buttons but they won't work together. i can only click on 1 of them at a time, for example, click on a button like the run button and then while holding the run button click on the jump button the player won't jump because the touch event of the jump button won't fire UNTIL i release the run button. they work perfectly separately but not simultaneously.

i saw in some tutorials that they are doing it like this:

B4X:
for touch in touches
{

}

but now it seems that you only catch the first touch and to create more complex games like platformers we must have a multitouch option.

thank you very much, ilan :)

Edit: game i am working on (https://www.b4x.com/android/forum/threads/working-on-a-new-game-ios.88908/)
 
Last edited:

ilan

Expert
Licensed User
Last edited:

ilan

Expert
Licensed User
Hello @JanPRO. i see that SpriteKit - SkScene supports multitouch. Can we also make our SKScene Multitouch in b4i?

link: https://stackoverflow.com/questions/31501983/ios-9-xcode-7-multitouch-with-spritekit

B4X:
-(void)didMoveToView:(SKView *)view {
    self.view.multipleTouchEnabled = YES;
}

i tried like this but no luck:

B4X:
    GameScene.View.Initialize("gamesceneView")
    Dim no As NativeObject = GameScene.View
    no.RunMethod("multipleTouchEnabled",Array("YES"))

i get error that the skview is not initialized.

thanx, ilan
 
Last edited:

ilan

Expert
Licensed User
Hello @JanPRO

it has been a long time since iSpritekit was talked about but i had to update some of my iSpritekit games and i came across an error.
i try to use the SKNode Userdata Object that is a Map but i always get an error that the object is not initialized even if i try to initialize it i get the same error.

How can we use the UserData object of the Sknode?

thank you, ilan
 

ilan

Expert
Licensed User

cxbs

Member
Licensed User
ok found the answer: https://stackoverflow.com/questions/36323490/saving-and-reading-information-from-a-sprites-userdata

B4X:
ground.UserData = CreateMap("trap":"fallGround")

anyway, any plans to update the Library?

Dear Mr. Ilan
I often see your articles in the forum. Obviously, you are a game development expert
Have you ever developed b4i games using OpenGL,
I want to use [gl_triangles] to draw a triangle gradient fill and display it,
But it has not been successful. It seems that there are few articles on this topic in the forum,
I'm looking forward to the release of libgdx version b4i
If you have any suggestions in this regard, can you tell me? Thank you very much!
The above English comes from translation software!
 

ilan

Expert
Licensed User
Dear Mr. Ilan
I often see your articles in the forum. Obviously, you are a game development expert
Have you ever developed b4i games using OpenGL,
I want to use [gl_triangles] to draw a triangle gradient fill and display it,
But it has not been successful. It seems that there are few articles on this topic in the forum,
I'm looking forward to the release of libgdx version b4i
If you have any suggestions in this regard, can you tell me? Thank you very much!
The above English comes from translation software!

hi @cxbs

it is better if you open a new thread and we can discuss it there.

regards, ilan
 
Top