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!
Comments
in the game class:
edit: will post project when I clean it up
Likes: keszegh, Apollo14, antix, SinisterSoft
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
easing.lua
gtween.lua
mk_classes.lua
scenemanager.lua
That are not in the zip...
https://deluxepixel.com
Likes: antix, MoKaLux
https://deluxepixel.com
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.
Likes: SinisterSoft
The pass through platforms are a bit buggy.
I found out why my player was jittery on moving platforms and fixed it
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
Likes: Nanocore, antix
@Totebo has had some success using their editor as well (I think)
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"
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.
Likes: SinisterSoft
"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)
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?
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!
Likes: hgy29, SinisterSoft
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.
Likes: MoKaLux, antix
"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)
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).
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
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
@MoKaLux For larger projects you are going to start getting fatigued creating levels inside Excel I think
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
Likes: MoKaLux, oleg
Dislikes: JuanZambrano
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!
It's always pain in the ass, there're no easy solutions anywhere.
"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)