Dusk Engine

Think i figured it out…

centerX, centerY = map.getViewpoint() top = centerY - (screenH / 2) bottom = centerY + (screenH / 2) left = centerX - (screenW / 2) right = centerX + (screenW / 2)

Beat me to it :slight_smile:

That’s correct. Just remember there’s also the property “display.contentCenterX” which is basically the same as screenW * 0.5 and “display.contentCenterY” which is screenH * 0.5. So maybe:

[lua]
local centerX, centerY = map.getViewpoint()

local top = centerY - display.contentCenterY
local bottom = centerY + display.contentCenterY
local left = centerX - display.contentCenterX
local right = centerX + display.contentCenterX
[/lua]

  • Caleb

Is there any videos on Youtube or such, where you could see Dusk Engine in action or “getting started tutorials”?

Thanks for confirming that Caleb  :slight_smile:

I just started playing around with Dusk, and tried to build a map from tiled with an isometric orientation. Does dusk not support this? As I can not seem to get it to work…

First… I’m sorry. This same thing has been asked and aswered again and again, but I’m still stuck with this :wink:

I’m using Tiled and Dusk. I can add physics to objects, but not for layers (tried tiled layers and object layers). Here is a screenshot what I’ve tried. Please, check to layer properties. “tiles” layer shoud be the collision/platform layer. I’ve set physics.setDrawMode(“debug”) and as you can see, the layer has no physics at all. I tried to declare bodytype using tiles-prefix and without it.

Thanks in advance!

[sharedmedia=core:attachments:3480]

 

@havochare4:

Unfortunately, Dusk does not support isometric maps right now. Sorry :(.

@Aatos Media:

Sorry about that; fixed.

  • Caleb

I don’t know if this is related to dusk… but when moving a character (Retro style pixel look) over the screen by adding x=x+1 and y=y+1 and make the camera following the character things look very good, sharp and the movement is steady.

BUT when the character is moved with x=x+0.5 and y=y+0.5 or other point values for example the camera movement begins to move in small steps (stair effect) which can be irritating on the eye. The character sprite then also is not sharp anymore but blurry which is looking wrong.

Any ideas on how this can be optimized, fixed?

Any help welcome!

I was waiting for something like that to happen. That’s a consequence of camera rounding. When I added camera rounding, that made Dusk’s camera system able to move at minimum in single-pixel increments. It was the fractional pixels that were the main problem with tile flickering, but now when you need fractional pixels, you don’t get them :P.

Fractional pixels cause a lot of problems if you don’t have access over rendering. IMO, you should stick with full pixel movement. Your character is looking blurry because of fractional pixels. The tile lines were occurring (majorly) because of fractional pixels. If you need smaller movement increments, you can scale your stage down and your graphics up (retro/pixel graphics are easy to scale) so that what was previously a 0.5px movement can be a 1px movement.

Of course, you could also modify Dusk to stop rounding camera positions, but that would bring flickering tile lines back. Every action has an equal and opposite reaction :P.

  • Caleb

Thx for your fast feedback Caleb!

Because I’m working with bigger tiles the flickering lines shouldn’t be a problem. So I think stopping the rounding camera positions should be the best option here.

Can you please give some tips on how to do the modifications to stop the camera rounding please?

Daniela

UPDATE: I totally forgot the change was so easy… :slight_smile: … I found the line to change and turned off the rounding. The line was:

dusk.setPreference("experimental:roundCameraPosition", true)

That’s correct for versions prior to the one on GitHub, but if you get the most recent one and can’t figure it out, that’s because I made camera rounding always happen. All you need to do in that case is find lines 95-96 of Dusk/dusk_core/run/camera.lua and take out the math_round() call.

  • Caleb

Ah… okay. Thx for the info!

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