Public Group

# 2d coords to 1d coords

This topic is 4989 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am having troubles of trying to create a formula that takes 2-d coords and turn them into 1-d array coords. I know for simple one it would be i = x +(y * arraywidth) but I need one that will get the alpha value out of a texture. So when I go 0 , 0 it will give me index 3,the byte in which the first alpha value is in. Then when I get 1,0 it would give me 7. Do you get what I mean. I can't seem to get one made. The closest I got was working for the first row of y's but then when I go to the next row like 0,1 it won't work. Can someone please help me out with this math? Thanks, vbuser

##### Share on other sites
i = ( x +(y * arraywidth) ) * 4

data[ i ] = red
data[ i+1 ] = green
data[ i+2 ] = blue
data[ i+3 ] = alpha

##### Share on other sites
Thanks for the help. Cya later.
vbuser

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634059
• Total Posts
3015296
×