Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Hot answers tagged

6

I don't think this is going to be quite as easy as you'd like, that said you should be able to copy/paste the code below to get something going. There might be a better way to approach this, but as I see it you'll need 2 render passes. The first to render the scene to a low resolution to introduce pixelation, and a second to resample the low resolution ...


4

It looks to me like this could be done with a TrailRenderer. This leaves a ribbon of 3D geometry behind a moving object, onto which we can assign a material to control the way it renders. We can use a custom shader incorporating a GrabPass to take a snapshot of the frame buffer, sampling it with a distortion offset, to get a refractive watery look: Shader "...


3

In a 4x4 transformation matrix, all directions are contained: First row of matrix contains the x-axis. Second row of the matrix contains the y-axis. Third row of the matrix contains the z-axis. Fourth row of the matrix contains the position/translation. Looking at your code, -z is the direction the camera looks at. Most likely, the y-axis in that ...


3

To put these into a formula, it seems that you want something that varies with the distance from the boundary, so first calculate that parameter (I'll call it dx below), and then put that into whatever formula you want. Note that some terms will preserve the sign of the distance and some won't (exp(x) and x*x won't but x*x*x will) so excursions to the ...


3

Yup! As of iOS 9, you can set a SceneKit SCNView to use a Metal renderer on devices that support it by initializing it with the SCNPreferredRenderingAPIKey key in the options dictionary, as described here. Something along these lines should work: let sceneView = SCNView(frame: someFrame, options:[SCNPreferredRenderingAPIKey: NSNumber(unsignedInteger: ...


3

The first issue is that you are re-creating and destroying the buffers, reloading the texture, and recompiling the shader on every single draw loop. This is the source of the huge CPU usage. As for the memory going up, there could be a memory leak in the scripting language you are using. Not recreating everything on every loop will probably reduce the ...


3

If I am not mistaken these types of problems are usually solved by backtracking family of algorithms. I would use an algorithm similar to DFS: recursively search the solutions tree and whenever leaf node is reached, save the path if it was the longest discovered. After reaching leaf node, backtrack to last "crossroads" and take the other turn(s). In order to ...


2

Might be a bit late, but I did this same thing recently. The simplest method for me was to give each SKSpriteNode object a unique name, and parse the sprite's name from the description property: sprite.physicsBody?.description


2

Your problem is in line return enemyArray.randomElement. This sentence tries to access a property called randomElement that your enemyArray has, but you want to get the object inside enemyArray that has the randomElement position, right? Try with this: return enemyArray[randomElement] More information about arrays in swift can be found here.


2

You may want to modify the collisionBitMask property of your SKPhysicsBodies. You can set a bitmask to make collision rules. Objects that shares a same bit collides together. Since collisionBitMask is a UInt32, you can set up to 32 different layers of collision. Set your projectiles in different layers depending on who launched the projectile. Here's an ...


2

Try setting the material fillMode to .lines: sphereNode.geometry?.firstMaterial?.fillMode = .lines


2

Quick solution didn't turn out quite as well as I'd like, but I'll post it up regardless as it may help someone out. To get something that better matches your figure I believe you'll need to build your own SCNGeometry with probably a box for each line. This can be done, and there's several examples on building your own geometry around, but it is a fair bit ...


2

A "20 year old" PC is going to be well below the minimum requirements needed to run anything built on modern Unreal 4. So no, this will not scale gracefully (or indeed, at all). It certainly won't render in "high definition." To support hardware and software that old you'll likely need to fall back on entirely different technology in that scenario. Given ...


1

After multiple deletes from the device, clean and device and XCode restarts, it magically started working, though not always 100% reliably. Seems to be "one of those things".


1

First you need to have a timer variable that only starts counting when the game has started. Some programming languages have build-in timers, but those usually already starts when the application is running, so these aren't useful if you're using a startup screen or reset button. But you can use these timers to calculete the time spend in a timer variable. ...


1

Well it appears as if no one here seems to know it so I'll just post what I used which is a new method that I added in an extension to GKEntity (which I was actually trying to avoid) extension GKEntity { func component<P>(conformingTo protocol: P.Type) -> P? { for component in components { if let p = component as? P { ...


1

There are a few methods one could use to create procedural irregular shapes that are individually capable of being colored. The simplest of these is likely to use SKShapeNode to create a Node based on a CoreGraphics path. You could use other means of creating procedural irregular shapes, but this is the most straight-forward when working with SpriteKit. A ...


1

Are you using a game engine? you didn't clarify that. (I assume you are using Unity) You should change the tetris piece's world position instead of moving in the direction of the right or forward vector. Or you make the tetris piece the child of another object and move the parent instead.


1

Coming from a game dev perspective, I'd suggest you pursue a entity component based system (ECS) to build up your simulation. An entity is a container for components. Components represent state (and/or) behaviour of an entity. In pseudocode, it translates to something like: class Component { } class Entity { var components: [Component] // ... ...


1

You are removing their children which they don't have and to remove them you have to remove them from Parent. You can find more about children and parent Here func CollisionWithRed (Orange: SKSpriteNode, Red:SKShapeNode){ Orange.removeFromParent() Red.removeFromParent() }


1

Have you tried to initialize your SKPhysicsBody with a rectangle of the size you want? var node = SKSpriteNode(imageNamed: "node.png") node.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(width: 50, height: 50)) That way you can increase the size of the bounding box of your node without using a larger image. More details in the docs. Hope it helps!


1

As the documentation specifies, the first 3 values will specify the 3d position of the axis for rotating the light, while the 4th parameter will specify the rotation around that axis. For instance, specifying (pseudo-code) (0, 0, 1, degToRad(45)) will have the effect of a light that will be rotated 45 degrees around the vertical axis (assuming that z is up),...


1

I figured it after found some sample code. Basically, after I bind the render buffer, the current render buffer is bound to the depthRenderBuffer, However, the bound rendering buffer while presenting must be a color render buffer. after I added another line of code at the end, it works. Hope this helps somebody in the future. // Make the Color Render Buffer ...


1

Look into the Multipeer Connectivity Framework from apple. It doesn't exclusively use bluetooth but it's meant for the type of connections you're describing. It uses Bluetooth, infrastructure wifi, and peer-to-peer wifi, depending on what's available. https://developer.apple.com/library/ios/documentation/MultipeerConnectivity/Reference/...


1

Use the SKPhysicsBody instances as keys to a dictionary of game objects. When you want to process a collision, retrieve the game object associated with the physics body from the dictionary. Not as efficient as the direct link you sought, but more than sufficient for most purposes.


1

Well you create your game in GameScene that is already linked to your GameViewController when you create a new project. If you need a Main Menu Then you need to create another UIViewController in the MainStroyBoard and a swift class in the project. Then you will have to link that class and UIViewController by clicking on the UIViewController and in ...


1

I found that it is because I was using a dynamic body rather than a kinematic body. I still have a bit of learning in regards to how physics works with scene kit.


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