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.

Author
Message
Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 21st Aug 2020 07:51 Edited at: 21st Aug 2020 08:19
The following is in reference to this thread where i'm attempting to offer a method to determine the proper prefecture on a map based on the pointer's position using what i'm calling a ColorMap vs the theoretically more-demanding system using hundreds of sprite shapes to create a sort of Image Map for lookup found there (if there's a proper term for this ColorMap, let me know?):



There are 2 separate things demonstrated where the second relies upon the first using the attached image (based on this original) where i simply took the image into photoshop and assigned each prefecture a unique color/shade based on region.


once loaded and displayed, i used one of the PickColor functions found on the forums (specifically, this one by fubarpk) to pull colors and added them (and the prefecture name) manually into an array for lookup.

with that, we can already hover over a given color to determine prefecture, tho it's not an ideal method because 1) you'll lose proper colors along the borders if maximized/resized, 2) copious use of GetImage() = performance hit/bad practice, et al.

instead, the goal was to use an image memblock to retrieve the color (GetPre2() Function). it works, but there is an error when you dip below the sprite's boundary (sometimes, and not obvious to me. any help there is appreciated, please ).

i've been wanting to explore this idea for one of my own (future) projects and thought i'd put something together and share it here. feel free to critique and offer any advice!
[My Itch.io Home] | [#LowRezJamAGK2020]
[AGK Resource Directory] | [TGC @ GitHub]
[CODE lang=AGK] Your Code Here [/CODE] | [VIDEO=youtube] VideoID [/VIDEO]

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Aug 2020 08:55 Edited at: 21st Aug 2020 08:57
i did something similar using dbpro then dark gdk without using sprites that changed the colour of the area you hovered over
attached is the older dbpro version i hope that helps that is if you can understand my bad dbpro code

apologies i didnt go through it to find the exact code but my hands are like clenched fists atm

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk

Attachments

Login to view attachments
Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 21st Aug 2020 08:58 Edited at: 21st Aug 2020 09:00
the sprite is irrelevant re: the memblock but maybe your comment on it would make more sense if you attached the dbpro code

i see it now, thanks i'll look through it and see if i can spot the pertinent code. thanks again.
[My Itch.io Home] | [#LowRezJamAGK2020]
[AGK Resource Directory] | [TGC @ GitHub]
[CODE lang=AGK] Your Code Here [/CODE] | [VIDEO=youtube] VideoID [/VIDEO]
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 21st Aug 2020 09:06 Edited at: 21st Aug 2020 09:07
I suggest to build polygons and check if the pointer position lies with in a polygon.
Here is a quick find
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Aug 2020 09:17 Edited at: 21st Aug 2020 09:27
i may have lead you astray and that version may be too old but quite sure i used masks
but thats what its meant to do with europe selected


sorry i did lead you astray its the menu selector you needed i have c version now

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Aug 2020 09:31 Edited at: 21st Aug 2020 10:10


finally dang my hands anyone want to build me robotic ones


so a kinda colour map like youve done to grab colors from and then just a bitmap and then one for each selection

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 21st Aug 2020 13:29
Quote: "finally dang my hands anyone want to build me robotic ones"

Sugar is an inflammatory.

Once I cut Sugar out of my diet, my arthritis went away.

It is still mild because I have some sugar intake with my Ice-Cream in summer, but I do not have to pry my fingers open in the morning anymore, and the results were seen within a month.

Taking sugar out of my coffee was the big thing as that was my main sugar intake, but I cut it in half, then found a brand of coffee that was good without sugar, then cut it out completely.

I do not buy sugar anymore, and only have small intakes on what I eat if it is already in there, but I avoid things with sugar or corn syrup as a main ingredient.

If you pay attention to the ingredients of the food you buy at the market, you may be surprised to find sugar and corn syrup as main ingredients in almost everything.

In the USA, it is hard to find things at the market that do not have those as main ingredients, and it is estimated that 74% of the medical conditions in the US are related to thickened blood.

The USA also has around 80% of its elderly population taking blood thinner medication.

I suspect an FDA-Pharma conspiracy, where they poison you with the food to sell you drugs you do not need, as healthy people are not profitable for big pharma which drives the FDA.

Anyway, cut back on your sugar (drastically) and you will see positive changes to your health, especially for joint pains.


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 21st Aug 2020 14:03
I did the same thing back in 2017/2018 using a seperate image to encode the country and eventually ended up putting the colour into the alpha value so that just one image. So if you want to know what are is under a pixel you just look at the alpha value.

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Aug 2020 14:27
thanks conjured anti inflamatories do zilch and the blood didnt show that it was arthritic so not really sure i have slight carpet tunnel in one hand but its both
and drs dont think thats it, i do know one of the medications ive been on has caused parkinson symptons so maybe its a part of that medication that i no longer will take
but it is going to take some time to get it out of my system

@bengismo thats clever using the alpha channel

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 21st Aug 2020 16:09 Edited at: 24th Aug 2020 02:08
Quote: " @bengismo thats clever using the alpha channel "

Agreed

I had thought of changing the alphas by 1 for each to detect which is which... 1st color 254, 2nd 253 etc... but your method of the overlay having the save value as the color is much easier as long as no two colors have the same red, green, or blue values, so there will not be any confusion.
Quote: "
thanks conjured anti inflamatories do zilch and the blood didnt show that it was arthritic so not really sure i have slight carpet tunnel in one hand but its both
and drs dont think thats it, i do know one of the medications ive been on has caused parkinson symptons so maybe its a part of that medication that i no longer will take"


Mod Edit: Let's not go this far off topic. Thanks.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 23rd Aug 2020 20:22 Edited at: 23rd Aug 2020 20:23
Virtual Nomad, thank you once more for this amazing demonstration. I studied your code to some extent and still need to learn more about the memblocks and how to use them. I was able to utilize your idea and put another map under the colored one and set the colored map to invisible and it works very well. As precision is concerned this method is deffinetly more precise and much simpler to apply. As for the error, I was able to identify and solve it. It appeared that when pointer y reached the bottom of the height of the map it produced an error suggesting that GetMemblockByte() was trying to read a pixel of the MemMap that was one pixel extra in length than the height of the actual MemMap.

The original function code:



Amended function code to account for the bottom row of the map where the error is produced:



So far, it works fine. There are some parts of your code that I do not understand, like what are:

1) Prefectures.Insert(ThisPref)
2) Prefectures.Sort()
Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 23rd Aug 2020 21:19 Edited at: 24th Aug 2020 02:03
Quote: "I did the same thing back in 2017/2018 using a seperate image to encode the country and eventually ended up putting the colour into the alpha value so that just one image. So if you want to know what are is under a pixel you just look at the alpha value."


Very good idea Bengismo, though for a map in this case with many prefectures I find it better to organize them according to different colors and different shades of a given color can be used to identiy prefectures of the major regions like Virtual Nomad did, in the case, which I think will be the case, I will utilize the same method for color map code as it organizes the data very well and easy to read and identify.

fubarpk, listen to Conjured on this matter.

Quote: "Like Pharma, they do not profit as much on healthy people, and unless they are offering their services for free, then they are in it for the money."


I understand that we are going off topic as the purpose of this thread, but I reason human health is of higher importance than coding, so I want to elaborte on what Conjured mentioned.

Mod Edit: Let's not go this far off topic and into a probable arena of inappropriate for a "family friendly programming forum".

Have a good night.
Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 24th Aug 2020 03:31 Edited at: 24th Aug 2020 04:06
@george++ & bengismo
thanks, guys. i'll look into both.

meanwhile, what i want to use this for is more than what the alpha value can hold (i want real colors to be retrieved, etc). it was a thought i offered to the Prefectures notion but want to use it for more than that.


Lupo4mica37 wrote: "Amended function code"

thanks, i thought a bit and confined it similarly:

IIRC, i could reproduce the error off all 4 sides of the sprite.

Quote: "
1) Prefectures.Insert(ThisPref)
2) Prefectures.Sort()"

see https://www.appgamekit.com/documentation/guides/12_array_changes.htm

i'm getting more comfortable with handling arrays (still a way to go) and .insert is now in just about everything i do. i'm embracing the notion of dynamic arrays and types (which took awhile for me discover, as well).

the function:

is just preparing a temporary record for the Prefectures array (ThisPref), .insert-ing it at the bottom since i didn't give specific index to .insert it in front of (as an actual record in Prefectures), then the array is sorted for later .find usage. and, no, it doesn't need to be .sort-ed with every addition. i should have saved the sort for after i'd added all Prefectures, but... i don't mind abusing the CPU sometimes, so...

note, the simple, 2-variable Type matters, for this:

...where "When sorting types the first variable of the type will be used to compare elements" and i want to .find Colors, so...


bonus pain, in case that doesn't hurt enough: Sorting Typed Array (and .Swap)
...which i did resolve:

...for THIS.
[My Itch.io Home] | [#LowRezJamAGK2020]
[AGK Resource Directory] | [TGC @ GitHub]
[CODE lang=AGK] Your Code Here [/CODE] | [VIDEO=youtube] VideoID [/VIDEO]
Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 24th Aug 2020 22:17 Edited at: 27th Aug 2020 10:39
Virtual Nomad, thank you as always for your great educational input, it means a lot!

As for the ERROR, I only got it for the height and not for the width. Very interesting. In fact, I wondered about it, meaning, why it does that with the height and not the width, and then the realisation that the image gets filled with the bytes from left to right and top to bottom, I guess must have been part of the reason, but then you are getting the error also in the width extremes, not sure what is going on.

Your pool/snooker game is a pretty nice little game. Is the low res the intention to be like that. like old school, Amiga type?

Also, I would personally make the volume of the audio for hitting the ball directly proportional to the force of the white ball hitting the other ball, unless that is your intended effect to sound equal each time. It would give more depth to the feel of the game in my opinion, however you may on purpose want it like that, that is totally another thing and it is not bad, just different. If I was you, I would in fact record @24 bit real audio of hitting the balls and going into the pockets to later implement in the game. I must say, the balls that hit each other even they just slightly touch each other, does sound unrealistic, so I guess the volume implementation would be beneficial for all interactions between all balls, unless it is meant to sound unrealistic.

The visual physics part is really nice, hence my opinion about the sound, the contrast between the two is like, realistic visuals with unrealistic audio, you know what I mean?

Once again, thank you for everything!
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 25th Aug 2020 15:30 Edited at: 27th Aug 2020 10:40

Apologies for going off topic, and for my response becoming a rant against certain establishments.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Sep 2020 13:55
Quote: "I did the same thing back in 2017/2018 using a seperate image to encode the country and eventually ended up putting the colour into the alpha value so that just one image. So if you want to know what are is under a pixel you just look at the alpha value."

Does that not mess up the display of the image? Or is the alpha channel being ignored?


I do like the idea of this color map. I've done similar things when I built my pixel-perfect collision library.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 3rd Sep 2020 14:29 Edited at: 3rd Sep 2020 14:30
Quote: "Does that not mess up the display of the image? Or is the alpha channel being ignored?"


In the example I listed above a separate image is used to store which country is underneath. So two separate images are in the example so alpha could be used if wanted.

For the application I was using it on I encoded it into the alpha and used SetSpriteTransparency( iSpriteIndex, 0 ) and so alpha isnt used when drawing the sprite at all. Using the alpha to store country data was just to save on some image memory. (rather than use 2)

Quote: "I do like the idea of this color map. I've done similar things when I built my pixel-perfect collision library."


I also did a pixel collision library that works with rotation etc and shared it on here somewhere. I just wished searches worked better otherwise everyone reinvents the exact same thing.
Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 5th Sep 2020 02:38
Quote: "For the application I was using it on I encoded it into the alpha and used SetSpriteTransparency( iSpriteIndex, 0 ) and so alpha isnt used when drawing the sprite at all. Using the alpha to store country data was just to save on some image memory. (rather than use 2)"


That is actually a very good technique, though the limit is 256, right? If you wanted more, you could generate another sprite.

So, how would you set the alpha for each prefecture to a given alpha value in Gimp?

Login to post a reply

Server time is: 2024-04-18 23:20:06
Your offset time is: 2024-04-18 23:20:06