Sorry; completely forgot about this topic. I’ll get an official fix for this right away.
- Caleb
Sorry; completely forgot about this topic. I’ll get an official fix for this right away.
I am trying to make a character to double jump and to be able to jump again when character touches to the ground.
So here is my attempt for double jump and noticed that collision doesn’t work properly. Is collision not easy to use when using dusk or something? Am I supposed to like compare character’s coordinates to my “ground” tilelayer where the physics are ?
[lua]
map.layer[“ground”]:insert(animation) – animation is the character
local playerInAir = false
local counter = 0
function jump(event)
if event.phase == “began” and (playerInAir == false or counter <= 1) then
playerInAir = true
animation:setLinearVelocity( 0, -300)
counter = counter + 1
end
return true
end
function onCollision( event )
if(event.object1.myName == “ground” and event.object2.myName == “animation”) then
playerInAir = false
counter = 0
end
end
Runtime:addEventListener( “collision”, onCollision )
[/lua]
So the jumping now is quite randomly happening when I keep clicking the jump button and the double jump doesn’t always work.
I added the ground layers name in Tiled by giving the preference tiles:myName “ground” (not sure if that is the right way) and for animation animation.myName = “animation” in main.lua
Also I would like to know how I could get the collision happen only in characters legs. So you can’t double jump if character jumps face to the wall.
Thanks Caleb:)
Thank you Caleb!
How can I name the whole layer’s tiles ? simply putting name = floor or tiles:name = floor won’t do the trick. Or is there a way to check from what layer tile is from? OR do I just need to manually name the tiles from tileset?
How is tiles:name not working? You’re putting it in the layer properties and the tiles aren’t getting the property?
Aside, an easier way might be to use tile.parent: the Corona ‘parent’ property points to whatever group the tile is inserted into, which’ll be the layer. Dusk stores the layer name set in Tiled as “_name”, just like for objects. So you can easily check ‘if tile.parent._name == “whatever” then’.
The best way to do this when using a full-on physics engine (Box2D) is to use a counter for isGrounded instead of a Boolean. Also, you should use “isGrounded” instead of the inverse, “playerInAir”. They’ll amount to the same thing, it’s just usually done with a “grounded or not?” counter instead of a “not grounded?” counter. It’s a little more clear.
Anyhow, back to the question.
First of all, what you should do is add a collision listener that waits for “began” and “ended” phase, then sets isGrounded accordingly, instead of manually setting it when the player jumps. Also, to make sure the collision only happens with the player’s legs, you can either add a separate physics body and check for the element number during the collision, or check if the player’s position is sufficiently high above the object you collide with. Alternatively, only give the ground property to the ground tiles , instead of to every tile in the layer. Right click on the tile in the tileset, then add the property isGrounding = true or name = “ground” or something like that to the tile (stay away from “myXYZ” property names - they make your code feel “demo-y” in my opinion, and it’s just a bad practice for readability). If you’re using the same tile for the ground and the walls, this will be a problem and you’ll have to do one of the other options.
Finally, using a collision listener for only the player instead of for all of the scene and checking for if the collider is the player just makes things clearer. So I’d add the listener to the player instead of to Runtime.
Anyhoo, here’s all that information wrapped up:
local function onCollision(event) if "began" == event.phase then if event.other.isGrounding then player.isGrounded = player.isGrounded + 1 end elseif "ended" == event.phase then if event.other.isGrounding then player.isGrounded = player.isGrounded - 1 end end end player:addEventListener("collision", onCollision)
Then, in your enterFrame listener, you can reset the jump count if the player is grounded (jump count also needs a more meaningful name):
if player.isGrounded then jumpCount = 0 end
Finally, when you jump, apply a jump force and increment the jump count.
if player.isGrounded and jumpCount \<= 1 then player:applyLinearImpulse(0, -50) jumpCount = jumpCount + 1 end
Hello I seem to be having a very basic problem using the engine, so I think I must be missing something very basic. Tried using the engine and it gives me an error “attempt to perform arithmetic on local ‘gid’ (a nil value)”. I initially had it in slightly more complex code, but I’ve narrowed it down to a test project with just the snippet below in an attempt to see what was wrong.
local physics = require("physics") local dusk = require("Dusk.Dusk") physics.start() local map = dusk.buildMap("testmap2.json") map.y = display.contentCenterY map.x = display.contentCenterX
I’ve definitely put the map and tileset image into the same project folder and the dusk folder is in there as well of course, so what am I missing here?
I’ll need a little more information - can you give me the whole error, including line numbers?
Hello guys,
could anyone tell me if the Dusk Engine is still being worked on, or it is depreciated. If so, could anyone tell me any other tile based engine to use for 2d games?
Thank you a lot!
Carlos, the developer of Dusk just replied to a post a few hours before your message (Caleb) So yeah - it is. I think that Dusk is the only tile engine for Corona at the moment.
Yeah sure. Thanks for the reply.
What you saw is the entire file, but the error is in line 142 of Dusk\dusk_core\layer\tilelayer.lua: attempt to perform arithmetic on local ‘gid’ (a nil value)
Full stack traceback from corona simulator:
Dusk\dusk_core\layer\tilelayer.lua:142 in function ‘?’
Dusk\dusk_core\layer\tilelayer.lua:324: in function ‘_edit’
Dusk\dusk_core\layer\run\update.lua:59:in function ‘register’
Dusk\dusk_core\core.lua:370:in function ‘buildMap’
Dusk\Dusk.lua:54:in function ‘buildMap’
main.lua:5: in main chunk (line 5 is the line on which buildMap is called of course, not much I can say about the rest of it.)
Hm. And what about your map file? Feel free to PM it to me if you don’t want to post it publicly.
Also, can you see if using the dev branch of Dusk fixes this? In GitHub, click on “Branch: master”, switch to “dev”, and re-download the ZIP.
Switching to the dev version did not seem to work. It just got me slightly different line numbers with a similar traceback. Posting it just in case it might be helpful.
Dusk\dusk_core\layer\tilelayer.lua:267: attempt to perform arithmetic on local ‘gid’ (a nil value)
stack traceback:
Dusk\dusk_core\layer\tilelayer.lua:267 in function ‘?’
Dusk\dusk_core\layer\tilelayer.lua:532: in function ‘_edit’
Dusk\dusk_core\layer\run\culling.lua:225: in function ‘initialize’
Dusk\dusk_core\layer\run\update.lua:57:in function ‘register’
Dusk\dusk_core\core.lua:392:in function ‘buildMap’
Dusk\Dusk.lua:46:in function ‘buildMap’
main.lua:5: in main chunk (line 5 is the line on which buildMap is called of course, not much I can say about the rest of it.)
The map was a typical .json exported from tiled. The map itself was just a simple 10x10 block of tiles (64x64 tiles), as I was making it as simple as possible just to make something appear on screen. The tiles themselves were from a colleague, made for the project that I’m looking to use Dusk for. So do you just need to examine the exported map data or do you need to see/mess with the map itself? The former isn’t a problem, so I’ve attached it to this post as a txt file (doesn’t like json apparently). The latter I’ll PM to you if you need them, since it probably would be better to err on the side of caution there.
Aha! Set the “Tile Layer Format” dropdown list in the Tiled map properties window to either XML or CSV. This is a common pitfall. I’ll add an error message for this until I can code a Base64 zlib or gzip decoder.
That did it, thanks a lot for the help. Might also want to add that detail to the documentation’s quickstart bit as well.
hi,
I am currently using MTE Tile engine for my game. I have few issues with this engine, especially when my camera moves fps is getting dropped in most of the devices. Faster the camera moves greater the fps drops.
So i am currently thinking to switch over to this engine and my game is not physics based. I have few questions,
does the same issue occur in this engine. .
I am using map , which has tile size of 10 * 10 and it almost has 1000 tiles. Can this engine accommodate this map.
Is it possible to use the Spine with this engine.
More over i could not find the documentation for this anywhere. The link which is specified says page not found.
Thanks,
Kumar KS.
Hello, the “some layer” should be the name of the layer that I created on Tiled? Or is it the name of the map? I am having the sema problem and I believe if a group the player to the layer, the collision will occur.
Thank you in advance
Hi Caleb,
I am experimenting with your Dusk engine. Pretty sweet. I got a question though…
I have two Tiled json file maps where player starts from map1 and when enters a door, he goes to map2. Eventually he returns to map1 once he exits interior again.
How should I handle the switch between different map files? Each map is also its own lua file which has methods for loading json file, defining events on this map etc.
What would be the best way to handle switching between multiple levels\maps?
-T-
Hello Tilen,
where do you put the name “tile”?
Is it in your code, or in some property of the sw where we create the maps?
Newbie question…
I have inserted rectangle object in Tiled and named is as “enemy”. In Corona I try to replace the rectangle placeholder with image/sprite sheet.
for object in map.layer["npc"].nameIs("enemy") do -- something like this maybe? object.image = display.newImageRect( "enemy.png", 40, 40 ) end
Thanks in advance