New answers tagged

2

I'm happy you figured it out, and I find it really cool that you managed to do it in your own way. But yours is a specific solution for a specific occurrence of a very general problem. I would like to explain what exactly happened and why it happened. Just in case others stumble upon this answer, sooner or later, with their own specific occurrence of the ...


0

If you want security, do the important jobs on the server. Nearly all operations that are being done on the client are easily accesible, editable and cheatable. Note that, this may reduce the performance a bit depending on the connection speed of client.


0

Usually, obfuscating (minifying) the JavaScript code is enough to deter all but the most fervent of exploiters from abusing the script through the developer console. But without knowing how the PHP and JavaScript sides communicate, that might not be an option. One idea does come to mind, however. You could have the server explicitly request the client to ...


1

I got the solution, it's simple. This is my animatin for it: I saw that it make a square out of the lines and then i could get the diagnol in the square. In that way i could get how much i had to scale the mouse x and y to match where it needed to go. The code would look this this: if (mouseX >= 0 && mouseY >= 0) { ...


0

You're on the right track, but just a little off the mark. Like most problems, this can be solved in many different ways. Here's one I think should be simple and effective in your case. The cool thing about tile-based games is that they allow for a good separation of data and visuals. As you can see from your own code, the map is nothing more than a two-...


1

As you noticed, you should call requestAnimationFrame only once per frame. It means that you need to call it once upon starting your game, and then once at the end of the same function it calls. For instance: requestAnimationFrame(draw); function draw() { if (onCutScene) drawCutScene(); else if (onMainMenu) drawMainMenu(); else if (inGame) ...


1

It turns out that the image was to large for the size I wanted it to be, so I was only seeing the corner of it (which was blank).


0

I'm doing effectively the same thing as you, although I think I have things organized a bit differently. I have an object (struct actually) that stores information about each map tile, including if it has more than one frame and what the frame cycle time is. I then have a sprite-map object that contains all those tiles. I then update the sprite-map every ...


1

As long as you have the position of the moving wall and the size of it, as well as the position of the player and the player size, it's easily doable without using a tile map :) I posted three guides based on shape collision, so check them out: For testing if a point is inside a polygon, use the code I posted below. I wrote this in C# based off of the ...


3

Is the script attached to the game object of one of the two chests CurrentChest and OpenChest? Then keep in mind that deactivating a game object also deactivates all scripts attached to it. That means any events on them won't fire anymore. You likely only want to disable specific components of the chests.


6

The issue in your code is that you only check for the key press in the OnTriggerEnter function, which only gets called when the collider enters the trigger. What you probably want to do instead is check for the keypress inside the OnTriggerStay function, which gets called while the collider lies inside the trigger.


1

Nevermind, guys. I fixed the problem.. the reason why all the images are showing at the center of the screen is because of the "this.monsters = this.game.add.group();" and the " monster = state.monsters.create(state.game.world.centerX, state.game.world.centerY, data.image);" code. Now, the "x" serves as the horizontal position of the images and it should be ...


0

The easiest way is to use counters. If you want your bots to do something in X frames, you'll have: class Bot { constructor() { this.doSomethingCounter = 0; } doSomethingInFrames(n) { this.doSomethingCounter = n; } update() { if (this.doSomethingCounter > 0) { this.doSomethingCounter--; if (this.doSomethingCounter === ...


0

I found out that objects can be killed with body.lifespan Adding the line bullet.lifespan = 1000; in my fire() function fixed the problem


1

Not sure i (bother to :-)) understand your code, but i'd like to point out that accumulated time will never be accurate on the long term. If it is crucial that you have consumed exactly 2500 frames in 100 seconds, you likely cannot rely on exact sum of the individual frames. Instead you must make it "absolute". If you require 25 ms per frame, you know for ...


2

I think you can't do it. Phaser groups doesn't have body: http://phaser.io/docs/2.4.4/Phaser.Group But you can use setAll method to set properties to all sprites of a group: http://phaser.io/docs/2.4.4/Phaser.Group.html#setAll Otherwise, if you want more complex objects you could try another type of physics (P2) and make complex bodies with polygons.


0

Quaternion.Euler creates a Quaternion from three euler angles either by parameter list of floats or a Vector3 of the angles, not from a Quaternion (see docs): public static Quaternion Euler(float x, float y, float z); OR public static Quaternion Euler(Vector3 euler); Did you mean to write: transform.Rotate((transform.rotation * Quaternion.Inverse(...


0

After doing some more research I finally find a solution based on this post: java-merge-adiacent-rectangles-into-a-polygon Here is my solution process sequence in general: Extract all edges from the tiles into a EdgeArray Remove all the edges that has a duplicated one in the EdgeArray this will leaving only the Edges of the merged poly contour I want ...


-1

In a game I'm working on, I have bullets capable of automatically moving towards the closest enemy you're aiming at. They detect the enemy once only when the bullet is create, then start moving at finite speed and correct their direction when the enemy changes position. To fit your case, we can assume the enemy position in my script with the mouse ...


1

Your main problem is that you did not account for the discontinuity in the arctangent function... // Check if arctangent has crossed the discontinuity if (delta < -Math.PI || (delta > 0 && delta < Math.PI)) { And you are not reducing the player rotation into a canonical -Pi <= x < Pi range. // Reduce player.r into the -PI thru PI ...


5

You can solve this with some basic trigonometry. I wrote the code in Unity, but the general idea should be the same. Consider the following image: We already have P1 and P2. Here is some code to calculate the rest with comments: //Get points P1 and P2 based on circles Vector2 p1 = A.transform.position; Vector2 p2 = B.transform.position + ...


0

I've used the separating axis theorem and I've come up with this huge code: this.checkCollision = function(entity1, entity2) { var width1 = (entity1.width * this.COLLISION_EPSILON_WIDTH)/2; var height1 = (entity1.height * this.COLLISION_EPSILON_HEIGHT)/2; var width2 = (entity2.width * this.COLLISION_EPSILON_WIDTH)/2; var height2 = (entity2.height * ...


1

Minerals/items are gameObject, not Transform. Your instantiation code at DestroyRock() should be like: Instantiate(minerals[Random.Range(0,1)], position, Quaternion.identity); In minerals[Random.Range(0,1)] 0 and 1 are index of the minerals array. If there were 5 items it would be minerals[Random.Range(0,5)].


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



Top 50 recent answers are included