Dusk Engine

@maxpayne2877:

Please file an issue on GitHub for this, thanks :slight_smile:

@tommowas:

FPS means “number of times the game updates in a second”, obviously. So a 60FPS game gives the code ~16 milliseconds to run all its stuff each frame. If the code takes longer than that, the frame has to be delayed and you get a lag. Simple enough.

A 30FPS game, on the other hand, gives a game ~33 milliseconds (twice as much) to do it’s frame stuff. So there’s a lot more leeway for lag. Something has to take twice as long to make the game lag. Of course, this improvement comes at the cost of not as smooth animation and movement and such.

So, when you make a game at 60FPS, sometimes you need to optimize things to keep it running smoothly. If your lag is more than just a “click” every now and then, it’s probably not Dusk, but your game code. What’s your lag like?

  • Caleb

im familiar with fps, sorry if i didnt make that clear.  most likely issue with optimizations with my code, thanks for your explanation. i was just wondering why dusk could not be set to 30fps instead of 60fps in the settings i see now dusk requries the higher frame rate…

thanks again

Hi Caleb,

The tileset I am using has a purple background, so when I imported it into Tiled, I chose it as the transparent color and proceeded to make my map.

I loaded the map into my project and it worked, except that the background color was still showing.

I noticed in the .json file there is a part that says the value of the transparent color, but is there already a way in the engine to make this color transparent?

Thankyou in advance.

Unfortunately, Corona doesn’t allow us to do that. You’ll have to use an image editor like Pixelmator to edit out the purple color. Many bitmap editors come with a “Select Color” function, which should do exactly the same as what Tiled does.

  • Caleb

Ok I will do this, thankyou for the quick reply!

Hi, could anyone lend a hand with a question about player position?
 
This is my code:

----------------------------------------------------------------------------------------- -- -- level1.lua -- ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() display.setStatusBar(display.HiddenStatusBar) local physics = require "physics" physics.start(); physics.pause() local textureFilter = "nearest" display.setDefault("minTextureFilter", textureFilter) display.setDefault("magTextureFilter", textureFilter) -------------------------------------------- -- forward declarations and other locals -------------------------------------------- local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth\*0.5 local crate local grass local button local map local dusk = require("Dusk.Dusk") map = dusk.buildMap("map.json") ------------------------------------------- function scene:create( event ) ------------------------------------------- local sceneGroup = self.view local crate = display.newImageRect( "crate.png", 90, 90 ) crate.x, crate.y = display.contentWidth/2, display.contentHeight/2 crate.rotation = 0 crate.speed = 250 crate.isFixedRotation=true crate.id = "crate" crate.title = "crate" crate.anchorY = 0 crate.anchorX = 0.5 map.layer[1]:insert(crate) physics.addBody( crate, "dynamic", { density=1.0, friction=0.3, bounce=0.3 } ) map.setCameraBounds({ xMin = display.contentWidth/2, yMin = display.contentCenterY, xMax = map.data.width-(display.contentWidth/2), yMax = display.contentHeight-display.contentHeight/2}) map.setCameraFocus(crate) map.setTrackingLevel(0.1) local grass = display.newImageRect( "grass.png", screenW, 82 ) grass.anchorX = 0 grass.anchorY = 1 grass.x, grass.y = 0, display.contentHeight local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 } physics.addBody( grass, "static", { friction=0.3, shape=grassShape } ) local button = display.newRect( 0, screenH-30, screenW, 30 ) button.anchorX = 0 button.anchorY = 0 button:setFillColor( 0.2, 1, 0.2 ) button.id = "button" local function onObjectTouch( event ) if event.phase == "ended" then crate:applyLinearImpulse( 10, 0, 0.5, 0.5 ) crate.angularVelocity = 0 print("button hit") return true end end button:addEventListener( "touch", onObjectTouch ) function onEveryFrame( e ) map.updateView() end Runtime:addEventListener( "enterFrame", onEveryFrame ) sceneGroup:insert(1, map) sceneGroup:insert(2, grass) sceneGroup:insert(3, crate) sceneGroup:insert(4, button) end ------------------------------------------- function scene:show( event ) ------------------------------------------- local sceneGroup = self.view local phase = event.phase if phase == "will" then elseif phase == "did" then physics.start() end end ------------------------------------------- function scene:hide( event ) ------------------------------------------- local sceneGroup = self.view local phase = event.phase if event.phase == "will" then physics.stop() elseif phase == "did" then end end function scene:destroy( event ) local sceneGroup = self.view package.loaded[physics] = nil physics = nil end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene

The tiled background moves within limits set by map.setCameraBounds but the crate moves across the screen rather than being in a fixed position with the background tiles moving. I’m using ‘map.setCameraFocus(crate)’ and I’ve tried it in a number of positions but I can’t fix the crate in the centre.
 
I’m using composer here too and I’m not sure if I’ve put dusk/tile-related elements in the correct places.

Thanks for any help - I’m pretty stuck.

You need to have your crate and any other objects you want to move inserted into the map.

On line #47, you’re inserting the crate into the map, but on line #88, you’re re-inserting it into the scene group. In Corona, re-inserting means “un-inserting and then inserting into another group”.

  • Caleb

Thank you!

Glad I could help :slight_smile:

  • Caleb

I’m having an issue with the grass platform layer now (lines 56-61 in my last post). I’d like that to act as a platform but although the image stays on the screen, it seems its physics area scrolls with the background and eventually the crate falls over the edge.

I’ve tried adding the grass to a gui.front display group with the map in gui.back as per the Bob Dusk demo, and I’ve tried adding a rectangle shape layer in the tilemap with the properties:

physics:enabled - false

bodyType - static

so it doesn’t fall, but allow collisions - nothing seems to make a difference.

Could anyone point out where I might be going wrong?

I’ve even tried putting the grass.x and .y values in the enterframe function with the physics.addBody line but it’s the same.

Many thanks

Is the grass in the same group as the crate? It needs to also be in the map.

Also, physics:enabled should be set to “true” for physics to be added.

  • Caleb

Great, thanks once again Caleb.

I used physics:enabled - true to add a floor within the tilemap.

I was trying to have the grass static on screen (I guess it would need to be outside the map in that case?) but still act as a floor and stop the crate falling. When the grass is in the map it moves and the crate fall over the edge, but if it’s not in the map the image remains fixed whilst its physics scrolls with the map (although with debug enabled it doesn’t look like that’s what’s happening…)

Anyway, the tilemap object floor works a treat! Thanks.

Another approach you can do is take a look at Corona’s “JungleScene” sample code (“CoronaSDK/SampleCode/Sprites/JungleScene”); the way they do it is with two separate images that come past to make a seamless scrolling ground.

 - Caleb

Many thanks for your advice.

Is there a sample available which shows how to use a simple RPG like birds eye map from tiled with dusk? I really could use a sample showing a map created in tiled with some grass, a sprite character and some trees. :slight_smile:

Thx for your help!

Daniela

Unfortunately, no. Just Bob, which is moderately similar. It’s like a top-down maze game demo (I’m sure you’ve already seen it, though).

https://github.com/GymbylCoding/Dusk-Engine/tree/master/Demos/bob

  • Caleb

Can you please explain this more in detail Caleb? I still can’t figure out how to do this.

UPDATE: I did it! :slight_smile: … added a 1px border around the image sheet and a 2px space between the tiles in the sheet. I then filled the empty space between the tiles with an expanded border of each tile and now I don’t have any more gaps when scrolling around the map.

But I still have a question: How can I show animated tiles on a map?

local tile2 = map.layer["tiles"].tileByPixels(eventposX, eventposY)

When using this code to get the coordinates of tiles it only works if I do not use the camera! When I position the camera on the player the map is moved and the moved distance is not calculated in the tile detection which results in the wrong tiles being detected.

How can I use the code above to get the right tiles AND use the camera features?

Thx for your help!

Daniela

I’m assuming eventposX and eventposY are touch event position coordinates? If so, you need to first use Corona’s contentToLocal function to transform the touch position to the “real” pixel position in group coordinates:

[lua]

local localEventX, localEventY = map.layer[“tiles”]:contentToLocal(eventposX, eventposY)

local tile2 = map.layer[“tiles”].tileByPixels(localEventX, localEventY)

[/lua]

  • Caleb

@d.mach: Good to hear you figured it out :)!

Dusk doesn’t currently support animated tiles. This is a feature on the roadmap, but I’m not sure when I’ll be able to add it. Dusk is open-source, though (hint, hint :D)…

  • Caleb