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
Longtime User
Hi,

the examples haven't been updated yet.
Are you going to release a finished version of your lib or will it stay a beta?
For now it will stay in beta as I can't guarantee that there are no bugs anymore. Moreover before releasing, there will be probabaly a small update which adjusts iSpriteKit to the new features in the SpriteKit framework brought with iOS 10.

If you have specific questions or problems, you can always post a question in the questions section and I will try to help you.

Jan
 

ilan

Expert
Licensed User
Longtime User
Thanx @JanPRO . I really want to learn spritkit. i started learn yesterday a little bit and i think i can do a simple pong game with it. So i will try it in the next days and if i am stuck i will ask in the question forum

Thank you very much, ilan :)
 

ilan

Expert
Licensed User
Longtime User
hi @JanPRO, i think i found a bug.

when i use GameScene_DidEndContact event i get an error when 2 bodies collide.

Application_Start
Application_Active
leaved body
Error occurred on line: 367 (Main)
Method not found: BodyA, target: <PKPhysicsContact: 0x14693d70>
Stack Trace: (
CoreFoundation <redacted> + 152
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
Pong! +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 420
Pong! -[B4IShell runMethod:] + 574
Pong! -[B4IShell raiseEventImpl:method:args::] + 1998
Pong! -[B4IShellBI raiseEvent:event:params:] + 1442
Pong! +[B4IObjectWrapper raiseEvent:::] + 220
Pong! -[SScene didEndContact:] + 694
PhysicsKit <redacted> + 436
PhysicsKit <redacted> + 300
SpriteKit <redacted> + 3110
SpriteKit <redacted> + 1084
SpriteKit <redacted> + 302
SpriteKit <redacted> + 632
SpriteKit <redacted> + 268
SpriteKit <redacted> + 240
QuartzCore <redacted> + 112
QuartzCore <redacted> + 608
IOMobileFramebuffer <redacted> + 88
IOKit IODispatchCalloutFromCFMessage + 236
CoreFoundation <redacted> + 128
CoreFoundation <redacted> + 34
CoreFoundation <redacted> + 338
CoreFoundation <redacted> + 994
CoreFoundation CFRunLoopRunSpecific + 470
CoreFoundation CFRunLoopRunInMode + 104
GraphicsServices GSEventRunModal + 80
UIKit UIApplicationMain + 150
Pong! main + 106
libdyld.dylib <redacted> + 2
)

Method not found: BodyA, target: <PKPhysicsContact: 0x14693d70>

is it a typo error in the lib? PKPhysicsContact instead of SKPhysicsContact ??
 

ilan

Expert
Licensed User
Longtime User
hi again

i think there is another issue.

if i set the SKSpritenode -> SpriteNodeWithColor then tapping on it will not trigger the SKscene TouchBegan event.
setting it as SpriteNodeWithImageNamed will trigger the Skscene TouchBegan event.

you can also try it out on your Breakout example.
just change the paddle sprite settings to this:

B4X:
Paddle.SpriteNodeWithColor(Colors.White, CreateSize(120,45))' .SpriteNodeWithImageNamed("paddle")

after doing this you will not be able to move the paddle anymore.
 

sorex

Expert
Licensed User
Longtime User
Do I need to do something special to make the iSpriteKit library appear in B4i when using hosted builder?


Edit: It's ok, I had 2 additional library folders and copied the files into the wrong one :)
 

sorex

Expert
Licensed User
Longtime User
Jan,

Do you have any example lying around on how we can copy part of an image to a sprite node. I can only seem to get the entire texture in my sprite.
If this is only possible with a textureatlas then how are we supposed to work with it?


By the way... how do you define the size of a sprite in the scene?
I only see a .setscale option. Is the point of all this to work with images in their size as-is and is you want them twice as big you set the scale?
so there's no real .width .height as we're used to.
 

ilan

Expert
Licensed User
Longtime User
hi again.

i have a small question please.
if i want to set the CollisionBitMask to more then 2 Collisionsgroup how do i do that?

if native language i just separate the groups with | like this:

redBall.physicsBody?.collisionBitMask =RedBallCategory|GreenBallCategory|WallCategory//Collision will occur when RedBall meets RedBall, GreenBall or hits a Wall

but in your flappybird example you use Bit.Or(x,x) but with Bit.Or i can set only 2 groups.
any idea how i can do it with more then 2?

thanx
 

sorex

Expert
Licensed User
Longtime User
you can do multiple ORs

whatever=bit.or(bit.or(x,y),z)

or

whatever=x+y+z

which does the same thing if the bits are not used before in the values which is the case since you use single bit mask values
 

ilan

Expert
Licensed User
Longtime User
you can do multiple ORs

whatever=bit.or(bit.or(x,y),z)

or

whatever=x+y+z

which does the same thing if the bits are not used before in the values which is the case since you use single bit mask values

yes i already found out that i had just to add all values together. i cant say that i understand why it is working like this since i dont understand fully how the bit stuff works but as long as it works its good for me.
 

sorex

Expert
Licensed User
Longtime User
it's simple

see OR as SET bit(s) (and AND as GET bit(s))

you have those bit.left values you mentioned which creates

00000001 'player
00000010 'enemy
00000100 'wall

if you add (+) bit 0 & 2 it it will become

00000101

which is the same as the OR method

but if your value already contains that 3rd bit (bit2) it will move bits since the value changes due to the addition

00000100
00000100 + (4+4=8)
00001000 =

with OR it remains the same since the bit has already been set

00000100
00000100 OR (4+0=4)
00000100 =
 

ilan

Expert
Licensed User
Longtime User
hi,

i getting another crash when i try to create a FixedJoint or a PinJoint

Application_Start
19:07
Application_Active
screensize: 736:414
clicked pn play button
Error occurred on line: 792 (Main)
Expected: SKPhysicsJointFixed, object type: PKPhysicsJointWeld
Stack Trace: (
CoreFoundation __exceptionPreprocess + 189
libobjc.A.dylib objc_exception_throw + 49
CoreFoundation +[NSException raise:format:] + 104
2D Physics -[B4IObjectWrapper setObject:] + 292
2D Physics -[SPhysicsJointFixed Initialize] + 113
CoreFoundation __invoking___ + 29
CoreFoundation -[NSInvocation invoke] + 321
2D Physics +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1842
2D Physics -[B4IShell runVoidMethod] + 277
2D Physics -[B4IShell raiseEventImpl:method:args::] + 2419
2D Physics -[B4IShellBI raiseEvent:event:params:] + 1623
2D Physics +[B4IObjectWrapper raiseEvent:::] + 309
2D Physics -[SpriteNodeHelper touchesBegan:withEvent:] + 397
SpriteKit -[SKView touchesBegan:withEvent:] + 1038
2D Physics -[ViewHelper touchesBegan:withEvent:] + 139
UIKit -[UIWindow _sendTouchesForEvent:] + 2333
UIKit -[UIWindow sendEvent:] + 4445
UIKit -[UIApplication sendEvent:] + 363
UIKit __dispatchPreprocessedEventFromEventQueue + 2973
UIKit __handleEventQueue + 1255
UIKit __handleHIDEventFetcherDrain + 66
CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
CoreFoundation __CFRunLoopDoSources0 + 500
CoreFoundation __CFRunLoopRun + 1084
CoreFoundation CFRunLoopRunSpecific + 372
CoreFoundation CFRunLoopRunInMode + 123
GraphicsServices GSEventRunModal + 71
GraphicsServices GSEventRun + 80
UIKit UIApplicationMain + 148
2D Physics main + 140
libdyld.dylib start + 1
??? 0x0 + 1
)

Expected: SKPhysicsJointFixed, object type: PKPhysicsJointWeld
something is wrong :(
 
Last edited:

ilan

Expert
Licensed User
Longtime User
hi

after finishing my latest iSpriteKit Game i wanted to list all bugs i found while creating it:

1, _DidEndContact (aContact As SKPhysicsContact)
trying to use aContact will give you a crash (in DidBeginContact it works fine)

2, using SpriteNodeWithColor will not trigger his TouchBegan events even if i set "UserInteractionEnabled" to true
(with SkSpritenode its working fine!)

3, i could not use ANY of the Joints in iSpriteKit even if i create them as Apple say in their SpritKit Tutorials.

4, i also could not use action1.RunBlock("test"). the sub test is not called.

those are the 4 bugs i can report, if you could fix them it would be awesome. :)

i really really like iSpriteKit. its way simpler to use then Box2d and LibGdx so i really hope the lib will be fixed and also updated with the new features.

thank you very much @JanPRO
 
Last edited:

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

thank you very much for your feedback.
1, _DidEndContact (aContact As SKPhysicsContact)
Yes, you are right. I know where the problem is and will fix it.

2, using SpriteNodeWithColor will not trigger his TouchBegan events even if i set "UserInteractionEnabled" to true
Unlike of what I have said here, the TouchBegan event of the parent (the Breakout scene) is not triggered, when you have set UserInteractionEnabled to True. But that's not the explanation, why SpriteNodeWithColor doesn't work in the Breakout example, because here UserInteractionEnabled was set to false. The reason for this behaviour is a bug in the library: When you have used the SpriteNodeWithColor method, the UserInteractionEnabled property was automatically set to True. Sounds a bit weird, but it will be fixed in the next version :)

3, i could not use ANY of the Joints in iSpriteKit
Can you give an example?

4, i also could not use action1.RunBlock("test"). the sub test is not called
I have test it and wasn't able to reproduce it, can you post your code?

Jan
 

ilan

Expert
Licensed User
Longtime User
Hi @JanPRO,

because here UserInteractionEnabled was set to false

I did have set the UserInteractionEnabled to true and still the event was not triggered (for SpriteNodeWithColor)

Can you give an example?

the app crashes already on the initialize call.

B4X:
    Dim pinj As SKPhysicsJointPin
    pinj.Initialize
    pinj.JointWithBodyA(player.PhysicsBody, GameScene.PhysicsBody,Functions.CreatePoint(0,0))
    GameScene.PhysicsWorld.AddJoint(pinj)

Application_Start
Application_Active
Error occurred on line: 109 (Main)
Expected: SKPhysicsJointPin, object type: PKPhysicsJointRevolute
Stack Trace: (
CoreFoundation __exceptionPreprocess + 189
libobjc.A.dylib objc_exception_throw + 49
CoreFoundation +[NSException raise:format:] + 104
B4i Example -[B4IObjectWrapper setObject:] + 292
B4i Example -[SPhysicsJointPin Initialize] + 113
CoreFoundation __invoking___ + 29
CoreFoundation -[NSInvocation invoke] + 321
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1842
B4i Example -[B4IShell runVoidMethod] + 277
B4i Example -[B4IShell raiseEventImpl:method:args::] + 2419
B4i Example -[B4IShellBI raiseEvent:event:params:] + 1623
B4i Example +[B4IDebug delegate:::] + 79
B4i Example -[b4i_main _setupgamescene:] + 347
B4i Example -[b4i_main _page1_resize::] + 1283
CoreFoundation __invoking___ + 29
CoreFoundation -[NSInvocation invoke] + 321
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1842
B4i Example -[B4IShell runMethod:] + 515
B4i Example -[B4IShell raiseEventImpl:method:args::] + 2519
B4i Example -[B4IShellBI raiseEvent:event:params:] + 1623
B4i Example +[B4IObjectWrapper raiseEvent:::] + 309
B4i Example __30-[B4IPanelView layoutSubviews]_block_invoke + 878
libdispatch.dylib _dispatch_call_block_and_release + 15
libdispatch.dylib _dispatch_client_callout + 14
libdispatch.dylib _dispatch_main_queue_callback_4CF + 1053
CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
CoreFoundation __CFRunLoopRun + 2445
CoreFoundation CFRunLoopRunSpecific + 372
CoreFoundation CFRunLoopRunInMode + 123
GraphicsServices GSEventRunModal + 71
GraphicsServices GSEventRun + 80
UIKit UIApplicationMain + 148
B4i Example main + 140
libdyld.dylib start + 1
)

I have test it and wasn't able to reproduce it, can you post your code?

ok that is working,sorry :)
 
Last edited:

JanPRO

Well-Known Member
Licensed User
Longtime User
Update v. 1.0.1

Bug fixes:
  • the DidEndContact event is now fired correctly
  • SpriteNodeWithColor method works correctly
  • Joints are now useable
Thank you @ilan for reporting these bugs :)

You can find the new version attached in the start post.

Jan
 

ilan

Expert
Licensed User
Longtime User
Update v. 1.0.1

Bug fixes:
  • the DidEndContact event is now fired correctly
  • SpriteNodeWithColor method works correctly
  • Joints are now useable
Thank you @ilan for reporting these bugs :)

You can find the new version attached in the start post.

Jan

Awesome, Thanks a lot @JanPRO !! :)
 

ilan

Expert
Licensed User
Longtime User
hi,

i just got some time to test the new update and i am getting some troubles.
it seems like you have removed the possibility to change the width/height + positions of a SKView

in beta 1.0 i could do something like this:

B4X:
GameView.SetLayoutAnimated(1,0.9,0,0,Width,Height)

now its not possible.

i use this in the resize event so i add the skview in Application_Start

B4X:
Page1.RootPanel.AddView(GameView,0,0,0,0)

and in Page1_Resize i just set the layout of the skview.

why is it not possible anymore?

thank you, ilan

EDIT: another issue, you have removed the SKSpriteNode Tag Object!! the TAG object is very very important!!! please bring it back
 

ilan

Expert
Licensed User
Longtime User
hi @JanPRO the latest update is working well Thanks a lot for that :) (and i hope you have a nice vacation;) )

i have one question please. i would like to use multitouch in spritekit. i have read that it is possible however in b4i iSpritekit it seems that you get ONLY the first touch. so something like this:

B4X:
let touch = touches.first as UITouch

but if you would do something like this and return an array instead of a single object we could have multitouch:

B4X:
for touch in touches
{

}

what do you say? could it be possible?

thank you, ilan
 
Top