Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
liquidfun / box2D — Gideros Forum

liquidfun / box2D

MoKaLuxMoKaLux Member
edited October 2019 in General questions
I have a question please.
I am trying to make a platformer using box2D. So far so good:
- player moves left/right/jump with keyboard
- moving platforms
- bouncing enemies
- slopes, ...

I have a small issue with jumping. I want the player to jump only when on floor. This works but only when the player touches the joints of my ground!

Do you know how I can fix this please?



Some piece of code:
in the player class:

	self.numfeetcontacts = false
 
	local myfeetshape = b2.PolygonShape.new()
	myfeetshape:setAsBox(self.w, 8, self.w / 2, self.h + 3, 0)
	local myfeetfixture = self.body:createFixture { shape = myfeetshape, density = 1 }
	myfeetfixture:setSensor(true)
	myfeetfixture.type = 2
 
	if e.keyCode == KeyCode.UP then
		if self.numfeetcontacts then
			impulse = self.body:getMass() * 5
			self.body:applyLinearImpulse(0, -impulse, self.body:getWorldCenter()) -- OK
		end
	end

in the level class:

function Level01:onBeginContact(e)
	local fixtureA = e.fixtureA
	local fixtureB = e.fixtureB
	local bodyA = fixtureA:getBody()
	local bodyB = fixtureB:getBody()
 
	if fixtureA.type == 2 or fixtureB.type == 2 then
		self.player.numfeetcontacts = true
		print(self.player.numfeetcontacts)
	end
end
 
function Level01:onEndContact(e)
	local fixtureA = e.fixtureA
	local fixtureB = e.fixtureB
	local bodyA = fixtureA:getBody()
	local bodyB = fixtureB:getBody()
 
	if fixtureA.type == 2 or fixtureB.type == 2 then
		self.player.numfeetcontacts = false
		print(self.player.numfeetcontacts)
	end
end

Any hints much appreciated! Peace.

edit: it sometimes work when the player does not touch joints as well but it is very inconsistent!
my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Tagged:

Comments

  • MoKaLuxMoKaLux Member
    edited October 2019
    ok got it working, super cool :| :

    in the game class:
    function Level01:onBeginContact(e)
    	local fixtureA = e.fixtureA
    	local fixtureB = e.fixtureB
    	if fixtureA.type == 2 or fixtureB.type == 2 then
    		self.player.numfeetcontacts += 1
    	end
    end
     
    function Level01:onEndContact(e)
    	local fixtureA = e.fixtureA
    	local fixtureB = e.fixtureB
    	if fixtureA.type == 2 or fixtureB.type == 2 then
    		self.player.numfeetcontacts -= 1
    	end
    end
    and in my player class:
    	if self.numfeetcontacts > 0 then
    		impulse = self.body:getMass() * 7.5
    		self.body:applyLinearImpulse(0, -impulse, self.body:getWorldCenter()) -- OK BUT
    	end
    box2d looks amazing!

    edit: will post project when I clean it up :*
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+4 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited October 2019
    Here is the beginning of a liquidfun platformer project. It is quite difficult to get the things I would like to have in a platformer.
    What I have working: animated player, player can go left right and jump (tested with 3 variations impulse, force, ...), moving platform (jittery!), pass through platform, enemies (but no firing yet), slopes (that's why I wanted to try liquidfun)

    What's missing: firing something (why bullets), taking/making damage, fixing the jittery, moving platform, and a lot lot more...

    PS: I put some comments in the code
    PS2: the code is quite short for what it is
    PS3: liquidfun is quite fun ;)
    forum_liquidfun_pf.png
    406 x 771 - 39K
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • You have links to:
    easing.lua
    gtween.lua
    mk_classes.lua
    scenemanager.lua

    That are not in the zip...
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • SinisterSoftSinisterSoft Maintainer
    Accepted Answer
    It's funny how much people code things differently. I'd have the game running all the time with the scenemanager just being used to change the state machine.

    Likes: antix, MoKaLux

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+2 / -0 )Share on Facebook
  • @SinisterSoft here is the new zip :/
    yes there are so many different ways of doing things. This is what I love about coding = freedom. When you begin you do it the way that makes sense to you then overtime when you learn best practices you adapt.
    zip
    zip
    mkgiPlatformerLiquidFunForum.zip
    238K

    Likes: SinisterSoft

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited October 2019
    A bit of progress here with my liquid fun platformer.
    The pass through platforms are a bit buggy.
    I found out why my player was jittery on moving platforms and fixed it o:)
    Now we have a bridge, the player can shoot (but no collisions with enemies yet), ...
    Some thought about this:
    - I noticed that for a platformer, liquidfun (box2d) is the way to go (cf: other engines)
    - I learnt a lot from iforce box2d tutorials
    - it is a bit harder than cbump but we can achieve so much more!

    I think that I will push it more to make a yt tutorial?
    The game is quite fun to play on a mobile! I am quite happy with the controls <= great success here B)
    zip
    zip
    mkgiPlatformerLiquidFun.zip
    261K

    Likes: Nanocore, antix

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+2 / -0 )Share on Facebook
  • antixantix Member
    Accepted Answer
    Yes! At iForce there are heaps of great box2d tutorials. I created a Gideros version of the car based on that site... a great resource!

    @Totebo has had some success using their editor as well (I think)
  • MoKaLuxMoKaLux Member
    edited October 2019
    yes @antix you are right! box2d (liquidfun) is a very big thing. I searched this forum to get some help and I came across your car demo and it is great!!!
    What has your game became (become?)? It looked very promising and I am quite a fan of those top down racing games!
    Gideros is a great engine but we have to dig. @antix we need a gideros book it's becoming urgent.

    I am trying to put everything together to see how far I can get building a platformer using liquidfun.

    One problem I may have is building the level! RUBE looks super cool and I have read that TILED also fits but I am not there yet. As of now I am building my level pixel by pixel!
    I may ask for your help later if I am not happy with how I build my levels.

    @all I am sorry but a platformer is the basics of any game engine!
    PS: I managed to make my player shoot and kill "enemies" B)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • antixantix Member
    edited October 2019 Accepted Answer
    @MoKaLux Nothing because of my little game because Gideros has no multiplayer support and I couldn't figure that out myself. I have lots of ideas for multiplayer games but Gideros doesn't support that out of the box :(

    You can use tiled to make levels but its slow going. You create polygons and then give them properties. In your code you load the tiled map and iterate through the objects layer and use that data to generate the Box2D shapes you need. I'm not sure how you are doing things right now but I found Chain Shapes to be quite good.

    Anyhoo.. hit me up if you need any help :)

    P.S, I also gave up on my Gideros book for now because I'm studying full time. I'd like to get back into it but I feel myself becoming more and more detached from Gideros as time goes by.
  • @antix I know what you mean. Gideros can be frustrating sometimes but trust me this is a great engine (if not the best engine I have used so far)! Please don't give up on us, we need you!

    Likes: SinisterSoft

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited October 2019
    antix said:

    because Gideros has no multiplayer support

    Gideros does have multiplayer support:
    1. Photon
    2. Colyseus
    3. GooglePlay Gaming Services
    4. Noobhub
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • ok I think it's good enough! A nice liquidfun 2d platformer for you to test!
    Please let me know what you think.

    The only little problem I see is building the levels! I place every single items by hand. It's ok if you build a couple of levels but more than that it can be cumbersome.
    Personally I don't mind building the levels by hand and I haven't tried Tiled editor nor RUBE. I am using the wonderful Contour.lua class by @n1cke and I have read you can build levels using it!
    Some tutorials to come?
    zip
    zip
    mkgiPlatformerLiquidFun.zip
    310K
    forum_liquidfun_pf02.png
    721 x 456 - 112K
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • MoKaLuxMoKaLux Member
    edited October 2019
    IMHO
    1- that's the way to go to do 2D platformers in gideros.
    2- Liquidfun is not that hard once you know a little bit.
    3- compared to cbump I would definitely go the liquidfun way.
    4- there are much more things I have tested (particles, joints, ...) but they did not make it into this demo.
    5- I enjoyed the development a lot and I got frustrated at times but @Apollo14 "no pain, no gain" :)
    6- I got my mobile controls working pretty well too!
    7- of course VIVA GIDEROS!
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+2 / -0 )Share on Facebook
  • MoKaLux said:


    Personally I don't mind building the levels by hand and I haven't tried Tiled editor nor RUBE.

    Wow I love that physics rope there! <3
    Many hyper-casual games are physics-based nowadays, with simple graphics. I guess the only thing that restricts us is our imagination.

    Imo you should give Tiled a try, it's great tool. :smile:

    Likes: MoKaLux, antix

    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
    +1 -1 (+2 / -0 )Share on Facebook
  • yes I believe every game engines rely on box2d (or liquidfun) under the hood. With liquidfun you can build many interesting games and I think I found the missing link from doing what I use to do in an other engine.
    Now that I know that box2d is the key I will have to do many more experiments.
    For Tiled I have read that it's cumbersome to set up everything in it because you have to add lots of parameters for each physics objects so I don't think I am going to use it. In the code you set up one class and that's it. When you want to build something you call that class.
    I will surely find a way to make it easier (for the main level I used MS Excel to set up the shape).
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • Very cool @MoKaLux I will try to check it out lateron today :)

    I think that if you don't require slopes then cbump trumps liquidfun in terms of performance and ease of use though. It's really a matter of using the right tool for the job.

    @Apollo14 Sure you can attempt to use those systems but IMHO they aren't exactly straight-forward.

    Likes: oleg

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLux said:


    For Tiled I have read that it's cumbersome to set up everything in it because you have to add lots of parameters for each physics objects so I don't think I am going to use it. I.

    The right solution would be to use: Tiled +cbump+spine
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • antixantix Member
    Accepted Answer
    @Oleg, totally agree but if you want irregular shaped platforms you have to use LiquidFun... or make some whacky code to manage slopes yourself. This video on youtube features a platform engine (yet another one) that I made that uses only cbump and includes slopes

    @MoKaLux For larger projects you are going to start getting fatigued creating levels inside Excel I think :D

    Give tiled a try for sure and use object layers to create physics shapes. I've atached a small example to show you how easy it can be ;)

    Oh... you will need the tiled program to open the map for editing :)
    zip
    zip
    tiled.zip
    3K

    Likes: MoKaLux, oleg

    Dislikes: JuanZambrano

    +1 -1 (+2 / -1 )Share on Facebook
  • thank you all for your replies. @antix that's a perfect example, thank you.
    I am not sure which road I am going to take. I need more time to experiment.
    My rule of thumb is doing as simple as possible with minimal/no external tools. Pure gideros studio/lua magik!
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • Apollo14Apollo14 Member
    edited October 2019
    antix said:

    @Apollo14 Sure you can attempt to use those systems but IMHO they aren't exactly straight-forward.

    All the multiplayer games that you see either use Photon or their custom backend.
    It's always pain in the ass, there're no easy solutions anywhere.
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
Sign In or Register to comment.