Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Dusk Engine
Started by Caleb P Dec 13 2013 12:22 PM

490 replies to this topic
dusk engine tilemap game engine opensource
[TOPIC CONTROLS]
« Page 18 of 20 16 17 18 19 20
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#426

yaliyaa

[GLOBAL: userInfoPane.html]
yaliyaa
  • Observer

  • 4 posts
  • Corona SDK

Hi,

 

Im having a strange issue. Im building a platformer game and i position my map in the bottom left of the screen like this 

local map = dusk.buildMap("levels/level1.json")
map.y = -map.data.height + display.contentHeight

I have a ground layer with physics:enabled and tiles:bodyType static.

When i insert my character to the ground layer it appears above the screen then falls down and collides

with the ground.

physics.addBody(character, "dynamic", { friction = 0.0, density=1.0, bounce = 0.0})
map.layer.Ground:insert(character)

What i want is my character to be positioned in the center of the screen, i tried 

character.x = display.contentCenterX
character.y = display.contentCenterY

it works if i don't insert the character to the ground layer, but when i insert it it just positions above the screen.

 

- Best



[TOPIC: post.html]
#427

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

@yaliyaa:

I'll need some more information. What do you mean by "start at the bottom left"? Do you want to position the camera at the bottom left of the map?  How did setViewpoint mess up your tiles?

 

@Painconfess:

You can either turn object culling off, or iterate through the objects' data (there's an iterator for that with the latest branch), but a better way is probably to add every object type in your code. What I have is each object type (just like yours, stored under objects/objectType.lua), then I have a types file that looks like this:

return {
  require("objects.cupcake"),
  require("objects.explodingCow"),
  require("objects.poisonedAcorn"),
  require("objects.wonkaBar")
}

Then, in my code, I iterate through the object types file and add each object type from it. If you want to only load the object types you need, the iterator is 'objectDatas'. It iterates through each object data stored in the layer. The object data is in a special format, so you might need to explore the format with a few pairs() loops to see how things are stored. Basically, there's some object building data in the table, then a 'transfer' table that contains stuff the built object gets. The _type will be in the 'transfer' table.

for objectData in map.layer["objects"].objectDatas() do
  print(objectData.transfer._type)
end

@yaliyaa #2:

This is a mix-up between local and content coordinates. Insert the player into the layer, then you should be able to fix this with Corona's contentToLocal function:

player.x, player.y = map.layer.Ground:contentToLocal(display.contentCenterX, display.contentCenterY)

- Caleb



[TOPIC: post.html]
#428

yaliyaa

[GLOBAL: userInfoPane.html]
yaliyaa
  • Observer

  • 4 posts
  • Corona SDK

Hi Caleb,

Yes i want to position my camera at the bottom left.
I'm building a sidescroller game.



[TOPIC: post.html]
#429

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

You can set a layer's camera offset via layer.setCameraOffset(x, y). That might be what you're looking for. Otherwise, can you give me an example of what you mean?

 

- Caleb



[TOPIC: post.html]
#430

burnsj002

[GLOBAL: userInfoPane.html]
burnsj002
  • Contributor

  • 212 posts
  • Corona SDK

If I use collision filtering for my player and bullets the player fires-- the tiles will not be part of any collision detection between them. How do I add a collision filter to the tiles? Or can I?



[TOPIC: post.html]
#431

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

You can use Dusk's JSON or Bang (I recommend Bang!) notation to do that (in tile properties):

physics:filter     =     !!! categoryBits: 4 maskBits: 1

You can use one of the collision filter helper charts (one is on the docs page at https://docs.coronalabs.com/daily/guide/physics/collisionDetection/index.html) to find the correct values for tiles to collide.

 

- Caleb



[TOPIC: post.html]
#432

burnsj002

[GLOBAL: userInfoPane.html]
burnsj002
  • Contributor

  • 212 posts
  • Corona SDK

Okay I got this far but how do you use Bang notation to change the physics:filter of each tile?

for tile in map.layer["tiles"].tilesInRange(1, 1, 32, 32) do
  
        if(tile.bodyType and tile.bodyType == "static" ) then
            --physics:filter     =     !!! categoryBits: 4 maskBits: 1  ?????
        end
end​

Also, how do you return  how many tiles are in the map? When I iterate through this code it seems I have 832 tiles in the map. But its a 32x32 map size. Shouldn't the map tiles size be 1024? Am I using "tilesInRange" wrong??

 

The dusk engine is awsome everthing worked perfect unti added the code for the Player  to fire bullets. There was collision between the player and the bullts ugh.

Thanks for all your help Caleb



[TOPIC: post.html]
#433

Painconfess

[GLOBAL: userInfoPane.html]
Painconfess
  • Enthusiast

  • 49 posts
  • Corona SDK

Hi Caleb and thank you from the earlier response of my previous problem! :)

 

But once again there is something I need your help.

 

I want to achieve the same thing Aatos Media wanted awhile ago:

 

 

 

EDIT

 

Don't know if this a good way, but at least it works:

objectType.build = function(event)

  local objectid = event.object.x .. "|" .. event.object.y
  local object = display.newImageRect("image.png", 40, 40)
  if globals.hitPoints[objectid] == 0 then
     return object
  end

 

 

@Aatos Media:

Good catch. Didn't even think about that. You can add a nil check in the addObjectType function for that.

 

You probably don't want to use up the resources to create an object if the object doesn't need creating, which is why I was just exiting the function if it was destroyed. So a nil check is probably a better idea than creating the object whether it should be or not. That said, if you don't mind the wasted memory, that'll work, too.

 

 

- Caleb

 

So the question is: where do I add the nil check? I have tried right before the error and in the beginning of the addObjectType function and many other places, but then occurs more dusk_core errors.



[TOPIC: post.html]
#434

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

@burnsj002:

The filter notation will go in the tile properties from Tiled. With the most recent version of Tiled (0.13.0 at the time of this writing), click on the tile you want to have a filter, then add a property from the properties menu.

 

@Painconfess:

The nil check'll be in the object type building code. After you create your object via the params.build function, check for if the object was created. If it was, proceed, otherwise, cancel and clean up or whatever. Then, add another nil check in the object type removal code erase listener.

 

- Caleb



[TOPIC: post.html]
#435

burnsj002

[GLOBAL: userInfoPane.html]
burnsj002
  • Contributor

  • 212 posts
  • Corona SDK

Thanks Caleb:)



[TOPIC: post.html]
#436

Painconfess

[GLOBAL: userInfoPane.html]
Painconfess
  • Enthusiast

  • 49 posts
  • Corona SDK

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? :D



[TOPIC: post.html]
#437

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

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'.

 

- Caleb



[TOPIC: post.html]
#438

geiganax

[GLOBAL: userInfoPane.html]
geiganax
  • Observer

  • 6 posts
  • Corona SDK

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?



[TOPIC: post.html]
#439

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

I'll need a little more information - can you give me the whole error, including line numbers?

 

- Caleb



[TOPIC: post.html]
#440

carlos.rafael

[GLOBAL: userInfoPane.html]
carlos.rafael
  • Observer

  • 28 posts
  • Corona SDK

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!



[TOPIC: post.html]
#441

Aatos Media

[GLOBAL: userInfoPane.html]
Aatos Media
  • Contributor

  • 128 posts
  • Corona SDK

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.



[TOPIC: post.html]
#442

geiganax

[GLOBAL: userInfoPane.html]
geiganax
  • Observer

  • 6 posts
  • Corona SDK

I'll need a little more information - can you give me the whole error, including line numbers?

 

- Caleb

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.)



[TOPIC: post.html]
#443

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

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.

 

- Caleb



[TOPIC: post.html]
#444

geiganax

[GLOBAL: userInfoPane.html]
geiganax
  • Observer

  • 6 posts
  • Corona SDK

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.

 

Attached File  testmap2.txt   900bytes   3 downloads


 



[TOPIC: post.html]
#445

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

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.

 

- Caleb



[TOPIC: post.html]
#446

geiganax

[GLOBAL: userInfoPane.html]
geiganax
  • Observer

  • 6 posts
  • Corona SDK

That did it, thanks a lot for the help. Might also want to add that detail to the documentation's quickstart bit as well.



[TOPIC: post.html]
#447

kumarks102

[GLOBAL: userInfoPane.html]
kumarks102
  • Enthusiast

  • 71 posts
  • Corona SDK

  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, 
 
1. does the same issue occur in this engine. .
2. I am using map , which has tile size of 10 * 10  and it almost has 1000 tiles. Can this engine accommodate this map.
3. 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.


[TOPIC: post.html]
#448

carlos.rafael

[GLOBAL: userInfoPane.html]
carlos.rafael
  • Observer

  • 28 posts
  • Corona SDK

Ahh... Make sure you're inserting the player into your map.

map.layer["some layer"]:insert(player)

 

- C

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



[TOPIC: post.html]
#449

carlos.rafael

[GLOBAL: userInfoPane.html]
carlos.rafael
  • Observer

  • 28 posts
  • Corona SDK

@CSIV2013to2014

 

Sorry for late answer.

 

Uhm...I wouldn't recommend playing around with physics during collisions. Adding physics bodies, turning physics on/ off and all that can ruin the performance of your game. 

 

I'm not sure if it's possible to do that...right now I can't think of anything to access layer properties within main.lua

 

Correct me if I'm wrong please.

 

You could however detect if your character (or something) collides with tiles, and it's possible to detect if physics bodies collided vertically or horizontally.

 

If they collide horizontally (while moving over the X axis), let the character pass through the stairs. How to let him pass through the stairs?

I think it's possible to do that by using collision--->event.contact

Haven't tried using event.contact myself yet, but that's probably what we're looking for.

...yeah, they use event.contact for the same thing right here.

 

 

Ok, so how to detect if objects collide vertically or horiontally?

I came up with some code that can detect that...originally I used it for something in my game.

 

Anyways here's the code:

--detects if the character hits a wall by its side or its top.
function colision_detect(event)
	if(event.object1.myName == "tile" and event.object2.myName == "character") then
		if(event.phase == "began") then
			if(event.object2.contentBounds.yMax > event.object1.contentBounds.yMin) then
			print("collided horizontally")
			else
			print("collided vertically")
			end
		end
	end
end
Runtime:addEventListener("collision", collision_detect)

It's basically comparing character's y value when collision happens.

The code that I wrote there only detects if collision happened on top of the tile or on side.

Doesn't work if they collide on the bottom side of the tile.

 

You could use the same method to detect if the character hits the stairs with his head, so that he can pass through them from below.

 

...or IF they collide on top, let the character stand on the stairs ELSE make him pass through.

You will have to make some exceptions, if the character is already on the stairs...shouldn't be a problem.

 

Hope this helps.

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?



[TOPIC: post.html]
#450

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

@kumarks102:

1. I think any tile engine would have issues with 10x10 tiles. It's just that there are so many more tiles than there are with, say, a 32x32 map. Rounding 32x32 down, there are approximately nine 10x10 tiles for every 32x32 tile, so if you have a map completely filled with tiles that fills an iPad screen with 32x32 tile dimensions (32x24 or 768 tiles) and you switch to 10x10, you'll have almost 8000 tiles on the screen. Moving the map will result in a frame drop because you're drawing and erasing tiles as needed, and, again, you're drawing and erasing a lot more tiles than you are with a 32x32 map. Potentially, when I complete the tilemap shader, you'll be able to move some of your tiles to a shader layer and they'll render much faster. You can follow the progress of the tilemap shader here: https://forums.coronalabs.com/topic/59174-making-a-tilemap-shader/

2. 1000 tiles is by no means to much for Dusk to handle. The most I've ever done is twenty-five million, so you're good ;).

3. Integrating Spine and other libraries isn't so much a "can Dusk do it" as a "can I do it". Dusk just builds the framework for you, and you're left to make the rest of the game. Spine objects can be inserted into Dusk layers, if that's what you're asking - I'm doing that in my game.

 

@carlos.rafael:

"some layer" will be the name of the layer. Also, custom properties on tiles will be placed in the "Tile properties" window in Tiled. Dusk then loads them and you can access them on the tile.

 

- Caleb




[topic_controls]
« Page 18 of 20 16 17 18 19 20
 
[/topic_controls]