TextureAtlas | A simple script to generate texture atlases | Game Engine library
kandi X-RAY | TextureAtlas Summary
kandi X-RAY | TextureAtlas Summary
This is a short python script that takes a folder of images and generates a texture atlas from it. The images will be cropped to their non transparent bounding boxes. The script generates a CSS file and JSON file that can be used together with the texture atlas as well as an illustrative SVG/animation showing how the texture atlas is created.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Write SVG to a file
- Height of the node
- Width of the region
- Insert r
- Writes CSS to a file
- Add all source images in a folder
- Writes images to JSON file
- Write a list of images
- Finalize the image
- Removes borders
- Return the area of the image
- Returns the maximum extent of the rectangle i
- Height of the tree
TextureAtlas Key Features
TextureAtlas Examples and Code Snippets
Community Discussions
Trending Discussions on TextureAtlas
QUESTION
I plan to use TextureAtlas in my open world 2d game.
I need to load textures dynamically (because there are thousands of them, so I cannot load all at once). I plan to load textures that are needed at specific moment in gameplay. Also for some reasons I cannot have many texture atlases per map location.
Generally, I must avoid situation that I read all textures (entire atlas), because RAM usage will be too large. How the TextureAtlas work? Is is possible to keep the atlas open during entire game, but read from the atlas (to the RAM) only chosen textures when needed without worrying about RAM usage?
Best regards.
...ANSWER
Answered 2022-Jan-22 at 22:59You cannot load portions of a TextureAtlas. It is all or nothing. You will have to use multiple atlases and carefully plan what to put in each atlas such that you don’t have to load all of them simultaneously.
A Texture represents a single image loaded into GPU memory for use in OpenGL. A page of a TextureAtlas corresponds to a single Texture. Typically, you will have multiple TextureRegions on each page (Texture) of a TextureRegion. If you don’t, there’s no point in using TextureAtlas. The point of TextureAtlas is to avoid SpriteBatch having to flush vertex data and swap OpenGL textures for every sprite you draw. If you draw consecutive TextureRegions from the same Texture (or atlas page), they are batched together into a single mesh and OpenGL texture so it performs better.
Libgdx doesn’t support loading individual pages of a TextureAtlas though. That would make it too complicated to use. So, if you are doing a lot of loading and unloading, I recommend avoiding multipage atlases. Use AssetManager to very easily load and unload what you need.
QUESTION
init () {
super.init(texture: nil, color: .clear, size: initialSize)
// Create physicsBody based on a frame of the sprite
// basically giving it gravity and physics components
let bodyTexture = textureAtlas.textureNamed("MainCharacterFlying1")
self.physicsBody = SKPhysicsBody(texture: bodyTexture, size: self.size)
// Lose momentum quickly with high linear dampening
self.physicsBody?.linearDamping = 0.9
// weighs around 30 kg
self.physicsBody?.mass = 30
// no rotation
self.physicsBody?.allowsRotation = false
createAnimations()
self.run(soarAnimation, withKey: "soarAnimation")
}
// Animations to make the main character seem like it is flying
func createAnimations() {
let rotateUpAction = SKAction.rotate(byAngle: 0, duration: 0.475)
rotateUpAction.timingMode = .easeOut
let rotateDownAction = SKAction.rotate(byAngle: -1, duration: 0.8)
rotateDownAction.timingMode = .easeIn
let flyFrames: [SKTexture] = [textureAtlas.textureNamed("MainCharacterFlying1"), textureAtlas.textureNamed("MainCharacterFlying2"),textureAtlas.textureNamed("MainCharacterFlying3"), textureAtlas.textureNamed("MainCharacterFlying4"),textureAtlas.textureNamed("MainCharacterFlying5"),textureAtlas.textureNamed("MainCharacterFlying4"),textureAtlas.textureNamed("MainCharacterFlying3"),textureAtlas.textureNamed("MainCharacterFlying2")]
var flyAction = SKAction.animate(with: flyFrames, timePerFrame: 0.1)
flyAction = SKAction.repeatForever(flyAction)
flyAnimation = SKAction.group([flyAction,rotateUpAction])
let soarFrames: [SKTexture] = [textureAtlas.textureNamed("MainCharacterFlying5")]
var soarAction = SKAction.animate(with: soarFrames, timePerFrame: 1)
soarAction = SKAction.repeatForever(soarAction)
let soarAnimation = SKAction.group([soarAction,rotateDownAction])
}
...ANSWER
Answered 2021-Dec-18 at 18:20you declare let soarAnimation
inside your createAnimations function, meaning it's not in scope when you call self.run(soarAnimation)
. Solution: declare soarAnimation
as a class property. Alternate solution: have createAnimations()
return the SKAction and grab it in init that way
QUESTION
I have a SpriteKit platformer that uses a tile map for a background. The background in question is positioned 1 screen-height above the main content (it's positioned off-screen), acting as a forest canopy above the player. I accomplish that programmatically, like this:
...ANSWER
Answered 2021-Jul-11 at 16:53It seems that I've solved the problem.
I'm presenting my scene via SwiftUI SpriteView
, which I had configured to allow background transparency, like this:
QUESTION
For some context, I am using SpriteKit. I created an extension for SKTexture
:
ANSWER
Answered 2021-Mar-30 at 06:59I guess it's impossible to deprecate a system API.
You may override a default behaviour:
QUESTION
Is there a way of improving this situation or am i just using the engine wrong? I tried to go around this problem by first creating and spawning Images of the Background with lower Quality.
...ANSWER
Answered 2021-Mar-08 at 01:19When compiling with the --release
command line option, it runs much faster as the release profile have optimization enabled.
QUESTION
I need to draw a two-dimensional grid of Squares with centered Text on them onto a (transparent) PNG file. The tiles need to have a sufficiently big resolution, so that the text does not get pixaleted to much.
For testing purposes I create a 2048x2048px 32-bit (transparency) PNG Image with 128x128px tiles like for example that one:
The problem is I need to do this with reasonable performance. All methods I have tried so far took more than 100ms to complete, while I would need this to be at a max < 10ms. Apart from that I would need the program generating these images to be Cross-Platform and support WebAssembly (but even if you have for example an idea how to do this using posix threads, etc. I would gladly take that as a starting point, too).
Net5 Implementation ...ANSWER
Answered 2021-Mar-03 at 11:54I was able to get all of the drawing (creating the grid and the text) down to 4-5ms by:
- Caching values where possible (
Random
,StringFormat
,Math.Pow
) - Using
ArrayPool
for scratch buffer - Using the
DrawString
overload accepting aStringFormat
with the following options:Alignment
andLineAlignment
for centering (in lieu of manually calculating)FormatFlags
andTrimming
options that disable things like overflow/wrapping since we are just writing small numbers (this had an impact, though negligible)
- Using a custom
Font
from theGenericMonospace
font family instead ofSystemFonts.DefaultFont
- This shaved off ~15ms
- Fiddling with various
Graphics
options, such asTextRenderingHint
andSmoothingMode
- I got varying results so you may want to fiddle some more
- An array of
Color
and theToArgb
function to create anint
representing the 4xbyte
s of the pixel's color - Using
LockBits
, (semi-)unsafe
code andSpan
to- Fill a buffer representing 1px high and
size * count
px wide (the entire image width) with theint
representing the ARGB values of the random colors - Copy that buffer
size
times (now representing an entire square in height) - Rinse/Repeat
unsafe
was required to create aSpan<>
from the locked bit'sScan0
pointer
- Fill a buffer representing 1px high and
- Finally, using GDI/native to draw the text over the graphic
I was then able to shave a little bit of time off of the actual saving process by using the Image.Save(Stream)
overload. I used a FileStream
with a custom buffer-size of 16kb (over the default 4kb) which seemed to be the sweet spot. This brought the total end-to-end time down to around 40ms (on my machine).
QUESTION
I am relatively new to libgdx
and only started using it about a week ago. I am now facing a problem with my Box2D
dynamic bodies. They render but are unable to interact with each other(they are affected by force applied to them though). I created those bodies using the free editor on GitHub. I've been struggling with this and I cant seem to see what is wrong.
Here are all my classes:
...ANSWER
Answered 2020-Dec-15 at 01:18You aren't setting collision masks which specify what collides with what i.e.
QUESTION
In desktop and Android is Ok but in Html not work and freezing in this line:
...ANSWER
Answered 2020-Oct-26 at 10:07The js console gives you an error message.
Probably you are using a pre-1.9.10 particle effect with libgdx >= 1.9.10. The file format was changed, and while it was made backwards compatible on JVM platforms, this was not possible on HTML. You have to load and save the effect with the particle editor to solve this.
QUESTION
What do I need to fix so that a single keystroke plays one full animation loop?
Creating animation object:
...ANSWER
Answered 2020-Oct-02 at 07:51The Animation class provided by LibGDX includes an .isAnimationFinished() function. This will return a boolean indicating when the animation has finished playing.
In your case, I assume you're updating your elapsedTime variable in your update() function. So you can do something like:
QUESTION
I am currently trying to use events to signal when the character jumps in my Bevy game. I want the system that handles player inputs to send a JumpedEvent
which can then be received by other systems to perform the appropriate actions (set the correct player animations, velocity, sound, etc.) but the first system to read the event consumes it.
Does Bevy provide a way to read events without consuming them?
Here is my current code:
...ANSWER
Answered 2020-Aug-31 at 17:25I just realized what I was doing wrong. I was using a single global resource EventReader
to listen to the JumpedEvent
instances being sent. Each EventReader
only reads each event a single time. What I needed to do instead was to have an individual EventReader
for each system that needed to listen for the event. I did this by using Local
EventReader
s for each system that needed to listen for the event. See below the modified code:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install TextureAtlas
You can use TextureAtlas like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page