New answers tagged

1

I have it :) var blockHeight = 15; var blockWidth = 30; var zoom = 2; for (var x = 0; x < 10; x++) { for (var y = 0; y < 10; y++) { var screenX = Math.floor((x * (blockWidth * zoom - zoom * 2) / 2) + (y * (blockWidth * zoom - zoom * 2) / 2)); var screenY = Math.floor((y * (blockHeight * zoom - zoom * 1) / 2) - (x * (blockHeight * zoom - ...


0

You start in the middle, and move to the edge, until x <= 80, at which point you flip the direction of acceleration. Then you move to the opposite edge, until x >=100, and you flip the direction of acceleration. The cause of the problem is this: In the first run, you move from the 10 units from the centre before reversing. That means you have a runway of ...


0

When you hit the boundaries, you change the direction of the acceleration, but you do not set the velocity to 0. That means at the boundaries, the food will continue to move in the same direction, but slower and slower until it changes directions (when it's far past the original boundary). I assume you want the swaying effect from acceleration, but if you ...


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?


0

All it does is make the 'breathAmt' variable travel go up and down between 1 and -1 over time. This gets combined with the next snippet of code, about a few paragraphs down on the page: function redraw() { canvas.width = canvas.width; // clears the canvas drawEllipse(x + 40, y + 29, 160 - breathAmt, 6); // Shadow context.drawImage(images["leftArm"...


0

javascript has a random method as part of the Math package: Math.Random(); This produces a decimal random number 0 < 1 To get a specific range use some basic maths: Return a random number between 1 and 10: Math.floor((Math.random() * 10) + 1); (All taken from w3schools : http://www.w3schools.com/jsref/jsref_random.asp)


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 ...


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 ...


0

I'm not sure what you want to achieve. You could avoid pausing the game when it is out of focus: game.stage.disableVisibilityChange = true; or given the latest position of the bullets just update them when the game is unpaused. In this case is possible that the bullets have hit something/someone and no longer exists, but the general idea is to update the ...


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. ...


0

I'm guessing your using plain Javascript with no engine. You could just hold off drawing your objects to the screen. If you put all of your game objects in a function then you could hold of rendering them until someone click continue. After that condition is met then the render of all your object can happen. There you go. A nice simple start menu. Was this ...


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 = ...


0

Well, that's a tricky question but i'll start from the begining. Get/Put imageData is faster than you think, but if you want to do it in a efficient way i'd recomend you to build a double buffer and rasterize your shapes in it (here's a double buffer module i wrote, have a peek). Estrange shapes' shadowing is as hard to do as rectangles shadowing, you only ...


0

You are not setting jumping to false anywhere so it will be true forever,change this: if (y=area.canvas.height - 200){ player.image.src="man.png";} else{ to this if (y=area.canvas.height - 200){ player.image.src="man.png"; jumping = false; }else{ Also, is not a good idea using "y = area.canvas.height - 200", i would do <= instead, what if the ...


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 ...


0

You should move the call of timer.start() to be before your call of gameLoop(). You should also make a call to it right after the call of timer.reset().



Top 50 recent answers are included