How do I erase certain tiles.

Get help using Construct 2

Post » Wed Mar 23, 2016 7:42 pm

So I'm making a terraria-like game, but I don't know how to phrase an event that would delete the tile my player is standing on when i press space. Someone please help.

P.S. The player is 10, 10 size and the tiles are 16, 16 size
B
25
S
6
G
4
Posts: 173
Reputation: 3,933

Post » Wed Mar 23, 2016 7:58 pm

In the manual there is an action for erase tile:
https://www.scirra.com/manual/172/tilemap

So the only other thing you need is a reference of where your character is on the tilemap, which I assume the second expression on that page will work -> PositionToTile

Then you would have to add 1 to the Y tile so it destroys the tile underneath the character's feet.
ImageImageImage
B
44
S
26
G
11
Posts: 518
Reputation: 10,502

Post » Wed Mar 23, 2016 8:41 pm

badmoodtaylor wrote:In the manual there is an action for erase tile:
https://www.scirra.com/manual/172/tilemap

So the only other thing you need is a reference of where your character is on the tilemap, which I assume the second expression on that page will work -> PositionToTile

Then you would have to add 1 to the Y tile so it destroys the tile underneath the character's feet.

ya but can u give an example. I dont know how to phrase
B
25
S
6
G
4
Posts: 173
Reputation: 3,933

Post » Wed Mar 23, 2016 9:40 pm

I'm not near Construct right now but I would wager
On Space
-Erase Tile: PositionToTileX(CharacterSprite.x), PositionToTileY(CharacterSprite.y)-1

Or, if tile size 16 then PositionToTileY(CharacterSprite.y-16)

I can take a look in Construct later and be more exact but that's the idea.

Also, I would actually wrap it in a function so you can reuse it later
On Space -> Call.Function("eraseTile", PositionToTileX(CharacterSprite.x), PositionToTileY(CharacterSprite.y-16))

Function "eraseTile"
-Erase Tile
--X = function.param(0)
--Y = function.param(1)

But if you aren't familiar with functions start the testing without it
ImageImageImage
B
44
S
26
G
11
Posts: 518
Reputation: 10,502

Post » Wed Mar 23, 2016 10:26 pm

@badmoodtaylor its not working. Can you upload a capx? Or should I to see if something is wrong
B
25
S
6
G
4
Posts: 173
Reputation: 3,933

Post » Wed Mar 23, 2016 11:38 pm

Sorry it took a little while, I was at work before.

...and I took a little time to make the capx fun (for me at least):

https://www.dropbox.com/s/z4erazryf5tb0 ... .capx?dl=0


I organized and commented everything to try and make it easy to follow but feel free to ask me any questions!

Enjoy!


*Note: The images were obviously taken from Mario 2. I hope that doesn't get me in trouble anywhere as this was only for learning purposes.
ImageImageImage
B
44
S
26
G
11
Posts: 518
Reputation: 10,502

Post » Wed Mar 23, 2016 11:42 pm

...after playing around a little with the grenades this actually makes me want to make a game with a totally destroy-able environment. Imagine instead of Toad a guy with a bazooka completely wrecking a city . . .
ImageImageImage
B
44
S
26
G
11
Posts: 518
Reputation: 10,502


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 37 guests