Games (WISH) Camera Object

Discussion in 'Game Development' started by ilan, Sep 6, 2018.

  1. ilan

    ilan Expert Licensed User

    Hi

    in almost any game engine you have a camera object like in libgdx, spritekit... this object allows you to follow another object (player), zoom in , zoom out,...

    it is a very important feature in games like platformers.

    is there a camera object in xui2d? i saw the x2tiles example and what i see is just a complex calculation of the center of the world. it would be nice if i could initialize an object and just tell him to follow my player and nothing else.

    thanx, ilan
     
    MarkusR and Cableguy like this.
  2. sorex

    sorex Expert Licensed User

    to reposition the camera/viewport you can use

    Code:
    X2.UpdateWorldCenter(X2.CreateVec2(03))
    just give it the coordinates of your player and it should follow it.

    I thought there was a zoom level too, maybe I'm confused with the other game engine Erel made a while ago as I can't find it right away.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    As @sorex wrote it is quite simple to move the world center. X2Tiles is not the best example for this.

    This code is from Mario example. It is inside Mario.Tick:
    Code:
    If bw.Body.WorldCenter.X > x2.ScreenAABB.Center.X Then
           
    'update the screen center
           x2.UpdateWorldCenter(x2.CreateVec2(bw.Body.WorldCenter.X, x2.ScreenAABB.Center.Y))
           bw.mGame.WorldCenterUpdated(GS) 
    'create enemies based on the world position.
       End If
    To avoid issues where the world is updated at the middle of the game step, Mario.Tick is called from Game.Tick which is run first:
    Code:
    Public Sub Tick (GS As X2GameStep)
       mMario.Tick(GS) 
    'run first as mario updates the world position
    And there is a check in Mario.Tick at the beginning to prevent it from running multiple times.

    There is current no built-in support for zooming. This is a more complicated feature. It will probably be added in the future.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice