Posted: 10th Nov 2022 22:46
So I am trying to change sprite colors if another sprite is in its same position, the second sprite has nothing to do with the first other then its pos/

This is how I am choosing that sprite to change color, if the positions are the same, if they mach then the sprites color changes.

I am using this here that I changed a lot to get it to work and it well, works about 90 percent of the time.

note. the sprites I am matching positions with are deleted after the color change so I think this might be the case but I added a tween delay and noticed it is now about 95 percent working. As in the colors change about 90 percent. Here and there the sprites do not change, and well, they should, there is no reason for them not to other then AppGameKit is not very accurate. There is nothing at all holding them from changing colors. Other then one, and this could be some how the other sprites are not at the same positon, but there being placed in the same spots.

Any help or advice would be well, appreciated.


+ Code Snippet
     if CollectingAnimals=0
		 
	for A=backgrounds.length  to 0 Step -1
	backgrounds[A].Sprite_X# =GetSpriteXByOffset(Item.SpriteID)
	backgrounds[A].Sprite_Y#=GetSpriteYByOffset(Item.SpriteID)
	backgrounds[A].posx#=GetSpriteXByOffset(backgrounds[A].ID)
	backgrounds[A].posy#=GetSpriteYByOffset(backgrounds[A].ID)
	backgrounds[A].Colors=GetSpriteColorAlpha(backgrounds[A].ID)	
	
	if backgrounds[A].posx#=backgrounds[A].Sprite_X#  and backgrounds[A].posy#=backgrounds[A].Sprite_Y#
	//if GetSpriteXByOffset(backgrounds[A].ID)=GetSpriteXByOffset(Item.SpriteID) and 
         //GetSpriteYByOffset(backgrounds[A].ID)=GetSpriteYByOffset(Item.SpriteID)
	if GetSpriteXByOffset(backgrounds[A].ID)=backgrounds[A].Sprite_X# and GetSpriteYByOffset(backgrounds[A].ID)=backgrounds[A].Sprite_Y#
	if backgrounds[A].Colors>200
	SetSpriteColor(backgrounds[A].ID,255,0,0,200)
	
	inc CountGrid
	endif
	endif
	next A
	
	endif
Posted: 11th Nov 2022 1:52
Don't go by exact pixel perfect positions, add a margin of error to give a bit of wiggle room (an approximate position).
Posted: 11th Nov 2022 2:01
Steve Ancell


Ok , I will try this, and find a ballance if possible, thank you for the help, ill let you know if it helped.
Posted: 11th Nov 2022 2:57
Ok, i just changed this to sprite collison and it works 100 percent everytime, here is my easy fixed code . I guess dealing with positions it is never 100 percent.

+ Code Snippet
	for A=backgrounds.length  to 0 Step -1
	if GetSpriteCollision(backgrounds[A].ID,Item.SpriteID)=1
	if backgrounds[A].Colors>200
	SetSpriteColor(backgrounds[A].ID,255,0,0,200)
	inc CountGrid
	endif
	endif
	next A
	endif
Posted: 11th Nov 2022 6:41
backgrounds[A].Sprite_X#

assuming you left .Sprite_X# as Float in your Type, you're comparing at a Sub-pixel level. IE, use INTs, instead.

then, if there's a chance that things can move more than a single pixel, get even more fuzzy/"approximate" as mentioned above.

and, if both objects are moving, then.... well, we don't know what (all) might be moving and by how much, so...

meanwhile, seems you've got things working... onward!
Posted: 11th Nov 2022 13:59
assuming you left .Sprite_X# as Float in your Type, you're comparing at a Sub-pixel level.


It was a float in my type, wow that sounds like a drink Can I get a "Float in my type please?"