Adding a controllable character to a scene with physical objects

Hello Graham and fellow beta testers,

I am trying to figure out the best way to organize my program to include a controllable character.

Should my character sprites by included in a separate layer in tiled?
How can I act on bodies once they have been loaded into lime? Say for example, if I wanted to make one of the boxes in tutorial 3 jump when I tapped the screen. Would I give that tile a special name in the properties, then every time I wanted it to jump, I would loop through all the tiles to see which tiles had that property and then do something like this to the tile or body:

jumpingTile:applyLinearImpulse(0, -.3, jumpingTile.x, jumpingTile.y)

http://www.justaddli.me/tutorial.php?t=0&id=3

Also, I’ve been able to add a sprite w/a dynamic physics body to the end of tutorial 7 (just using physics.addBody to the scene. For what ever reason this new sprite will collide with the static platforms but not the falling tiles.

Anybody have any ideas or sample code I can look at while I try and figure things out/wait for the next tutorial.

Thanks in Advance,

Mike
[import]uid: 12267 topic_id: 4487 reply_id: 304487[/import]

For the character sprites, I would have them on a layer by themselves, this may not be the best way (and certainly not the only way) it is just the way I would do it. This is so that you can then have correct z-depth layering of things such as foreground and background items.

Rather than looping through all the tiles on every tap to check for a property, you could use the Object Listener stuff to create your jumping crates, that way on every creation you would be able to store off a reference to the objects.

As far as the dynamic physics object goes, it might be to do with collision filters if you have those set, other wise feel free to email me the map file (and any tileset images etc and code) and I will gladly take a look at it for you. [import]uid: 5833 topic_id: 4487 reply_id: 14071[/import]

I got my character into the scene moving around. I made a new layer and added “character” as one of my tile properties in TILED. It is animating a jumping around. Very cool.

I was wondering a few things:

  1. Is it currently possible to set the shape of a physical body associated with a tile? I know this is possible in corona, but wasn’t sure if it was implemented in lime yet. I either want to make the body shape a circle or a complex polygon.

  2. Is there a maximum file size that can be loaded with lime/corona? I am trying to load in a character that is about 3 tiles wide by 2 tiles high. Each tile is 64x64.

  3. Something I noticed when loading in my large character images in Tiled: The way they are initially positioned in lime is different than how they appear in Tiled. The position is close. I think it might be an issue with how lime initially lays out the scene if things added aren’t multiples of the grid size?

  4. When using the new 0.2 beta version, after my character got a certain distance down the map, the sprite texture disappeared but the physics body stayed the same.

You can check the progress here:

http://www.sendspace.com/file/it8di0 [import]uid: 12267 topic_id: 4487 reply_id: 14093[/import]

Hey Mike, awesome that it is all working and jumping :slight_smile:

  1. Currently polygon shapes aren’t supported yet that is something that I am literally currently working on :slight_smile:

  2. I think there is a maximum file size for Corona (well for the hardware anyway) but your tiles should, I think, be fine.

  3. I will look into the positioning as well, make sure it is all pixel perfect.

  4. I think this might be to the experimental chunk stuff messing up, I will have a look. [import]uid: 5833 topic_id: 4487 reply_id: 14099[/import]

Just loaded up your platformer, looking pretty cool. That is a giant rat :slight_smile:

I haven’t managed to get the rat to disappear yet apart from just jumping way to high. [import]uid: 5833 topic_id: 4487 reply_id: 14100[/import]

I also forgot to say, you must remember that the X and Y position of an Object in tiled is actually its TopLeft position, so for instance if you use it to set the position of an image like this -

  
local onObject = function(object)  
 local test = display.newImage("Guy.png", object.x, object.y)  
end  
  

The image will seem out of place as you have told it where its top left corner should be rather than the centre, to set the centre position you should do this instead -

[code]

local onObject = function(object)
local test = display.newImage(“Guy.png”)
test.x = object.x
test.y = object.y
end

[/code] [import]uid: 5833 topic_id: 4487 reply_id: 14101[/import]

I have just uploaded a new version of the code (check the Beta updates thread for the link) as well as a new tutorial to go along with it - http://justaddli.me/tutorial.php?t=0&id=8

You can now have circular bodies as well as ones built from a single shape, multiple shapes are coming soon. [import]uid: 5833 topic_id: 4487 reply_id: 14175[/import]

cool, is there a new way to move the map world in the new beta version?

used this in beta 0.1 and it works:

map.world.x = 100

I am using the exact same code in beta.3. The physics bodies are moving but not the graphics.
also, I am calling this at the end of my program:

local onUpdate = function(event)
lime.updateMap(map)

end

Runtime:addEventListener(“enterFrame”, onUpdate) [import]uid: 12267 topic_id: 4487 reply_id: 14186[/import]

Whoops, my bad. Again :slight_smile: Was to eager to get the code out and forgot to set a single value back to true :slight_smile:

Please download the updated lychee.lua here - http://dl.dropbox.com/u/571145/lychee.lua - and just overwrite the previous one with it. [import]uid: 5833 topic_id: 4487 reply_id: 14189[/import]

map moves now in sync with physics , however after moving a screen and a half to the right, new bg tiles don’t show up. Quick fix: drag physics .3 into beta build .1 [import]uid: 12267 topic_id: 4487 reply_id: 14190[/import]

Ok thanks, I think I many know what is causing the problem but not sure of the solution yet, could you send me your project file so that I can reproduce the error? [import]uid: 5833 topic_id: 4487 reply_id: 14191[/import]

http://www.sendspace.com/file/9t311b

top of screen jump

bottom left and right [import]uid: 12267 topic_id: 4487 reply_id: 14192[/import]

Just added in an updated version that will fix this. Basically rather than using map.world.x and y to move the map, instead use -

map:move(x, y) [import]uid: 5833 topic_id: 4487 reply_id: 14281[/import]

Cool, I am eager to integrate new lime versions into my game.

I’ve made some progress on my game with the old beta: Tortise,Rat, Pigeon, Trout
FYI, it is much better than before:

http://www.sendspace.com/file/o9t20p

There are a few things that I don’t understand about Lime that could help take it to the next level:

  1. an example of how to use listeners to detect a collision between the character and the ground objects.
    This could help me prevent the problem of “double jumping” in a platformer

  2. some help on making my physics bounding box match the shape of the character(s). I tried to apply the latest physics tutorial to a tile, instead of an object, with no luck.

  3. Is it possible to add all of the animals to one container object, and then rotate the container object and the position of each animal, instead of repositioning large sprites over and over again?

Really enjoying not having to get super dirty in code, thanks to Lime.

Thanks for all the work,

Mike [import]uid: 12267 topic_id: 4487 reply_id: 14286[/import]

Glad to see it is progressing and that you are enjoying Lime along the way while also finding ways to improve things!

  1. I think that sounds like a great idea for a gameplay-specific tutorial, I will do that one very soon.

  2. I think you will want to read (once it’s ready) the next physics tutorial, as that will show you how to use multiple shapes to build up your physics body.

  3. You could add all your objects a group and then rotate that, something like this:

[code]

local group = display.newGroup()

group:insert(image1)
group:insert(image2)
group:insert(image2)

group.rotation = 90

[/code] [import]uid: 5833 topic_id: 4487 reply_id: 14287[/import]