Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Platform game design — Gideros Forum

Platform game design

click2installclick2install Member
edited November 2013 in Game & application design
Hi all,

I am creating a platformer like mario or wonder boy, etc and wondering the best method of movement. I will be managing physics myself and not using Box2D.

Should the character (and the world) move (possibly at a different rates) or should the world just move. E.g. character jumps to right and world moves down and to the left.

Thanks

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @click2install are you sure you want to manage physics on your own?

    But ok if you ask me, then, most probably you would want your character to remain on in the same place on screen (like in the middle of the screen for example)

    So there are two approaches.

    You have a scene
    background layer is added to the scene, and character is added to the background layer

    This would be a box2d approach, because you already have the speed of moving object, and what you do is simply move the background in inverse speed in another direction, and your character would always stay in the middle of the screen

    Example:
    http://appcodingeasy.com/Gideros-Mobile/Gideros-Camera-Move

    But since you will handle the physics on your own, you can:
    have a scene
    add background layer to the scene
    add character to the scene

    That way, you will be able to simply position your character in the middle of the screen, and it will always be there, and you can move background layer to any side independently. So you would only have to manipulate the world as you described.
  • Thanks @ar2rsawseen, that's what I thought and implemented a test scenario to the same. I am also toying with moving the character slightly as well as the background so there is a slight parallax effect between the character and the scene background.

    I have done quite a lot of AS2/3 development as well as other languages but this will be my first larger scale game. Have made several small scale (viz Space Invaders, PacMan, etc) games before.

    I have read in a couple of places that Box2D is not a good idea for platformer's due to it being too restrictive once the game starts to grow in size. What are your thoughts, from what I have read the jury is still out? I don't have a problem with doing my own physics but if Box2D is an option, then why reinvent the wheel?


    Thanks for your input.
  • I honestly have not tried creating platformer, so those who did may have better understand to answer if you should or not use box2d.

    So maybe @phongtt could elaborate on how Cerberus puppy (http://giderosmobile.com/apps/cerberus-the-puppy) was created? :)
  • I can always use Box2D and try it. If it starts getting out of control I can change it to custom physics. Thanks @ar2rsawseen and @phongtt.
  • john26john26 Maintainer
    edited November 2013
    I've written a platform game using Gideros and I *did* use Box2D which I strongly recommend. If you don't you have to implement some advanced collision response (not the same as collision detection) algorithms. This tutorial will tell you how

    http://www.metanetsoftware.com/technique/tutorialA.html

    (basically you'll end up reimplementing some of the algorithms in box2D)

    You can try my game if you like. If it's the sort of thing you want to do I'd be happy to answer questions:

    https://itunes.apple.com/us/app/nebula-retro/id730484292
    https://play.google.com/store/apps/details?id=com.simpleinteractive.nebula&hl=en

    Likes: phongtt

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks @John26, your game is pretty cool, love how you can edit completed levels. I have started using Box2D and will continue that path until it gets to a point where I feel like I am having to hack the code to get around any limitations it might impose (based on blog posts I've read).

    The game I am making is more a multi-screen per scene sideways platformer like Mario Bros or Wonder Boy, etc. Old school gaming at its best :). If I have any issues I will start another thread up and document the process for everyone to see.

    Likes: ar2rsawseen

    +1 -1 (+1 / -0 )Share on Facebook
  • john26john26 Maintainer
    edited December 2013
    Thanks! Please leave write a review if you have a moment. That will help me get more downloads.

    I did try not using Box2D to begin with but it just didn't look right. But if you follow the tutorial I linked above you can probably make it work.

    I did have some issues with Box2D. It's important that the character can only jump when he is in contact with the ground not in mid air (except when he has rocket boost in my game). To do this I used box2D collision events BEGIN/END_CONTACT. But these do not distinguish between horizontal and vertical platform sides (they just tell you about fixtures, I was using rectangular fixtures). In the end I made this a feature so the character can jump off any platform (except for ice platforms). But in a classic platformer you will probably want your character to only be able to jump off a (near) horizontal surface. I'm not sure what the best way round this is? I guess you could use a body with multiple fixtures, for the top and sides of each platform. I've heard there is also a collision manifold but not sure what it is...

  • ar2rsawseenar2rsawseen Maintainer
    edited December 2013
    @john26 yes you are right about b2.Contact and you can get it from collision event:
    function onCollision(e)
        --gives you b2.Contact object
        local contact = e.contact
        --which you can then use to check
        if contact:isTouching() then
            --the collision is still active
        end
    end
    ;)
  • john26john26 Maintainer
    But I want to tell which *side* of the platform body is in contact with the player. I'm now thinking the best way is to create a platform body with 4 fixtures, each an edge shape, which surround the rectangular platform. The user is only allowed to jump if he is in contact with the fixture for the top of the platform (not sides). Is this the standard way of doing it?
  • ar2rsawseenar2rsawseen Maintainer
    edited December 2013
    I meant you are right, that it can be figured out by the manifolds, no need for extra fixtures.
    for example:
    local isTouchingGround = false
    self.world:addEventListener(Event.BEGIN_CONTACT, function(e)
    	local manifold = e.contact:getWorldManifold()
    	if manifold.normal.y > 0.9 then
    		--collision came from bottom
    		isTouchingGround = true
    	end
    end)
     
    self.world:addEventListener(Event.END_CONTACT, function(e)
    	local manifold = e.contact:getWorldManifold()
    	if manifold.normal.y < 0.1 then
    		--collision ended from bottom
    		isTouchingGround = false
    	end
    end)
    Note that normal works from fixtureA to fixtureB, so depending on in what order the fixtures were created, you may need to check instead
    if manifold.normal.y < -0.9 then
    and
    if manifold.normal.y > -0.1 then
  • john26john26 Maintainer
    That's an interesting way of doing it, thanks!

    Another method I found is to create a "foot sensor" under the main body which fires only when in contact with the ground. Nice tutorial here:

    http://www.iforce2d.net/b2dtut/jumpability

    Probably there are pros and cons of these two methods...
  • DungDajHjepDungDajHjep Member
    edited August 2014
    @john26
    resloved problem, just need set name for fixtures after creat fixtures

    example:
    poly:setAsBox(bodyWidth*0.5,5,0,bodyHeight,0)
    body.fixtureFootSensor = body:createFixture{
    shape = poly,
    density = 0.000001,
    friction = 0,
    restitution = 0,
    isSensor = true
    }
    body.fixtureFootSensor.Name = "FootSensor"

    --[[
    i reading tutorial in box2d forums but dont know how to set user data to find different from fixtures]]

    Dislikes: Yan

    +1 -1 (+0 / -1 )Share on Facebook
Sign In or Register to comment.