0 Favourites

How do I compare two tiles

  • Hi guys,

    I am a begginer to construct 2 . In the below image there are 4 tiles.when i drag first tile over second tile ,the numbers in 1st and 2nd tile should be changed and also the colors..

    how to do this ? ...

    and next thing i want to know is

    when i tap a tile it should change both its numer and color..they sould be predefined ... i.e each tile has three set of number and colors and when the user taps it should change to second set ,when they tap for third time it should change into third set and if they tap for 4th time i should again change to 1t set...

    somebody please tell me how to do these things in construct

  • someone please tell me solution

  • Well, there are a lot of things you asked to know how to do there, and a lot of parts to each of those things. Without knowing how far you've gotten on each part, you're basically asking someone to make your game for you. It would help a lot if you made an effort to try it on your own and ask a specific questions where you got stuck. If you upload an example of what you've got so far, it would also help in seeing what type of advice to give to you by showing your level.

    Otherwise... to start - I would use one sprite object for the tiles. Each animation frame should be a different color and value. The animation frame number can be the same as the value on the tile, so when you have two overlapping, you can add both tile's animation frame numbers to get your new number.

    Actually before that you probably want to figure out how to drag tiles around.

    So again, what are you stuck on?

  • Yeah-- pretty loaded question, I'm guilty of doing the same thing as far as not forming the right or specific question. Here are my 1st thoughts--

    How many Sprite objects do you have? Meaning I would have Sprites that have different colors programmed in the animation, then set conditions to change those colors.

    Are you pining text objects? I would then pin text objects to sprites. Make some visable and in-visible, and set conditions to have them change states.

    Was this helpful?

  • As i said i am a beginner so i dont know much about creating events...sorry for inconvinience,but i have to submit a project within a week so please bear with me ..i need just some hints or tips on complex functions ,i can see through web for common functions....

    The below link is the capx file

    bit.ly/1ntMMLs

    I want to change the first two tiles to green when the user drags first tile over second or second over first.

    how to do that ?

    P.S i can change both to green by using conditions but dont know how to make a smooth drag and dont cosider those numbers in the first pic(on my first post).

    NOTE : the word "drag" is not appropriate...it would be better if someone tells me how to use swipe from one tile to another.

  • OK couple more pieces of advice:

    I highly do not recommend using a program you are unfamiliar with to meet a time sensitive deadline.

    If you are new to Construct, try to avoid using plugins. You can do almost everything with what is included in Construct, and it will be significantly harder to get help on the forums if you use a bunch of plugins. People won't be able to open your file if they don't have the same plugins installed, and few people will go out of their way to install them to help you.

    Now about your project:

    Will each number always be tied to the same color? In that case, you should just draw the number as part of the sprite instead of using a text object.

    I see three main things you need to work on.

    First is preparing your tiles. As I suggested, you should create a single sprite object containing all of your tiles, with each number corresponding to the same animation frame. Set the origin point to the center.

    Second is moving the tiles. You mentioned dragging and swiping. These are two rather different things. Dragging would be relatively easy, while swiping could be rather hard. For dragging, you'll need to add a few instance variables to the sprite: boolean called Active, as well as an OriginXVariable and OriginYVariable to return the sprite back to its original position:

    On touched TileSprite | Set OriginXVariable to Self.X
                          | Set OriginYVariable to Self.Y
                          | Set Active to True
    
    TileSprite Active is True  |  TileSprite Set position to Touch.X, Touch.Y
    
    On touch release     | Move TileSprite to OriginXVariable, OriginYVariable
    TileSprite is Active | Set Active to False[/code:22ddonut]
    
    Third will be changing the tiles. You need to detect which two tiles are to be interacting (just using overlap will not work, as a tile can overlap several at the same time). Then you will change both tiles to the sum of their numbers/animation frame.
    
    Out of time for now, I'll be back with the third part later if you can't figure it out.
  • For the third part you'll want a global variable called Total, to add up the two animation frames.

    Touch - On touch release       | Add TileSprite.AnimationFrame to Total
    Touch - Is touching TileSprite | 
    System - For Each TileSprite   |
    
    (Make a separate event)
    
    Touch - On touch release       |Set TileSprite.AnimationFrame to Total
    Touch - Is touching TileSprite | Set Total to 0
    
    [/code:wojoighu]
  • Thanks for your help...I tried the code you have written

    I have two doubts

    1.

    On touch release | Move TileSprite to OriginXVariable, OriginYVariable

    i couldnt use the above code...it shows only pixel values

    2.On the previous capx (included in above reply) i made four sprites and included 3 animation frames to each tiles

    and created four evens to make those tile change their color when tapped ....how to get these effect(to change only 3 different color on each tile in that square) by using single sprite (Tilesprite).

  • Sorry those should be Self.OriginXVariable and Self.OriginYVariable.

    For changing on tap, you can use sub events on the Touch - On tapped TileSprite condition, then compare values.

    Touch - On tapped TileSprite 
           
             System - Compare two values - TileSprite.AnimationFrame = 4 | TileSprite Set Animation Frame to 7
             System - Compare two values - TileSprite.AnimationFrame = 7 | TileSprite Set Animation Frame to 11
             System - Compare two values - TileSprite.AnimationFrame = 11 | TileSprite Set Animation Frame to 4[/code:fqbomx5c]
  • I got another one week time to complete my project. I implemented swipe function but now i m struck.

    bit.ly/1R2TLDx

    the above link is the capx file.i have spawned four tiles using a single sprite and in each tile i displayed animation frame (0,3,6,9).

    i have totally 11 frames in tht sprite. when i tap the first tile it should change to next frame,on next tap on t1(tile 1) it should change to next frame but it shouldn't exceed frame 3...after frame it should start from frame 1...like that for tile 2 frames (should b 3,4,5) ;tile 3=(f 6,7,8);t4=(f 9,10,11)......how to do this ?

    i made a pseudo code but it not working..

    PSEUDO CODE

    on tap gesture on block |

    while(x<4) | block.color=block.color+1 //color is instance variable

    if(x>3) | block.color=block.color-3

    | x=0

    someone tell me how to make this pseudo code work

    and i have another doubt i will post it once i got this cleared ,at the same time i ll try to implement tht myself.

  • someone tell me a solution

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I got another one week time to complete my project. I implemented swipe function but now i m struck.

    http://bit.ly/1R2TLDx

    the above link is the capx file.i have spawned four tiles using a single sprite and in each tile i displayed animation frame (0,3,6,9).

    i have totally 11 frames in tht sprite. when i tap the first tile it should change to next frame,on next tap on t1(tile 1) it should change to next frame but it shouldn't exceed frame 3...after frame it should start from frame 1...like that for tile 2 frames (should b 3,4,5) ;tile 3=(f 6,7,8);t4=(f 9,10,11)......how to do this ?

    i made a pseudo code but it not working..

    PSEUDO CODE

    on tap gesture on block |

    while(x<4) | block.color=block.color+1 //color is instance variable

    if(x>3) | block.color=block.color-3

    | x=0

    someone tell me how to make this pseudo code work

    and i have another doubt i will post it once i got this cleared ,at the same time i ll try to implement tht myself.

    Ok you have a few issues here. First you don't need a "While" condition- that will make the event run over and over again until the other conditions are false.

    Second you don't want the x>3 as a sub event of x<4 - the sub event will only run if the parent event does - basically if x is 4, the parent event won't run, and the sub event won't either.

    From there you also have a couple more problems. One is that your x global variable will cycle 0-1-2-3-4-1-2-3-4-1... ect, but this global variable will be shared for all your blocks and not each one individually.

    The other problem is that Block.color as an instance variable, and doesn't actually change the color of the block or do anything at all by itself. You want Block - Set animation frame to Block.AnimationFrame+1.

    Put those two together and you might realize your animation frame will keep going up no matter what your x variable is, so you'll need to rethink through your logic a bit. You probably don't need the x variable at all. I suggest having an instance variable for your block with the starting frame number.

    Block.AnimationFrame < Block.OriginalFrame+4 | Block - Set animation frame to Block.AnimationFrame+1
    Block.AnimationFrame = Block.OriginalFrame+4 | Block - Set animation frame to Block.OriginalFrame[/code:11biidh9]
  • I have made the changes u told....it still has two problem..

    1.Only two tiles are working

    2.How to set instant variable to starting frame number since each tile has to start with different frame numbers

    bit.ly/22nqdeF

    And my final doubt in this project is

    When the user swipes a tile over another( or towards another tile) both tiles should change into a diiferent frame. That is after tap gesture is implemented each tile will have four frames .so how to change frames of both tiles ( one which is swipinging and another which is target or swiped into).I think the above question will have a very long code ..so tell me a basic concept or code for one tile i can manage to do for others.

  • someone help me

  • The first two problems are related - to set the origin frame, you would use the action Block - Set originalframe to Block.AnimationFrame.

    The swiping was more complicated than I expected without Families (I'm assuming you're using the free version of C2), so I've put together an example with comments here (with help from R0J0hound) -

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

    The next thing to figure out would probably be how to handle looping - I've included a bit for when newcolor is higher than the amount of animation frames you have, then it will loop back by using % (modulo). I didn't add that for when you tap the colors though - so if your color tries to change to a color higher than the number of animation frames you have, it will just get stuck.

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