Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Store RGB as integer

Author
Message
Scotty1973
AGK Backer
13
Years of Service
User Offline
Joined: 2nd Jun 2011
Location: Burton-on-Trent, uk
Posted: 4th Nov 2014 13:10
Hi

Is there a way to store RGB values as an integer, one of the drawLine commands takes an integer as a colour.
So is there a way to convert RGB to integer and back?

Many thanks

Scotty
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 4th Nov 2014 13:30
integer MakeColor( red, green, blue )

haliop_New
User Banned
Posted: 4th Nov 2014 19:05
what does this do actually ? i dont get it
Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 4th Nov 2014 19:27
It basically assigns the color to a variable.alot like

mysprite=createsprite(image) will store a sprite in mysprite variable

U can them access ur color anywhere else in the program if u make the integer GLOBAL

try

Global col as integer
col = MakeColor(r,g,b)

And then

DrawLine(x,y,xx,yy,col,col)

Native Technology
Scotty1973
AGK Backer
13
Years of Service
User Offline
Joined: 2nd Jun 2011
Location: Burton-on-Trent, uk
Posted: 4th Nov 2014 22:09
Hi all

Thanks for that, looked through help commands and missed that one! ops


Thank you

Scotty
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 5th Nov 2014 06:11
My version of AppGameKit doesn't seem to have makeColor, but Paul demonstrated what it actually does here, so you could implement it yourself: thread.

Rather than allocating some kind of resource behind the scenes and just returning an identifier to it (like createSprite), it actually does pack the entire color into an integer. This works because each of the four components in the color are 8-bit values, and an integer can store 32 bits.

Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 5th Nov 2014 12:15
Hi

You can use that in agk v1. I think it works :



http://www.dracaena-studio.com
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 6th Nov 2014 08:04 Edited at: 6th Nov 2014 08:05
You'd have to declare those parameters (r,g,b) as floats, and you should also use 255 instead of 256 in RGB or you'll overflow into the next byte on a 1.

Probably faster and neater to use bitwise operators as Paul does:


easter bunny
12
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 13th Nov 2014 01:08
You can also use this:




Audacia Games - Latest WIP - AUTOMAYTE 2.1, AppGameKit one click deploy to Android
"When you've finished 90% of your game, you only have 90% left"
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 14th Nov 2014 11:29
Nice

Login to post a reply

Server time is: 2024-11-25 11:52:22
Your offset time is: 2024-11-25 11:52:22