Initial pain point
SpriteKit rather brilliantly integrates with CoreGraphics. This means sprites can be created procedurally from CGMutablePath sequences. The mobs in Escape Into Infinity (called "drones") are defined as follows.
A path of straight lines is specified, then provided to the constructor of SKShapeNode for the path argument. Some additional properties are set to style the shape node and add a glow effect, then bam, we've got our mob sprite. So, what's the problem here?
It turns out, SpriteKit will create a unique texture for every SKShapeNode instance we declare this way. If you're at all familiar with lower level GPU frameworks like OpenGL or Metal, you'll know that swapping out texture objects, along with other render state changes, tends to be costly, performance-wise. On 64-bit phones and tablets that supported Metal this didn't make things dip below the point of playability, but it was still noticeably sluggish. On 32-bit iOS devices, which only support OpenGL, the result was disastrous. Generating a map with hundreds of mobs on it, each with its own texture, ate up enough CPU time with switching textures and state validation to make the game unplayable. Add to that other enemies, props, parallax star fields, and various particle effects, and what should have been a fairly simple game ended up being a slideshow.
let path = CGMutablePath() path.move(to: .zero) path.addLine(to: CGPoint(x: 15, y: 20)) path.addLine(to: CGPoint(x: 20, y: -20)) path.addLine(to: CGPoint(x: 5, y: 0)) path.addLine(to: CGPoint(x: 0, y: -20)) path.addLine(to: CGPoint(x: -5, y: 0)) path.addLine(to: CGPoint(x: -20, y: -20)) path.addLine(to: CGPoint(x: -15, y: 20)) path.addLine(to: .zero) let shape = SKShapeNode(path: path, centered: true) shape.lineWidth = 1 shape.strokeColor = .magenta shape.lineJoin = .round shape.glowWidth = Drone.glowWidth
A path of straight lines is specified, then provided to the constructor of SKShapeNode for the path argument. Some additional properties are set to style the shape node and add a glow effect, then bam, we've got our mob sprite. So, what's the problem here?
It turns out, SpriteKit will create a unique texture for every SKShapeNode instance we declare this way. If you're at all familiar with lower level GPU frameworks like OpenGL or Metal, you'll know that swapping out texture objects, along with other render state changes, tends to be costly, performance-wise. On 64-bit phones and tablets that supported Metal this didn't make things dip below the point of playability, but it was still noticeably sluggish. On 32-bit iOS devices, which only support OpenGL, the result was disastrous. Generating a map with hundreds of mobs on it, each with its own texture, ate up enough CPU time with switching textures and state validation to make the game unplayable. Add to that other enemies, props, parallax star fields, and various particle effects, and what should have been a fairly simple game ended up being a slideshow.
The solution
It turns out, SpriteKit knows how to batch sprite draw calls that explicitly use the same texture object. Even better, the SKView class has a method called texture(from:) which takes any old SKNode and renders it to a texture bitmap.
The constructor for the Drone enemy type (as well as other SKShapeNode-based sprites that would need to be repeated in large numbers) was modified to take the render target SKView as an argument, and lazily generate a static texture property, creating SKSpriteNodes from that common texture. So, zooming out a bit from the above:
private static var texture: SKTexture! = nil
private static func getTexture(view: SKView) -> SKTexture {
if texture != nil {
return texture
}
// ... path and SKShapeNode code from above...
texture = view.texture(from: shape)
return texture
}
Newly minted Drone instances will call this method on setup, and create an SKSpriteNode instance from the returned texture. The sentries (stationary turrets) and dormant ships use this same hack. With sentries, the pivot point is actually toward the bottom center of the resulting sprite texture, not the center of the generated image itself, so that had to be set manually by debug inspecting the resulting texture's dimensions and converting the normalized coordinates on setup.
One-time objects, such as the HUD buttons, the virtual joystick, and the Starbase, didn't require this technique because they only appear in the game once, rather than potentially hundreds of times.
Parallax star fields required a technique fairly similar to this one, while differing in some key ways. I'll talk about that in a future blog entry.
luckyyniki-card games【Malaysia】
ReplyDeleteluckyyniki-card games,【WG98.vip】⚡, 카지노사이트 luckyyniki-card-games,【⚡iheart.tv】⚡, 샌즈카지노 luckyyniki-card-games,roulette,roulette. ラッキーニッキー
MGM Resorts Casino | Drmcd
ReplyDeleteMGM Resorts Casino, a $3.3 billion multi-million-dollar resort and 익산 출장샵 convention center, 문경 출장마사지 is 의정부 출장마사지 in the process of shutting down. The resort will 경기도 출장안마 be closed 거제 출장마사지
Alien 5 casino - filmfileeurope.com
ReplyDeleteAlien 5, a Japanese online 야구 실시간 slot game developed 토토 마켓 by BlueSky Entertainment Limited, is a 5-reel, 5-row and 스포츠토토 통계 샤오미 5-payline 스포츠토토 매출 샤오미 slot 승인전화없는 토토사이트 벳피스트 놀검소 machine. Released on 13 November
Many 소울카지노 of those old cheating gadgets had been made by the late Tommy Glenn Carmichael, a slot machine fraudster who reportedly stole over $5 million. In the fashionable day, computerized slot machines are totally deterministic and thus outcomes may be typically successfully predicted. In some instances a number of} machines are linked throughout a number of} casinos. In these instances, the machines could also be} owned by the producer, who's responsible for paying the jackpot. The casinos lease the machines quite than proudly owning them outright.
ReplyDeleteThis private menu saves a lot as} 15 favorite bets for 토토사이트 each player, dashing up betting for everyone and making complex betting simple for extra skilled gamers. Roulette traces its roots to the invention in England in about 1720 of the horizontal gambling wheel for a recreation called roly poly, which featured white and black slots, but no numbers. The first fashionable roulette wheels were in use in Paris by 1796. Deciding how many of} chips to place the place on the roulette desk decided by} what kind of bet you need to make.
ReplyDelete