2017년 7월 18일 화요일

is it possible for a sprite to detect is its touching a color?


hi, i was wondering if its possible for a sprite (ball) to detect is its touching a color (light blue). i have tried many times, but i simple cant find out.

--
Maybe... You'd have to check every pixel for it's color, and no matter how hard you try, that'll be very consumptive in AI...

You'd have to analyze the color of each pixel based upon it's location... Use the Canvas.GetBackgroundPixelColor, and pass it the x,y of each tick, but expect the deal to be VERY slow...

--
Try here ...

Ball, Canvas: Bounce a ball off a drawing on the Canvas


The first link (Scott Ferguson) in this thread discusses this.

--
Please not that Scott's example is an AI Classic project... you'll have to convert it to AI2...

--
thanks for the link, but sadly i didn't work. i put in some screen shots of my app, i was wondering if u have any suggestions. 
i want to make it so when the ball (red thing) touches the light blue, it would trigger the game over screen. the light blue, is just a picture with white and blue.


i do not know of any other way to fix it. so if u come up with any ideas please tell me

--
You appear to have different timers for different stuff... That's NOT the way you should do this.  You need to check that color every time you move the sprite, which I'm sure, is in another timer.... Do this in there... When the sprite moves, check the color.

Also, why open another screen when the game is over?  Just put up a Notifier... you can also change the image in the background of the same screen...

--
what is the timer interval of your clock?
what happens, if you set the ball manually to a x/y coordinate with the light blue background?
use Do it to debug your blocks

--
im some what confused... could you show me how you would do it in the same timer?

--
Perhaps     

1. http://rosettacode.org/wiki/Color_of_a_screen_pixel      

App Inventor has two Canvas blocks to determine the color under a pixel.
GetBackgroundPixelColor returns a color from the Canvas but ignores Ball sprites and ImageSprites.
GetPixelColor returns a color from either the Canvas or a Ball sprite or ImageSprite.
In the app's display below, the purple Ball sprite was touched on the left canvas, but the pixel color (green) returned was from the area below it.


2. https://lh4.googleusercontent.com/-Gw0xm7RIEck/Uute2nQSGsI/AAAAAAAAJ90/rq3UuWYE9Yw/s1600/Capture.PNG  


might help

--
thanks for the link, but sadly it still doesn't seam to work, ive tried another way, by setting the canvas background color to the light blue, and making the path a white .PNG, do u know if there would be any way i can detect if the ball comes off the path (touches the blue canvas)?

--
Post a screenshot of how and where you're moving the ball...

--

댓글 없음:

댓글 쓰기