B4i Library iSpriteKit- 2D game engine

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.


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


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)


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
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…