Hot answers tagged

3

This is a very hard question to answer since there are many things which come into account when you have to deal with these things. What I usually do, is that I set up an array for all my enemies. Each enemy is basically an object with values such as their coordinates, direction, sprites etc., and what's most important, a draw() and an update() function. ...


3

This is one way on how to do it and might not be the best, there should be some other way. If you want to change the speed according to where the ball hit the paddle you could do it like this: You calculate the ball's x position and the middle position of the paddle (x coordinate too of course). For the formula, you could do it like this: speed = ...


3

The line animation["Sword Slash"].wrapMode.Once doesn't actually do anything, and that's why an error is generated, to help you. Maybe you meant to assign by calling animation["Sword Slash"].wrapMode = WrapMode.Once?


2

If you handle input directly from the OS's event callback (or similar platform events), you generally only have access to the data the OS gave you for that event. That data usually only pertains to the immediate input action (pressing this key or moving the mouse on that axis, and maybe some information about what modifiers were down). This can make it ...


1

You can make an invisible copy of your ball which you update for as long as it didn't reach the paddle. Here's an example: Suppose you have a ball class which looks something like this: function Ball(x, y, size) { this.x = x; this.y = y; this.size = size; this.vx = 0; this.vy = 0; } Ball.prototype.update = function () { // Move the ...


1

Simple solution: Have the paddle always move towards the current horizontal position of the ball. When the x-coordinate of the ball is larger than the x-coordinate of the center of the paddle, move it right, otherwise move it left. Better solution: Extrapolate where the ball will reach the finish-line and have the paddle move towards that point. In both ...


1

Whether you handle input through callbacks or in the game loop have their advantages and disadvantages: Using callbacks: this method make sure to detect any key the user press ,or any other form of input. Being an asynchronous event, any callback is fired at any time, granting real-time input detection. CONS: user input may affect your simulation at any ...


1

When in doubt: Fake it. Instead of calculating the wheels from where the cart is, calculate the wheel direction from where the wheel was. Something like this: //Constants, per wheel. I'm assuming Y is up/down var wheelOffset = Vector3( -40, 0, -10 ); //Variables kept over multiple frames, per wheel var wheelAngle = 0; var lastWheelPosition = 0; //Per ...


1

My answer contains the following assumptions: You want to get the the x,y-coordinates in order from the upper left to the bottom right, even if your viewport overlaps the map. If it overlaps, you want to look at the repeated map. Your viewport does not exceed the size of the map. var mapDimensions = {x: 20, y: 20}; // Width of the map var ...



Only top voted, non community-wiki answers of a minimum length are eligible