[SOLVED] Setting collisions with the image API

ariakbari

  • *
  • Posts: 40
Hello,

I've nailed a few solid mechanics down in my current game and am now looking to correctly manage my scenes. Each scene is 3200 x 2400 (it's my understanding scene size doesn't effect game performance much, more what's going on in the scene) as I would like the scene to hold a maze that the player must shoot a ball through. I would like to have multiple levels in the game, so therefore multiple scenes around this same size. My Screen size is 320 x 480.

My problem is, drafting up a 3200 x 2400 maze in photoshop with lines running all over won't be doable when trying to place it as an actor. Nonetheless one of them per level. I've used image instances before and assume this is the route, but I am unfamiliar with it's capability with collisions.

If I place these 3200 x 2400 image instances in each of my scenes is there a way for me to set up collisions allowing the ball to bounce off walls correctly and what not? I am of course familiar with collisions with actors, and had my character bouncing perfectly off walls on a smaller scale, I'm just not sure how it works with the image API. I assume possibly something with the "get pixel" block? I tried a few things to no avail.

Any and all help is appreciated. Will gladly go into further detail if needed. Thanks!

« Last Edit: October 13, 2018, 03:25:15 pm by ariakbari »

Luyren

  • *
  • Posts: 1499
I recommend looking into using Terrain Regions before attempting collision with images. They are regions with solid collisions, so you could place them on your scene to make the collisions for walls in your mazes.
Working.

ariakbari

  • *
  • Posts: 40
I recommend looking into using Terrain Regions before attempting collision with images. They are regions with solid collisions, so you could place them on your scene to make the collisions for walls in your mazes.

Got it. Considering I am creating each maze via image instances though, my maze is not present in the scene designer. Is there a way for it to be, so I can easily add custom terrain where I need? I see a "create region" block as well, but it seems that's different than terrain so not sure if I could use that. 

How else am I able to easily add terrain regions to the correct spots? I'm used to attaching image instances to an actor and in doing that they are not shown in the scene designer. Better way to create image instances to allow this?

Thanks for the help.

Luyren

  • *
  • Posts: 1499
If you are creating everything with blocks, then I'm afraid there is no easy way to make them show in the scene designer. But you can work around this, just need some extra effort. Some ideas, since I don't know your exact setup:

If your final image is the same size as the scene, you can in photoshop pinpoint the spots where you'd need the terrains, with their dimensions and positions (remember that the top left corner is x: 0, y:0), assuming you have the full image in photoshop. You can set a terrain/region's position and dimensions precisely in the Inspector tab inside the scene designer, so that should be doable.

If you don't have a mock up, and your images are individual pieces, you could test game, your behaviors would assemble the full image, and you could screenshot the whole thing and stitch it together, then do the above process.

Another idea, unrelated with terrains, are the blocks under Actor> Properties > Collision Shapes. You could have an actor created at the position of every one of your image instances that would have a collision, and setup a collision shape to match the image's position and dimensions. I've never used them though, so I don't know if that would suit your needs.

EDIT: And of course, you can create the terrain regions with code blocks, or there might be an extension for terrain blocks in the forums.
Working.

ariakbari

  • *
  • Posts: 40
If you are creating everything with blocks, then I'm afraid there is no easy way to make them show in the scene designer. But you can work around this, just need some extra effort. Some ideas, since I don't know your exact setup:

If your final image is the same size as the scene, you can in photoshop pinpoint the spots where you'd need the terrains, with their dimensions and positions (remember that the top left corner is x: 0, y:0), assuming you have the full image in photoshop. You can set a terrain/region's position and dimensions precisely in the Inspector tab inside the scene designer, so that should be doable.

If you don't have a mock up, and your images are individual pieces, you could test game, your behaviors would assemble the full image, and you could screenshot the whole thing and stitch it together, then do the above process.

Another idea, unrelated with terrains, are the blocks under Actor> Properties > Collision Shapes. You could have an actor created at the position of every one of your image instances that would have a collision, and setup a collision shape to match the image's position and dimensions. I've never used them though, so I don't know if that would suit your needs.

EDIT: And of course, you can create the terrain regions with code blocks, or there might be an extension for terrain blocks in the forums.

Thank you, this is very helpful. Your first suggestion sounds the most suitable for me. I appreciate all the help.

 One last question- Since I have to do it many times over and over, I'm considering simply using the maze images from photoshop as a background in the scene allowing me to see it in scene designer. Then be able to place the custom terrain boxes from there. Is using image instances as opposed to a background per scene going to be significantly less impactful on my game performance/size?

« Last Edit: October 10, 2018, 07:15:31 pm by ariakbari »

Luyren

  • *
  • Posts: 1499
Thank you, this is very helpful. Your first suggestion sounds the most suitable for me. I appreciate all the help.

 One last question- Would I be better off simply using the maze images from photoshop as a background in the scene allowing me to see it in scene designer? Then place the custom terrain boxes from there. Main question being, is using image instances as opposed to a background per scene going to be significantly less impactful on my game performance/size?
If you have the option to use the whole image as background, then yes, I think that would be the easiest way to setup collisions. I'm not really sure about performance though. I haven't used images that size to know how it will impact a game. I would go with backgrounds first, and try an alternative if it hinders the game too much.

And just a reminder: you might want to uncheck the project scales you aren't using for your game, to save up on game size (Settings > Settings > Advanced).
Working.

ariakbari

  • *
  • Posts: 40
Thank you very much, I'll try each as a background and see what the impact is. I'll make sure to uncheck unneeded scales as well. Much appreciated.

ceosol

  • *
  • Posts: 2213
Collisions with the image API are pretty simple. Just say:

if (get pixel x: y: of image)  = 16711680
    set velocity to 0
    set onground to true

16711680 is red. You would have have to figure out whatever color value you want to count as the colliding part. The x and y in the image is wherever your character is that you want colliding.

ariakbari

  • *
  • Posts: 40
Collisions with the image API are pretty simple. Just say:

if (get pixel x: y: of image)  = 16711680
    set velocity to 0
    set onground to true

16711680 is red. You would have have to figure out whatever color value you want to count as the colliding part. The x and y in the image is wherever your character is that you want colliding.

Hey,

I just saw this, thanks for the help. I've got the color value for the parts I want my character to be colliding off of. In my case, my character is a ball bouncing off walls in all different directions in a maze. How can I set his velocity/speed to have him properly bounce off each wall upon collision? Setting velocity to 0 he will just stop on collision.

Like if right side of character hits a wall, set x-speed to negate absolute value of (x speed of character). Thus bouncing in opposite direction. Any way to do this for each collision with the image? Using the right side left side hit blocks won't work...

Let me know, thanks. Can explain better if needed.

« Last Edit: October 12, 2018, 11:41:58 pm by ariakbari »

ariakbari

  • *
  • Posts: 40
Just put this together, it's working for me currently. Let me know if there's a better way for it to be done. This seems to function fine though for what I just explained. Thank you for the help! All collisions are being picked up and it works flawlessly! Had no clue you were able to point to color value like that.

ceosol

  • *
  • Posts: 2213
Yeah, it is neat. The absolute value and negate definitely work. You could also multiple the current speed by -1 to make it go in the opposite direction.