Hello guys, below I attached a project. Actually it is not a real project, just some stuff I am trying all together and as you guess I have some problems
1) Camera.lua : This is a Camera class that I modified from ar2rsawseen's appcodingeasy tutorial and also added parallax scrolling to it which works fine now. What I am also trying to do is also adding a zooming option but somehow I am having difficulties with converting coordinates when zoomed. If you take a look I'll be glad.
Look for Camera:setZoom(zoomLevel) at line 107
2) Player.lua: This is the default Player spawn Class. What I am having here is , when I try to move the Player at line 54
( function Player:move(dir) ) with linearVelocity somehow gravity does not work, when I switch to LinearImpulse it works fine.
3) And last but not least I couldnt manage how to make KeyPresses work so I did a dirty trick with dispatching events with
onMouseDown and onMouseUp in button.lua and I am sure this is not a good approach.
If you can examine and give comments I'd be glad. Btw anyone can use Camera stuff if needed , no needed to mention
Thanks
Comments
1) Well its understandable camera won't move accordingly, I'll check it more deeper and provide a solution later
2) Well that's easy. Problem is that you are constantly calling Player:move and you are constantly setting linearVelocity or LinearImpulse. The difference between them is, that LinearImpulse takes into consideration current object speed and applies force to it, while linearVelocity completely resets it. So basically your object gains speed by falling, but you constantly reset it to 0 by setting linearVelocity.
3) I didn't really understand that. I saw an offclick event. Do you dispatch an event when player finishes pressing button? You could simply add a mouse down event to your button directly by yourself, without modifying the button.lua code
All in all suggestions. Never do something like that:
You see what happens here, is that you have a class, and then you throw it out away and replace with class instance.
For now, you have one scene, but when there would be multiple scenes and you'd transition through them, next time you go back to this scene, there won't be Camera class anymore, because you have replaced it. Same applies to couple other instances.
And don't call applyLinearImpulse or setLinearVelocity without the need for it (like you do with 0), check before if you need to apply them and only do that if needed. Because box2d actually is a huge resource eating monster (comparing to Gideros) and you'd want to mess with it as less as possible