New answers tagged

0

I found out why it was not working... I needed to do this: layer.fixedToCamera = false;


4

Since we are unsure what the game or rendering library is, I have commented the code to tell what I think it does. It appears to make rain drops. var max_bollar = 15; // Lots of setup - should be explanatory. Skip to update() var i = 0; var timecounter = 0; var bollarcounter = 0; var spawn_delay = 5; var min_spawn_delay = 25; var max_spawn_delay = 500; var ...


0

If you create rectangles for the tiles, the origin is not from the left upper corner, they start from the middle. if you create a tile in Phaser and set his position to x:0,y:0 with 32*32 size it is only 16*16 large, because you need to set it at x:width/2, y:height/2


-2

layer.position.set(this.game.world.centerX, this.game.world.centerY);


0

The ups of the "storing texture in atlas" would be, that you can assign textures dinamically. E.g. you hve your dungeon brick tile on the 0;0 coordinates on your image. If ypu put the 0 id on the array where the tile goes, then instead of harcoding it in, you can just do texX = (i * texSize) % imageWidth texY = Math.floor(i * texSize / image.width) * ...


0

Create an array to hold all the balls: var balls = []; When you spawn a ball, include it on the list: function spawn(i) { var boll = {x: random(totalWidth), y: random(totalHeight)} circle( boll.x, 10, 10, "blue"); timecounter = 0; bollarcounter++; max_spawn_delay = ( random(max_spawn_delay - min_spawn_delay ) + min_spawn_delay ); ...


0

Add the balls to the list in update() iterate over the list and update each ball's y position


0

How can i make the object spawn til i say stop and spawn at difrent times You have two different questions there. One is how you can make the object spawn until you say it to stop. The other is how to spawn them at different times. It is not very clear to me what you exactly mean regarding the first part. If you just wanna learn how to make a "while ...


0

This will execute the same function every 2 seconds change the delay to change how often the function is called and set carryOn to false to stop calling the function every "delay" number of milliseconds ... var delay = 2000; var maxDelay = 4000; var carryOn = true; setTimeout(stuffToDo, delay); function stuffToDo() { //whatever code you want here ...


-1

To answer all your questions: The two languages supported by unity are currently javascript and c#. In unity 4 was a 3. one, boo, but like 5% of the developers used that language, so they removed it to be able to focus on other aspect of the engine. javascript Don't let the name confuse you, this is really far from the pure javascript. Unity provides some ...


0

I created a simple platformer that used rectangle collision in order to detect if the player is currently colliding with a tile. I made the game in c# but I believe the concept will be the same for Javascript. Here are the steps I took: 1: Create a new class named Tile 2: Generate a list of Tiles in order to fill up the tilemap 3: Run a loop through each ...


1

I asked just this question on SO a while ago, same language aswell, and no one didn't really care, so when I found the solution I didn't really bother to put it up there, but now more people are interested and I am glad for that, so now I will post the answer here. Here's my original code, it's the exact same thing as yours, just a bit more clear of what ...


0

Similar to RDeving's answer, here's my usual code: var keys = {}; window.onkeydown = function(evt) { keys[evt.keyCode] = true; } window.onkeyup = function(evt) { delete keys[evt.keyCode]; } Then, in your update loop: if (37 in keys) { //keycode 39 is down } if (38 in keys) { //keycode 38 is down } // ... etc


0

It looks to me like you can use a variant on a Poisson disc sampling algorithm to achieve this. Check out Mike Bostock's wonderful visual demonstration of these algorithms, particularly the explanation of Bridson's algorithm about a quarter of the way in. Here you store your points in a grid where the cell size is r/sqrt(2) - that way if all your points ...


0

Is simple, you have to use a simple "camara" system and make the cube or item or player be the center of it, so...done Here's an example of a camera in pure javascript Use arrows to move the camera var map = []; for(var t = 0; t < 100; t++){ var r = []; for(var tt = 0; tt < 100; tt++) r.push(Math.floor(Math.random()*4)); ...


0

I wonder how are you trying to sync it, the "best" way to do this is via socket connection. Also, you have to identify the important info that you really need to sync, FE, im developing an MRTS, i have to sync the units but the client doesn´t care about movement speed, attack points, etc, so, in essence i only need send to the client which unit he has to ...


2

Most games use quadtree structures to manage the colisions, you should read about it. Anyways, if you are having lag after X levels is possible that you are storing all the objects and checking them out every loop, and not just the object in the current scene or level.


3

I prefer not to use FSMs for movement, but it can work in certain cases. One of the things FSMs are great for is animations, which is what the linked example would easily tie into. The key thing to notice about the code you are working from is that lateral motion is considered in every one of their states using their function agent:getMovement(). Even in the ...



Top 50 recent answers are included