How do I create object in grids?

Get help using Construct 2

Post » Tue Jun 30, 2015 9:46 pm

Hey guys,

I have a layout and I want to split it to 6*6. On any touch start, an object should be created in one of this 36 cells that nearest the touch position.

I made it with placing 36 invisible sprites and when player touch the sprite, I spawn an object but I am looking for a better way to make it without using that much object.

I really appreciate if you guys give me any clue helps me to achive this.

Thank you!
Image
B
58
S
25
G
39
Posts: 449
Reputation: 23,723

Post » Tue Jun 30, 2015 10:10 pm

When the player touches the screen, create an object at the location:

X: floor(TouchX / (LayoutWidth / 6)) * (LayoutWidth / 6)
Y: floor(TouchY / (LayoutHeight / 6)) * (LayoutHeight / 6)

I don't have access to C2 right now, so I'm unsure of the exact expression names, but this is the general method.

EDIT: For the record, this presupposes a sprite with the origin in the top left.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,106

Post » Tue Jun 30, 2015 11:19 pm

@linkman2004 It works :) Thanks a lot!
Image
B
58
S
25
G
39
Posts: 449
Reputation: 23,723


Return to How do I....?

Who is online

Users browsing this forum: Colludium, varr, Yahoo [Bot] and 3 guests