Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Can I use tiledMap for an endless background game? — Gideros Forum

Can I use tiledMap for an endless background game?

flyhereflyhere Member
edited February 2014 in Game & application design
I got a tiledmap to work where the hero runs to the end of the map, jumping or climbing to avoid physical obstacles, hits a door, and goes into the next level.

Can I use the same method but instead of going into the next level, the tiledmap restarts from the beginning to have the hero running endlessly with a continuous endless background? I tried resetting the X-coord to the beginning, but that only re-displays the graphics, and all of my physical bodies are all messed up not aligned with my graphics.

Is there a better way to do this type of game?


function Level:onEnterFrame()
if self.started then
if self.hero.moving then
-- at the end of map: stop world moving
print (self.map:getX())
if self.map:getX() < -2400 then
-- self.map:setX(-240)
self.hero.moving = false
else
-- moving map(x, y)
self.map:move(-3, 0)
self.frame = 0
end
end
self.frame = self.frame + 1
world:step(1.5/60, 8, 3)
end
end


Thanks

Comments

  • hgvyas123hgvyas123 Guru
    edited February 2014
    good idea is to create 4-5 maps using tiles and then load any map to start and after some time append another map at the end of the first map once the first map is outside of the screen destroy all the objects and physics body for that and continue this same process again

    :)
  • Another way is what I used for my Dream Runner game was to generate the floor without using tilemaps and would randomly generate bodies and sprites on the screen for the platforms. This was done at a certain amount of pixels ahead of the player.

    If your comfortable with coding bodies and sprites with box2d you could do a few sets to be created ahead of the player and then just loop it forever.
  • Tilemaps make for a fixed experience, where playing the level over and over again can help you sort the level / master it. On the other hand the dynamic way to create levels provide for a unique experience everytime you play it.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • also it looks more good if we go with tilemap see video of my game viking runner



    :)
  • @hgvyas123: Thanks, will try it this weekend. I have to draw the map out on a big piece of paper and work out the coordinates. I only know using tiledmap.new to load the map, not sure how to append the 2nd map to the end of the first. Will have to do some reading up.

    @kredor7, @OZApps: Good ideas too, will experiment with random objects that the hero has to avoid. Thanks.
  • actually there is no inbuilt method to append the map so you have to go for your own way say you are making map of 2000 pixel then calculate in your way when you need another map and put that at 2001 once the first map is outside of the screen remove all physics bodies and object associated with that and repeat this for ever

    :)
  • Thanks, will try to figure that out.
  • I must be doing something wrong.

    I have
    self.map = TiledMap.new("maps/map01")
    stage:addChild(self.map)

    which has the background graphics and the corresponding ground and obstacles, and map01 scrolls OK until the end.

    - When I detect the end of map01 I load map02
    self.map = TiledMap.new("maps/map02")

    the ground and obstacles seems to scroll ok but not the background (obviously)

    - If I also add map02 to the stage with
    stage:addChild(self.map)

    then the background scrolls but I lost the ground and the physical obstacles.

    What am I missing? Since the map is both the background and physical bodies, shouldn't they both scroll?

    Thanks
    Phi
  • can't say much but you are using both map with the same name self.map so obviously when you are loading map02 you are losing the reference of map01 and may be that is the main problem over here

    :)
  • atilimatilim Maintainer
    Also you can use TileMap:shift(dx, dy) http://docs.giderosmobile.com/reference/gideros/TileMap/shift#TileMap:shift for fast and easy scrolling of your tile map.
  • yubaroyubaro Member
    edited January 2016
    I'm trying with Tiled Map. How you can remove an object and corresponding image?
  • 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
  • @SinisterSoft , I'm using this method and I get:

    attempt to call method 'clearTile' (a nil value)
  • piepie Member
    @yubaro I just tried it on sewers example, works for me.
    Are you sure you're calling it on the right object?

    The problem may be that you call clearTile on a Sprite that "contains" the tilemap, not on the tilemap itself.

    This is what I've done in main.lua (sewers example):
    --(...)
    				local tx = (gid - tileset.firstgid) % tileset.sizex + 1
    				local ty = math.floor((gid - tileset.firstgid) / tileset.sizex) + 1
     
    				tilemap:setTile(x, y, tx, ty)
     
    --added on line #76, but I may have played around with the example and changed line numbers... <img class="emoji" src="http://forum.giderosmobile.com/resources/emoji/smile.png" title=":)" alt=":)" height="20" />
    				tilemap:clearTile(10,10)
     
    --(...)
  • @pie My question goes to a collision between "hero" and an object on the map (removing the object and its corresponding image)

    Watch the video above of @hgvyas123 , where the stars are destroyed when they collide with the Viking
  • piepie Member
    @yubaro take a look at these examples:
    http://giderosmobile.com/forum/discussion/comment/46243#Comment_46243

    With the first one you should be able to clearTile() ( instead of setTile() ), while with the second you should be able to place the stars "outside" of the tilemap object and access them directly/check if hero collidesWith( star )
Sign In or Register to comment.