kinome79 Posted February 21, 2023 Share Posted February 21, 2023 So, learning Pixijs by building a game... created my ship, and it flies around with an asteroid like dynamic, leaving me to track its x and y velocities, if its accelerating, turning, firing, etc. I usually build a class for this, but the following seems to work for my purpose. let ship = PIXI.Sprite.from('images/sprite.png'); ship.width=50; ship.height=20; ship.speed = .2; ship.rotspeed = .07; ship.xvel = 0; ship.yvel = 0; ship.rotating = 0; ship.accelling = false; ship.braking = false; ship.shooting = false; This seems to work just fine, and my ship is flying around without issue. Tried searching if this is OK, I mainly find implementations of set/getAttr, creating classes, etc. I haven't tried the same thing with a method yet ( ship.explode = () => {} ) but can almost imagine that will work too. Thoughs? Is this going to lead to problems down the road? Quote Link to comment Share on other sites More sharing options...
kinome79 Posted February 21, 2023 Author Share Posted February 21, 2023 And sorry about the way the code looks... seems perfectly fine in my edit window, no additional spaces or chars I can find, but the result has extra lines and spacing. Weird. Quote Link to comment Share on other sites More sharing options...
Yurii Bilas Posted March 1, 2023 Share Posted March 1, 2023 Hi, @kinome79! Your code is perfectly fine for a beginner. You can do like this while you learn. Also it will be ok to do so when you're just prototyping a new project and not taking it serious. But after some time, when you'll want to progress in development or make make big complex projects - it will become a little bit hard to maintain such code style. For big projects you'll probably need more of OOP, classes and stuff. Hope this helps! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.