New answers tagged

0

Ok, i was able to solve it, even if i can't really explain why. In the tutorial, inside the function ColorShaderClass::SetShaderParameters(), i had this: bool ColorShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX& worldMatrix, XMMATRIX& viewMatrix, XMMATRIX& projectionMatrix) ...


0

What comes to my mind would be to have a list of each collision box per frame of the attack, then advance each hit box every frame and check if it collides with any enemy. If so, set the attack hit to true so the enemy doesn't get hit twice or more times for the same attack. If this doesn't make sense, here's an example of the code in Java: public void ...


8

An alternative way (Josh's approach is great too!) would be to setup an boolean on SDL_KEYDOWN, and possibly also ignoring all repeated key events. That you can do by checking the repeat member of the key event. Then you could implement your own timer, which doesn't have to be anything fancy, and implement key repetition your self. You could either trigger ...


15

By waiting for key-down events to be fired, you are likely at the mercy of the key event repeat rate that the OS controls (and which users can specify themselves). Instead, you may want to call SDL_GetKeyboardState at the top of your game update loop (the part of the update that happens every frame, whether or not an event has come in) to get the state of ...


-2

This code is adapted from a game demo in 'Cocos2d-x by Example Beginner's Guide' by Roger Engelbert. circleSprite->setScale(0.1f); circleSprite->runAction(ScaleTo::create(1.0f, 5.0f)); First it makes the sprite tiny (0.1f) and then runs an action to scale it up over 1.0 second (I have used an arbitrary scale to value of 5.0f for this example). The ...


2

The theory will tell that you're likely to get less cache misses (so 'more efficiency' w.r.t. response time) if your objects are close one to another in memory. This means that if you use an array, and your objects are contiguous, and you access each of them in a in-memory-sequential fashion, it will be more efficient than if you hop from here to there and ...


0

My approach is that there is a IQuadTreeItem class that has a member QuadTreeNode to the parent node and a virtual method ToBounding() that returns the correct bounding container. I think the member variable is very clean and it provides nice and fast access for relocating and removing among other operations.


1

You are fixing the time to 10(seconds?), so it will always takke it 10 seconds to reach its target. So if its a short distance, the bullet will move very slow and over a long distance the bullet will move very fast. So you need to set the time to (distance)/(velocity).


3

It's only a matter of opinion and code style. You can use: GL_TRUE and GL_FALSE true and false 1 and 0 Or anything that can be converted to 1 and 0. They all may have different types, but usually it does not matter because they all will be implicitly converted to GLboolean upon use. Use whatever you want, any of them will work. My only advice would be ...


9

I came back to this today and after some more investigation and trial and error I discovered that the culprit was targetTexture. With some more investigation I learned that reading and writing to the same texture in a shader is bad practice (not surprisingly) and will cause undefined behavior on GPUs. The solution was to copy the target texture to a new ...


0

SDL_DestroyTexture(txt); should clean up and then free the memory used by the texture. However you will be left with a dangling pointer so be sure to deal with that. txt = NULL //if using C txt = nullptr //if using C++ (Unless you're really sure the variable won't ever be used again before you leave the scope) Without doing this if the pointer variable ...


1

I have achieved this in my little testing and learning exercises. I have read that rendering text is a fairly expensive process, especially if using blended and wrapped mode. and so it should be avoided unless there is an actual change to the content. My solution was to store the rendered texture inside whatever object has the text pinned to it and have a ...


2

Here's one of my go-to jump functions. It's similar to a Mario jump - fast at first, slowing down until reaching the top. Please excuse the syntax. I haven't used C++ in ages, and never SFML. const float GRAVITY = 9.0f; const float MAX_VELOCITY = -10.0f; const float MAX_AIR_TIME = 1.2f; float timeInAir = 0.0f; float jumpImpulseTime = 0.2f; float ...


1

It could be your view as it is not to be in radians as you can see by if (view > 360) which indicates degree. And you use it in sin and cos. Or It seems to me, your nx and ny use a rotation matrix which rotates relative to origin [0, 0] with the distance to the origin x and y. If you are going to use that, change x and y to something like x1-x and y1-y ...


2

I assume you use integer for the coordinates. You could do something like the following: for (int z = A.z; z <= B.z; z++) { for (int y = A.y; y <= B.y; y++) { for (int x = A.x; x <= B.x; x++) { // Do things here.. You can get the coordinates from the x, y, and z variables. } } } This will basically iterate ...


0

Alternatively, you could store four different pre-defined rotations and swap amongst them.


1

The base idea is to chain Ease Actions with your normal tween action. Ease action basically changes the flow of time for it's inner action; So by implementing a simple/linear action, and chaining it with an ease action, you'll end up with the ease function you originally intended. As for the tweening. Let's say you want an object to change, there are two ...


0

there are many ways, why not just make it local to the player, make a small grid that follows the player and checks under each intersection whether or not its transversable, like is there a floor there and do a ray cast to see if there is a wall/building on any upcoming side..


1

You are moving at a constant speed in terms of the y-axis. To move a constant speed in terms of the vector direction, you would need to calculate the distance to be traveled (in purple in your first diagram), and if you know how far you want to go per run, divide the total distance by that distance to get how many loops it will take to traverse the vector to ...


0

Your problem is still open, in the sense there is so much research about optimizing pathfinding and reducing its time complexity (however there is much advancement if positions are constrained in euclidean space: so travelling cost is equal to distance), I don't know the details of your game, but I think you don't need to be 100% precise, if you have to ...


1

The compiler isn't smart enough to figure out that Status != EGuessStatus::OK is always true. So it assumes that it might be true or false - and if it's false, then the computer would get to the end of the function without returning anything, which is what that warning is trying to tell you. One solution would be to change the condition to while(true).


1

You can store the game data in a file, and obfuscate the data if you do not want the player to modify the stored values. This would be done by encrypting your data, and then decrypting it when you load it up in your game. The encrypting / decrypting would be hard coded into your binary. That being said, if someone wants to get at the game data, there will ...


0

You can't. If your game is a single player game or not connected to the internet, and you don't have them use any kind of DRM that big companies can have (Ubisoft, EA, Blizzard and the like), users will find a way to hack in your data and modify them. There are ways to obfuscate it, and make their life harder, but ultimately, someone motivated enough will ...


2

Do not use boxes for this kind of terrain. There are numerous problems that arise with using boxes, namely "catching" of objects on the intersections between the boxes. Box2D provides Edge Shape (line) primitives as well as a Chain Shape that far better suites your purpose. From the linked manual: // This a chain shape with isolated vertices b2Vec2 vs[4]; ...


0

You can compute the angle with the arctangent function atan2 (from math.h) float angle = atan2(differenceY, differenceX);


1

It seems each time you call getHeight(x,z) you get different results, regardless of whether the (x,z) is the same or not, so the generated normals don't match the terrain surface. Normals will match the actual terrain if you compute them from the generated terrain, and not from what getHeight returns. However, it makes sense to also fix getHeight so it ...


-1

try using something >= your near (i.e. >= 0.1) for your window_z instead of 0? glm::vec3 wincoord = glm::vec3(mx, 480 - my, /**/0.1f/**/);


2

You could use a hashtable with a key which consists of both the x-coordinate and y-coordinate. Finding the tile at a specific coordinate is then a constant-time operation. When you want to cache the "outline", you could store it in another hashtable. Whenever a node is added, follow this algorithm: the new node is removed from the "outline" hashtable for ...


0

I found a solution, I am posting it just in case. Basically I removed the method rotatePiece(), instead of that I have a method that calculates the rotation independently of drawing: void PieceZ::getRotation() { newX1 = (y1-y2) + x2; newY1 = (x2-x1) + y2; newX3 = (y3-y2) + x2; newY3 = (x2-x3) + y2; newX4 = (y4-y2) + x2; newY4 = (x2-x4) + y2; ...


0

You appear to be writing your vertices in a straight line. That is, vertex0 has position (0,0,0). vertex1 has position (-6,0,0). vertex2 has position (-12,0,0). vertex3 has position (-18,0,0), and so on. Once you've finished all 128 vertices along one strip, you move back to the start and then specify vertex128 (0,0,-6). (and then (-6,0,-6), ...


1

The answer turns out to be rather easy, altho lengthy, Instead of cleaning up faces (now called points) and preparing the list for gldrawarrays, I instead create a new list of unique faces/points as a base reference: Ill just post the entire function: void objload4(string filename, vector<glm::vec3>&vertices, vector<glm::vec2>&texcords, ...



Top 50 recent answers are included