How do I get Y-value from sprite over tiles.

0 favourites
  • 3 posts
From the Asset Store
Piano tiles
$4 USD
60% off
Template for a piano tiles game, fully documented in comments and video
  • Hello.

    I'm in the making of my first game, Construct 2 is excellent but I have now stopped my development since I can't get pass a hurdle.

    I am pretty far into my game and started using tilemaps to speed up my mapmaking a bit.

    Here's my problem:

    I use a big vertical sprite (laserHunting, 720 pixel in height) that with bullet behavior shoot across the screen and destroying everything it connects to which means everything on the map. This works great when using "on collision with" with other sprites. My problem is with tilemaps I can't get it to work.

    The problem is the Y-value that I try to get with mytilemap.PositionToTileY(mySprite.Y) always adds up to zero.

    If I set a fixed value in variable selectTileY it will destroy tiles but only tiles with the specific specify a Y-value.

    THIS WORKS when I try.

    This works with SelectTileY to 20 but I want to get Y from tilemapRed.PositionToTileY(laserhunting.Y) or something similar.

    When trying to output tilemapRed.PositionToTileY(laserhunting.Y) to a spritefont it gives me the value 0 which I guess is my origin of the sprite, not where it collide. How can I get a Y-value where the sprite collide with the tile?

    Thanks for a great product and hopefully someone can help me to go further.

    Seems pictures can't load in forum, right click image and open in new window/tab and it should work.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You'll have to calculate how many tiles high the laser is: round(laserhunting.height/tileheight). Or if laser height is constant, just make it a value of however many tiles high it is.

    Then create a for loop 0 to calculatedNumber.

    And use the tile position the laserhunter.y is currently on PLUS the loopindex value. That will give you the current tile position that should be erased.

  • You'll have to calculate how many tiles high the laser is: round(laserhunting.height/tileheight). Or if laser height is constant, just make it a value of however many tiles high it is.

    Then create a for loop 0 to calculatedNumber.

    And use the tile position the laserhunter.y is currently on PLUS the loopindex value. That will give you the current tile position that should be erased.

    Super! Thank you for helping.

    I did it like this and now it works.

    https://drive.google.com/open?id=0BwwMn ... UVrYmNiMXM

    Thanks a lot! I can now continue to make my game and hopefully finish it before I die. <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)