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

Get help using Construct 2

Post » Mon Aug 01, 2016 10:37 pm

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.
Image

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


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.
B
4
S
1
Posts: 2
Reputation: 304

Post » Mon Aug 01, 2016 11:14 pm

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.
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Tue Aug 02, 2016 12:33 am

Prominent wrote: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
Image

Thanks a lot! I can now continue to make my game and hopefully finish it before I die. :)
B
4
S
1
Posts: 2
Reputation: 304


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests