Tuesday, August 23, 2022
HomeGame DevelopmentHow can I convert a uncooked pixel buffer (1D array) right into...

How can I convert a uncooked pixel buffer (1D array) right into a 2D array?


I’ve to take care of a uncooked buffer representing some pixels, particularly the pixels crate. To this point I’m able to do some magic from the examples, nevertheless it’s terribly dangerous with regards to readability and I want to convert that buffer right into a 2D array, in an effort to entry it extra effectively and make it simpler for collision detection. So in an effort to draw a single pixel in place (512, 423), I need to do that:

fn draw_something(&mut self) -> /* ... */ {
    self.pixel_array_but_2d[512][423] = /* Some shade in hex */;
}

I do know I may do that with different methods with out the conversion to a 2D array, however I nonetheless need to do with the way in which I described.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments