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
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.
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
@kredor7, @OZApps: Good ideas too, will experiment with random objects that the hero has to avoid. Thanks.
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
http://docs.giderosmobile.com/reference/gideros/TileMap/clearTile#TileMap:clearTile
https://deluxepixel.com
attempt to call method 'clearTile' (a nil value)
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):
Watch the video above of @hgvyas123 , where the stars are destroyed when they collide with the Viking
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 )