Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: About images/sprites and alpha and getting an image color  (Read 2459 times)

0 Members and 1 Guest are viewing this topic.

AdventWolf

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
About images/sprites and alpha and getting an image color
« on: October 15, 2011, 03:33:16 am »
It is kind of hard to get an accurate title for this question.

Okay what I am trying to do is display a picture and lets say it is an empty square. It is simply just the outline of a square and the inside is transparent.

The sprite needs to be used to test collision, so the character can move freely inside where the picture is transparent, but the character can not move passed the colored walls.

Is it possible to get a position inside an image and tell if that spot is transparent or a specific color?

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
About images/sprites and alpha and getting an image color
« Reply #1 on: October 15, 2011, 06:25:24 am »
You can use image.getpixel(x, y) and look a the return value.

Though things might be easier if you simply compare the player position to a rect of the same size as the image and bump the player back if they go outside it.

AdventWolf

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
About images/sprites and alpha and getting an image color
« Reply #2 on: October 15, 2011, 06:59:03 am »
That's true, but what I'm really trying to do is set all of the barriers in a level to a single image.

That way I could just draw a single image, and i could just check collision against a single image. Though I'm not sure what kind of difference it would make.

I think I will just check against the individual barriers, but would it make much difference to have a separate image with all of the barriers copied to it and just draw that image?

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
About images/sprites and alpha and getting an image color
« Reply #3 on: October 15, 2011, 09:43:37 am »
Generally, you should be fine to do them all individually. It should make your code simpler as well to have them as individual objects.

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
About images/sprites and alpha and getting an image color
« Reply #4 on: October 15, 2011, 10:48:08 am »
The general advantage AND disadvantage of your approach is that the only reasonable way to do it is per-pixel collision.

It's very precise, however also costs a lot of CPU time.

If you really want to implement it, divide the scene into individual objects, as was said earlier. Then generate collision bitmap from top-view for every object. First test against AABB, then against the bitmap with per-pixel.

I also assumed that you need something more than rectangle-rectangle collisions. If not, just skip the second step of what I said earlier.