Games Useful Formulas

ilan

Expert
Licensed User
Longtime User
btw making this game: https://www.b4x.com/android/forum/threads/physics-2d-game-in-progress.78313/#post-498197
took me about 2 weeks (and i have a full time job) and also the current iSpriteKit lib has a lot of bugs so i had to find different ways to solve my problems. so i think the reason i could do it so fast is because its really simple after you understand the logic how spritekit works.
so i would definitely take some features and logic from it and implement in SGE ;)
 
Last edited:

ilan

Expert
Licensed User
Longtime User
Oh another great feature.

Spritekit can create a physicbody according your texture. So it will get the alpha of a transparent texture and return a very precise physicbody. Although on a high performance cost. So its not always a good thing to do but its an option.

https://developer.apple.com/referen...ef/occ/clm/SKPhysicsBody/bodyWithTexture:size:

Btw lights and shaders are very simple to use in spritekit.


My next game i am planning will use some nice light effects ;)
 

Informatix

Expert
Licensed User
Longtime User
Thanks for these informations.

1. create a simple template. in spritekit you just create an SkView and add everything to it. its like a big panel where you add it to your Page like you would add a panel. so you always can hide it or do what ever you want with it.
I suppose that SKView is a scene editor where you can place your visual assets and compose your scenes, and where you can test the behavior of physics simulations too. It's what misses the most to libGDX and SGE. With such a tool, it would be easier and simpler to create games, but it's too much work for me.
It exists Overlap2D but I only tried a very early version that was not fully working. It deserves a new try.

2. skscene: an skscene is also like a panel where you add childs to it (sknodes) so its like a page in your skview
if you have a menu you create an skscene and add all childs to it.
SkScene, as I understand it, is a Screen in libGDX and SGE.

now try to do it with libgdx and you will see you need to think about a lot of stuff !!
No, sorry, I don't understand what's best with SkScene. Switching to another screen with libGDX or SGE is very easy.

3. in spritekit you create a node. a node can hold textures or can be a labelnode... but the awesome thing in sprite kit is that every node has his own physicbody.
even a gamescene has his phsyicbody. if you dont set it its like just a simple sprite but if you set it it will react to gravity and collisions.
I understand that you appreciate a lot the scene editor of iSpriteKit, and I fully agree as it is an unvaluable add-on. But I cannot compare this part of iSpriteKit with anything of SGE. Considering only the framework, what do you find interesting in iSpriteKit that is not in SGE (or not well implemented)? And not related to physics as I don't plan to add a physics engine to SGE.
 

Informatix

Expert
Licensed User
Longtime User
Probably not many people use Tiled Map Editor as a scene editor, but it can be used like this. It's why exist object layers or collision objects in this tool. I used these objects a lot in my Diktatour game. Composition and paths of processions are stored in the map file.
 
Last edited:

ilan

Expert
Licensed User
Longtime User
I suppose that SKView is a scene editor where you can place your visual assets and compose your scenes, and where you can test the behavior of physics simulations too. It's what misses the most to libGDX and SGE. With such a tool, it would be easier and simpler to create games, but it's too much work for me.
It exists Overlap2D but I only tried a very early version that was not fully working. It deserves a new try.

yes, a SkView is like a big container where everything is added to it.

SkScene, as I understand it, is a Screen in libGDX and SGE.

i am not sure its the same but anyway a SkScene is also a PhysicWorld and has also its own PhysicBody. so it is really simpler to use.
so every SkScene has its own PhysicWorld so the combination of nodes and physics are very intuitive.

what do you find interesting in iSpriteKit that is not in SGE (or not well implemented)? And not related to physics as I don't plan to add a physics engine to SGE.

i still have not used SGE i just wanted to share my experience with you about SpriteKit.
i just find it very simple how Spritekit handles all nodes. its like working with real views (imageviews, buttons,..)
 

ilan

Expert
Licensed User
Longtime User

ilan

Expert
Licensed User
Longtime User
if i remember correct there was a thread about how to make a wave shader with libgdx.
or what is a drop shader? o_O
someone asked about an android app where you have an aquarium with fishes and there was a very nice shader. however i just found a simple tutorial how you can implement a wave shader in spritekit. maybe you can have a look at it and compare it with libgdx what is simpler.

http://endlesswavesoftware.com/blog/spritekit-shaders/
 

Informatix

Expert
Licensed User
Longtime User
i just find it very simple how Spritekit handles all nodes. its like working with real views (imageviews, buttons,..)
It's the philosophy of JavaFX too. Everything is a node. A circle, a polygon, an image... But this is something great for a scene editor, not for a game framework. Using multiple nodes in a game (e.g. using an ImageView for each sprite) would lead to terrible performance. Drawing things on a canvas is 10 times faster. That's why, in SGE, only the drawing surface (the canvas) is a node.
 

ilan

Expert
Licensed User
Longtime User
It's the philosophy of JavaFX too. Everything is a node. A circle, a polygon, an image... But this is something great for a scene editor, not for a game framework. Using multiple nodes in a game (e.g. using an ImageView for each sprite) would lead to terrible performance. Drawing things on a canvas is 10 times faster. That's why, in SGE, only the drawing surface (the canvas) is a node.

yes i understand and also agree. what i was thinking of is

if i will use SGE (and i am sure i will) i would create a custom type that holds a texture, a physicbody, x/y coordinate and lots of other stuff

then i will create a draw and move function in a code module and handle all object in my screen with just this custom type.
so i will use the logic of spritekit but draw everything like libgdx. this is something i would do and it would be possible to do it by myself but implementing it would make it easier. of course it will change the whole logic how SGE will work but if we want to make it simple i would do it like this.


it will make it easier to interact with an object instead of interact with a body and then get his angle and draw a texture to it... this way you will not loose performance but make it easier to handle all object in the screen.

this is just a thought, what do you think?
 

Informatix

Expert
Licensed User
Longtime User
yes you can.
https://developer.apple.com/reference/spritekit/skshader

you load those shaders from external files.
but you have also build in shaders i guess. i still did not used any in SpriteKit but the lighting stuff is something i will try soon.
I looked at videos of SpriteKit and it is a great scene editor indeed.
The lighting stuff seems to work like Box2DLights (the result is the same).
What I don't understand is how you apply steering behaviors to sprites.
 

Informatix

Expert
Licensed User
Longtime User
if i will use SGE (and i am sure i will) i would create a custom type that holds a texture, a physicbody, x/y coordinate and lots of other stuff
This abstraction already exists in SGE. It's an actor (sgeActor). An actor can have a visual object (a text, an image, an animation) or not. You can create a class based on an actor to add new properties and perform a customized drawing of this actor. Thus, creating a class that binds a jBox2D object to an actor is the recommended way to go.
 

ilan

Expert
Licensed User
Longtime User
This abstraction already exists in SGE. It's an actor (sgeActor). An actor can have a visual object (a text, an image, an animation) or not. You can create a class based on an actor to add new properties and perform a customized drawing of this actor. Thus, creating a class that binds a jBox2D object to an actor is the recommended way to go.

Yes this is what i ment. Its the logic spritekit works.

What I don't understand is how you apply steering behaviors to sprites

Sorry i dont understand your question.

You mean how i use the lib steering behaivor with ispritekit?
Or how can i move a sknode in a path?
 

ilan

Expert
Licensed User
Longtime User
in spritekit almost everything happens with Actions.
expect if you apply forces or impulse.

what i have seen until now is that there is a possibility to create an skaction that will move a sknode along a path.
i think its also possible to make it react to the physicworld while its following that path but i have not used it until now so i cannot tell you 100% how it can be done.
i will try to investigate it and let you know.

however this is the skaction method of following a path

path.png

there are 4 different followPath methods but i am not sure how they work and whats the difference between them.
 
Last edited:

ilan

Expert
Licensed User
Longtime User
i am just thinking that maybe you could create an sknode that follow a specific path and then connect your car with this sknode with a spring joint. so if it moves it will move that car but on sharp curves the spring joint will give a smooth curve effect.
 
Top