ldurniat / berry Goto Github PK
View Code? Open in Web Editor NEWBerry is a simple Tiled Map Loader for Corona SDK.
License: MIT License
Berry is a simple Tiled Map Loader for Corona SDK.
License: MIT License
Unless you are planning to merge Berry into Lime2D later on at some point, I would recommend you make Berry a stand-alone repo. I’m also pretty sure the original author of Lime2D is inactive and wouldn’t be able to accept a merge even if that’s the route you want to take.
I would do this for two primary reasons:
This blog post has some really good information that goes into detail about forks.
You will have to contact GitHub support and tell them you want to detach the fork and make it a stand-alone repository.
So I'm looking to tackle this feature in PR #1 but some things definitely need to be taken into consideration.
The way a lua TP sprite is used is through the following methods:
local lua_sheet = require("path_to_TP_lua_file") (ie. require("my-PC.project.image.lua"))
local image_file = "path_to_image_file" (ie. my-PC/project/image.png)
local sprite_name = "name_of_sprite_you_wanna_use"
local sprite_frame = lua_sheet:getFrameIndex(sprite_name)
local imageSheet = graphics.newImageSheet( image_file, lua_sheet:getSheet() )
local sprite = display.newImage( layer, image_sheet, sprite_frame)
Not too complex really. Although to implement this into Berry some consideration needs to be taken.
We need to require the lua_sheet
somewhere and save it. Do the same with the image_file
. The sprite_name
will be used to locate the frame index of the sprite. Those three things are needed to add an object to berry.
If we add a addImageSheet
method to berry, it should save the image sheet somewhere that is only used for texture packer sprites. Since the sprites don't have anything to do with gid
, I don't think they should be grouped with Tiled image sheets, but it might be possible. Maybe have a variable like, map.TP_imagesheets
or something. We also may want to save the lua file somewhere to map as well. (ie. map.TP_lua_files
)
Once we have a method that adds our imagesheet our next step would be:
local imageSheet = map:addImageSheet(image_dir, lua_sheet) -- returns an imagesheet
At this point I assume myself and other users who are planning to use this feature will have multiple texturepacker image sheets and sprites loaded. Therefore we need a universal lookup across all imagesheets to find the frameIndex for a sprite name. (Ie. if you load 3 imagesheets and lua files, we need to search for a sprite name across all of these) So we would need to add another method to berry getSpriteFrame
. It would look like:
-- this assumes the imageSheet was added like so, map.TP_imagesheets[name] = lua_sheet
function Map:getSpriteFrame(sprite_name)
local spriteFrame
for name, info in pairs(map.TP_imagesheets) do
spriteFrame = info:getName(sprite_name)
if spriteFrame then return spriteFrame end
end
end
Then if we combine all the above adding a sprite using Texture packer should be simple.
local imageSheet = map:addImageSheet(image_dir, lua_sheet)
local sprite_frame = mapt:getSpriteFrame(sprite_name)
local sprite = display.newImage( layer, image_sheet, sprite_frame)
I will play around with coding this over the week, but my time is constrained currently. Adding these features turned out to be way more work than I initially thought!
Another useful suggestion. Definitely should consider making the example map, Corona files, etc. all in their own repo or folder perhaps. The main directory should just be berry.lua, the plugins folder, and the README.
If the code is put into an example repo, it will have to constantly updated as Berry as fixed or improvements added to it. This may be time consuming, but probably not.
So while I was overhauling the plugin system I noticed something. The label plugin has many of the variables referenced incorrectly.
Not just that the map.extension
property is not even used in Map:extend
. I’ll fix them, but it may take me a day or two.
So I’m overhauling how berry does property management for all types of containers: Objects, Layers, Maps, Tilesets, etc.
My goal is to copy properties directly to their designated tables instead of having to do weird lookups. Going to try my best to remove the findProperty
function as it will be deprecated and no longer needed.
I noticed the doc folder is gone. Not sure if that was intentional or not, but I think the project could benefit from some basic documentation. You should also include documentation for what properties a object/layer/map table contains. This will be useful for when people are creating (whatever kind of) objects to look at a table they can reference.
Ie.
local fake_object_json_data = {
gid = 1075,
height = 32,
width = 32,
name = "foo",
rotation = 0,
type = "blah",
visible = true,
x = 0,
y = 0,
properties = {},
}
So a lot of data has been crammed into this table and I think it’s getting very crowded. It’s time to cleanup and arrange the data into sub-tables. Also I’m going to change the variable name from image_cache
to cache
because initially it was for only images but I started to put more and more data types in there. It currently contains the following data:
All of these types of data need to be put into separate tables and referenced appropriately.
So it appears that the animation code is broken. Not sure if it was like this initially or because of some changes I made earlier. Regardless, here is what is happening.
In the README.md it says it’s possible to animate a sprite with the custom property isAnimated
for either an object or a layer. The object creation code checks for these properties successfully. The problem is that neither the object nor the layer contains the needed sprite data to animate the object. This is because when you use Tiled’s Animation Editor it exports all the animation data to the tileset. Thus, the object/layer needs to be linked to the tileset somehow.
Luckily it shouldn’t be too hard to fix. In fact, there doesn’t even need to be a isAnimated
property at all. I can simply check if the object gid is present in the map.cache.animations
table. If it is, then it’s an animated sprite automatically.
Maybe an older version of Tiled had different data structure for its animation stuff? That could be why it’s not working now.
Tiled allows a user the feature to export the map as either a JSON or lua file. Seems kinda silly that a lua library doesn't support a lua format. With that said, I'm not sure how much work it would take to incorporate this feature.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.