Tag Info

Hot answers tagged

6

How are you passing your normals to the vertex shader? It looks like those are the normals for each of the six faces of a cube, but the vertex shader operates on vertices, not faces. Unless you're doing something unusual, you need to specify a normal for each vertex. In addition, if you want a cube to look right, you will need 24 vertices rather than 8, so ...


3

You don't need to call glVertexAttribPointer for the indexes; the indexes are found from the bound GL_ELEMENT_ARRAY_BUFFER during the drawElements call (which is saved in the VAO state IIRC). However indexes start from 0 so the contents of your index buffer are flawed they should be: {0,1,2,2,3,0}


3

Basically, you'll need some kind of container or collection to hold all entities. Then create some spawn or factory function to actually add them. When drawing (or updating) your game entities, you'll just iterate through this list and modify them accordingly. Here's some pseudo-code example: List<Entity> entities; function spawnEnemy(position pos) ...


3

In my experience with android, it is the garbage collection the kills the performance, not the allocation, although these two are tied hand and hand. As mentioned on the comments, pre-allocation is a way to deal with this issue. This is known as a memory pools. Another similar solution is object pool pattern. An object pool allocates as needed, but does ...


3

Sure, this is quite simple really. I'll guide you through Paint.net. Open the application and go to New. In the dimensions, put 8 for width and 8 for height. A new 8x8 canvas will open, typically I zoom in all the way to 3200%. I'll also get rid of the white background layer, by making a new layer, then deleting the background one. Now you have the canvas ...


2

Just rotate the point at an angle of -θ around the center of the rectangle. relx = x-cx rely = y-cy rotx = relx*cos(-theta) - rely*sin(-theta) roty = relx*sin(-theta) + rely*cos(-theta) dx = max(abs(rotx) - width / 2, 0); dy = max(abs(roty) - height / 2, 0); return dx * dx + dy * dy; Also, remember this is still the distance squared, so you need to take ...


2

Try doing this:- try { Robot bot = new Robot(); bot.keyPress(KeyEvent.VK_F6); bot.delay(50); bot.keyRelease(KeyEvent.VK_F6); } catch (AWTException ex) { Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex); }


2

Convert them to the normalised space: float r1 = color1.r / 255.0f; float g1 = color1.g / 255.0f; float b1 = color1.b / 255.0f; float a1 = color1.a / 255.0f; float r2 = color2.r / 255.0f; float g2 = color2.g / 255.0f; float b2 = color2.b / 255.0f; float a2 = color2.a / 255.0f; and them multiply them: float r3 = r1 * r2; float g3 = g1 * g2; float b3 = b1 ...


2

You can explicitly get those numbers from id = glGetAttribLocation(program, name); after linking; the name is the string that appears in the vertex shader for the attribute. For example if you passed "vertexPosition" for name then you would get 0. If the layout information is not in the shader then openGL will create a default layout (usually in order as ...


2

All of the atlas regions are automatically available through the skin as TextureRegions. I just tried it, and works without modifying the json file. You can just call skin.get(name, TextureRegion.class); or skin.getRegion(name); Unfortunately, the skin docs are not very clear about this. libGdx docs


2

Before addressing the specifics of your question, I do want to point out that I disagree with your approach to your inheritance model. A Game generally does not implement a Scene but instead a Game consists of one or more active Scenes that are being rendered and updated in a main loop. It's important to think about whether a class relationship can be ...


2

why not create a list of enemies in the level so the draw becomes: List<GenericEnemy> enemies;//filled during construction Render(){ //Render elements common to all levels draw(background); draw(playerSprite); for(GenericEnemy enemy : enemies) { draw(enemy); } } where GenericEnemy is a superclass of all enemy ...


2

It's not that object oriented paradigms are bad for game development, they do the job just fine. Though, there are downsides to doing everything with a typical OOP mindset. 1) Inflexible, you can't reassemble behaviors and properties of your game objects on runtime as they are tied to fixed class hierarchies. 2) Slower unless you mix OOP with data ...


1

You have your thisMin and thisMax declarations reversed. Vector3f thisMin = new Vector3f(this.pos.x + this.w, this.pos.y + this.h, this.pos.z + this.d); Vector3f thisMax = new Vector3f(this.pos.x, this.pos.y, this.pos.z); should be: Vector3f thisMin = new Vector3f(this.pos.x, this.pos.y, this.pos.z); Vector3f thisMax = new Vector3f(this.pos.x + this.w, ...


1

The positions and color (and all other vertex attributes) all use the same index buffer, there is no way to change that. So if you have an index X then that vertex will have the position at index X and the color at index X. The size parameter indicates how many values to take (1 to 4). Sometimes positions are stored in the homogenic format (essentially add ...


1

LET THIS BE A CAUTIONARY TALE ABOUT BOX2D! Haha! Here's the solution I came up with The problem I amrunning into is due to the fact that Box2D uses meters instead of pixels for the scale, in my game a screen that is 1920x1080 would be 1920 meters wide and if I am using sprites a small sprite will be only as many meters wide as it is in pixels. The reason ...


1

What you need is double buffering I stole this from somewhere just to give you a quick answer: "Double buffering is conceptually pretty simple, instead of drawing your objects one by one, you draw them on an image and then tell the renderer to draw that entire image. This eliminates the flickering. Here's an example of how you might do this" class ...


1

I figured out the problem myself! After printing the coordinates of the mouse to the console I realized that where just something missing with my Input. Sure enough, I added GameContainer to the constructor of minigun and set input to equal GameContainer.getInput();. It works perfectly now :D public Minigun(GameContainer container){ try { ...


1

The distance moved does not take the delta time into account, so if you get updates coming at an irregular interval you'll get jerky motion. Scale your speed by the elapsed time, dt; public void update(float dt){ if(cont == true){ vec = makeVec(); x += vec.x * speed * dt; y += vec.y * speed * dt; } } This might mean you'll ...


1

Dialog is better suited for modal pop-up windows, and it includes a "button" and "content" table already in the window (as the docs say). You can grab these tables with getButtonTable() or getContentTable(). The dialog makes it easy to work with pop up windows. For example, here is a confirmation dialog: Dialog diag = new Dialog("Warning", skin, "dialog") ...


1

you say it's so complicated to implement a path-finding algorithm, but it isn't... and what's even better, once you have implemented one you can use that algorithm whenever needed again... i can provide you with an simple one (A* it is - and it is easy) and it's so open you can use it on hexfields, squared fields or even on cubes... private ...



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