Dusk Engine

I’m currently trying to get rid of another wierd problem.

When my character lands on the edge of the platform (if one part of the character object isn’t touching the tiles), he will bounce back up a little.

If I print the character’s y value, I can see that he moves up a little when he lands.

It’s wierd, because I’ve set bounce to 0 on the character and the tiles.

This is problematic when it comes to sprite animations- when the character already lands, it still plays the falling animation.

I don’t know what could be causing this to happen.

The function that check if the character moves up/ down is fine. There is nothing wrong with the functions for playing animations.

The character actually moves up a bit after he collides with the ground tiles. If it’s not the bounce- what could it be?

Hi, I’m having problem when I remove the object from map (for example box)

with event.other:removeSelf() or display.remove(event.other)

then i move “camera” out  to the right and when i come back that “box” appear back on a map

@Caleb P:

Yeah I’ve recreated multiple brand new maps and reloaded everything from scratch and the problem still would occur exactly when I create an object layer. I would just create an object layer save and export and the flickers on the screen would go nuts, but if I delete the object layers or make the object layer at the very bottom the flickers 100% go away. If I move it up +1 layer they come back… I don’t mind filing a report to help get this solved, I will try to make the file as minimal as possible.

@luistheworm:

A good question… That’s because of the culling system. Every time a tile goes out of the screen, it’s completely deleted. No physics, no nothing. You have a number of options that will solve that:

  1. If your maps are small (1-2 screens optimal), you can completely turn of culling

[lua]

dusk.setPreference(“enableTileCulling”, false)

[/lua]

  1. You can lock tiles from being erased

[lua]

map.layer[1].lock(x1, y1, x2, y2, “draw”) – This means the chunk of tiles from x1,y1 to x2,y2 will never be erased

[/lua]

  1. If your maps are moderately small, you can use objects for physical things (they’re not culled)

@dima1:

That’s also because of culling. Not only does culling erase tiles when they’re no longer visible, but it also draws them when they enter the screen. You’ll likely need to lock them.

[lua]

map.layer[1]._lockTileDrawn(x, y) – A core method that locks a single tile at an x,y tile position

[/lua]

For example, if you need to lock a single tile that is at 55,3 tile XY, you’d use this:

[lua]

map.layer[1]._lockTileDrawn(55, 3)

[/lua]

  • C

I still don’t know what’s causing that “bounce” issue, but I’ve found a way around.

It’s not a problem for my project atm.

So unless someone else is having a similar problem I wouldn’t bother with it anymore.

Hi there! I’m very new, but I had a quick question about the camera bounds. I understand that it takes a bounds object, so you have to the xMin, xMax, etc. but are the x values in pixels or is it in tile coordinates? I’m having huge issues trying to figure out how to stop the screen from scrolling once it reaches the edges of the map. Do you have any suggestions for what I should make my values in order to set my bounds equal to the size of my map? Thanks!

Also (sorry!) is there a way to keep my player in the center of the screen? So far I have the player inserted in a tile layer with the camera set on them. The camera automatically moves so that the player is in the center of the y axis but a bit to the left of center for the x, but I would rather the character be center, and when I move the character up or down, the map won’t start moving until the character is practically off the screen (it’s not to it’s bounds yet) but it works fine when I move my character right to left. Any help would be appreciated!

@bridgettekuehn:
The xMin coordinates are in pixels, xMax are in tiles, yMin are in the default font point size for your platform, and yMax are in inches :smiley:
 
Not really; the coordinates for the bounds are all in pixels :). To set the bounds to the size of your map, it’ll be something like this (assuming your map’s top-left corner is at the top-left corner of the screen): 
[lua]
map.setCameraBounds({
xMin = display.contentCenterX,
yMin = display.contentCenterY,
xMax = map.data.width - display.contentCenterX, – Use map.data.width because that’s the “real” width of the map - map.width changes when culling kicks in
yMax = map.data.height - display.contentCenterY – Same here
})
[/lua]
As for your “player-in-center-of-screen” problem, are you scaling individual layers?

Edit: Sorry, it seems the forum software isn’t formatting my code correctly…

  • C

Okay I got the bounds working! Woo hoo! Thank you!

And to answer your question, no I don’t think I’m scaling anything (unless it’s automatically scaled or something). Should I be?

EDIT: I have been putting my player in a certain place instead of just on the screen, but when I altered it so that the player was just added to the screen at no designated x,y it worked fine. I’m not sure if there is something I’m missing maybe? It seems like wherever the player starts in relation to the map is where the player is kept. So for instance I had my player starting at -5, and my map starting in the bottom left corner, so my player was off center from the right, and the map wouldn’t follow up and down. Any advice would be helpful because I won’t be able to alter each map to start in the top right corner with the player in the top right corner! Thanks!

Update on that bounce issue (box 2d).

You can completely get rid of that bounce by displaying another rectangle/ image/ something (with a physics body), and position it on the same place as that corner tile or wherever the bounce is occurring in your case.

If there are more physics objects stacked on the same spot, they will have enough force to counteract the player or some other force that collides with them.

Please submit a bug if this is still occurring :slight_smile:

I just pushed the next version of Dusk, 0.1.3, to GitHub! You can now use !eval! to specify math equations, load map data without building, and use the MapCutter plugin to load up specific layers of a map.

Enjoy!

  • Caleb

@Caleb P:

Is it possible to make objects static? They keep falling down to the floor.

I want to create a door that floats in the air and disapears after a few seconds, but it keeps falling down :slight_smile:

Also, I think I’d be handy if tiles (not just objects) could have the ‘layer.nameIs’ function, so I can select the object and change it.

@Sneeuw

Select your door tiles on your tile set, and add a property with a name  physics:enabled and make the value  false.

It will float there, not affected by the gravity, and it won’t collide with other objects.

EDIT:

If you want them to be able to collide with other objects, you can add a property, name it bodyType  and write  static for the value.

Thanks, that works :slight_smile:

Can you please tell me why the masking isn’t correct of objects like:

corona.png

The white box just hangs (doesn’t fall like falling off a stairwell). I illustrated the problem with the red line. The tile is handled as a block instead of a triangle. The block has physics, it drops from the air and stops right there (see image)

(I also followed this tutorial of Tiled: https://github.com/bjorn/tiled/wiki/Using-the-Terrain-Tool)

I think I spoke too soon. That bounce issue is still giving me problems. I will eventually find a way around every time, but it’s starting to annoy me, that pretty much every time I implement something new to my game, this bounce issue is causing glitches with it!

Let me explain exactly what I mean by this “bounce issue”.

My character’s body is wider than one tile. Sometimes it stands/ collides on more tiles (the entire width of the body is standing on tiles), but sometimes only about half of the body width is colliding/ standing on tiles, while the other half is not (that other half is standing in air).

Here is the example of my character landing with a part of the width on the tile, and the other part in air.

If the character lands, with the entire body width on tiles, there is no bounce.

But if the character lands like on this image, then he slightly bounces up, in this case triggering the jumping sprite sequence while he appears on ground (standing sprite sequence should be playing at this time).

I really don’t know what is causing this bounce. Physics bounce is set to 0 on both the character’s body as well as on all the tiles.

I thought that it might be, because gravity scale is increased to 5.0 on the chracter’s body, but I’ve tried setting it back to default (1.0), and the bounce was still there.

Could it be somehow else connected to tiles?

I don’t know, I’m out of ideas here…

If anyone knows what could be causing this bounce, then please tell me, cause it’s a really annoying problem.

  1. Is the bounce noticeable to you, or is it only detectable because of the animation that is playing?

  2. How are you triggering the player’s jump animation?

  3. Does the player have .isFixedRotation = true? (I can’t see how you couldn’t…)

Here’s what I think is happening:

  1. Your player moves down to the tile at a fast speed

  2. The tiles don’t have enough force to counteract the player (only half of his physics body is on the tiles)

  3. He penetrates into the Box2D shape a bit

  4. The next frame, he has to be moved out…

  5. So he accelerates slightly upward

  6. Voila! The bounce.

You could try fixing this by making your jump animation only play when the jump button (or similar event) is pressed. Don’t know how you’re doing it, but it’s worth a try :slight_smile:

  • C

So the block is supposed to slide down that slope?

Yes, the slope tiles are getting handled as blocks. All tiles get handled as blocks, even if only half of the tile has a texture on it.

The transparent part will collide with other objects as well.

I don’t think there is a way to add physics to only half of the tile.

As far as I know Tiled doesn’t have that option, nor does the Dusk engine. Not at the moment…

What you could do to solve that problem is you could remove the physics body from the slope tiles, just make them float there, not colliding with anything.

And then display objects (rectangle or something), position them where the slope is, and rotate them to match the slope angle (Note that you can make those objects fully transparent, so they’re invisible and it looks like the objects are colliding with actual slope).

To get the coordiantes of the slope tiles, you can use map.tilesToPixels, instead of trying random coordinates till you get it right.

We discussed map.tilesToPixels a few pages back (Page 4 of this topic), if you need to know how it works.

Assuming you’re a Pro/Enterprise subscriber, you can use png2box2d to get an accurate shape:

http://coronalabs.com/blog/2014/01/28/tutorial-create-physics-bodies-from-texture-assets/

The bounce isn’t noticeable to the eye, you can’t spot it.

But it is there, cause the output terminal says that the character is moving up, it’s a really small bounce, that always lasts for 4 frames (at 30fps).

How do I know when the character is moving up? I’m using a function similar to the one that you’ve helped me with when I was looking for ways to check if the character is moving down. (the function that makes character.prevY- a made up variable same as character.y- actual y value , and then compares them, and when character.y is smaller or larger than character.prevY, it detects).

That function is okay though.

Yes, character does have .isFixedRotation = true.

The jump animation is triggered when the character moves up, and only allowed when the player hits the jump button, and the character is standing on the ground. 

However, if the character bounces up, and if the player hits the jump button right at that time, the animation will trigger, but the character won’t jump.

It’s a glitch that I noticed when I was playing around with the game on my phone.

Yes, I will most likely fix this by adding some boolean variables (true/ false), but I’d rather get rid of this bounce, as it will most likely give me more problems in the future.

  1. Your player moves down to the tile at a fast speed

  2. The tiles don’t have enough force to counteract the player (only half of his physics body is on the tiles)

  3. He penetrates into the Box2D shape a bit

  4. The next frame, he has to be moved out…

  5. So he accelerates slightly upward

I remmeber this was happening all the time, before I started using tiles. When my character was just walking and jumping on a rectangle that was serving as ground. I can’t remmember what were the physics properties of that rectangle though.

Can I get rid of this bounce by changing physics properties of tiles or character’s body?

Increase the density of tiles or something?

@tilen.curin:

Thank you for that answer. Your answer will do, but I really wonder how so many people create games and make the masking possible. Perhaps they used the same trick, but I doubt that.

@Panc software:

No I am not (look at my profile ;)). I just program things in Corona as a hobby. Though, I do have my own software company but its specialized in almost any WEB2.0 programming language.