wise9 / enchant.js

A simple JavaScript framework for creating games and apps
http://enchantjs.com
MIT License
1.69k stars 314 forks source link

An issue where map is not displayed properly on other surfaces #287

Open lyonbeckers opened 10 years ago

lyonbeckers commented 10 years ago

Because the map object uses the game's core as a reference for width and height, it creates display problems for surfaces larger than the game's core. This causes odd scaling behaviour, where the map's display will not be scaled, but the dimensions of the tiles will be (so at 3x scale, a collision tile that was at (32,32) will collide at (96,96) appropriately). As far as I can see, the map object is the only object that does not behave appropriately to scaling.

lyonbeckers commented 10 years ago

I've managed to get the map to display fully in the larger surface by passing a third argument to the map object which stores a rectangle object, and doing a search and replace for all instances of using core.width and core.height, and using the rectangle's width and height instead. This does not affect the scaling of the map object, however.

I'd recommend committing a third argument that stores either the rectangle data (as I've hacked together), or the target surface area, and making the map utilize its scaleX and scaleY values to make the map object that much more modular and versatile (as far as I can see, even if you were to set core.scale, only a scale of "2" seems to scale it, unless I'm mistaken).

ndimola commented 9 years ago

I'm working on a Wii U game at the moment that leverages enchantJS and specifically the Map, as it provides the best performance on the system for my needs. However, this issue is impacting my release and I'd like to work on fixing it, but could use some direction before digging through the Map code.

Essentially, when the scene is scaled, I'd like the Map to scale accordingly, like Sprites, Labels, and other enchant objects behavior (which seems to be the nature of the reported issue above). Does anyone have a good starting point to jump in here?

ndimola commented 9 years ago

So, last night I dug into this and made modifications to the redraw function to respect the scale value of either the map or its parentNode (with the map's scale value taking precedence). Based on my personal use case, it's working as intended now; however, I have no idea if my solution is appropriate to commit as I'm not really sure if the approach aligns with the rest of the project, nor do I know if it behaves appropriately in all use cases.

Any suggestions on next steps? I'd love to help out any fellow enchant users who are experiencing the same problem, but I definitely need the guidance of the official team before I do anything.