How do I change a sprite's colour when it's condition is met?

0 favourites
  • 13 posts
From the Asset Store
Color all tiles with the same color in 22 moves or less!
  • I have a game where you have to park a car, so i was going to make it so the parks would have a green sprite, indicating you can park there.

    I was hoping that when the player, or AI, park in a space, the green sprite would then turn red.

    I've looked into it, but I think I might be using the wrong descriptors to get an answer.

  • What problem are you having? What have you tried so far?

  • condition

    distance(car.x,car.y,parkinglot.x,parkinglot.y) =< 20

    abs(car.speed) =< 5

    trigger once

    action

    parkinglot.set_animationframe to 1 or the red color frame number.

  • What problem are you having? What have you tried so far?

    At the moment I am using a green sprite and the event

    Park_open [name of sprite] is overlapping player, set color to rgb(100,0,0)

    Player set position to Park open (image point 0)

    It's coming up a weird brown colour, like it's adding the red to the green. I also have a red sprite but I have no idea how to use the animation or even if I can, because I am using the free version.

    I wanted to make it that the car can't move once it is "parked" but at the moment, as soon as the sprites touch, it activates.

  • condition

    distance(car.x,car.y,parkinglot.x,parkinglot.y) =< 20

    abs(car.speed) =< 5

    trigger once

    action

    parkinglot.set_animationframe to 1 or the red color frame number.

    Sorry, I am still new to coding and attempting to wrap my head around things.

    I think I get distance (so if the car is less then 20 in relation to x and y's parking lot it activates)

    I'm not sure about the car speed though.

    If you could try and explain it in simple terms (sorry), I would appreciate it.

  • I'm not sure about the car speed though.

    If you could try and explain it in simple terms (sorry), I would appreciate it.

    by car.speed i meant if u are using the 4 or 8 directions to move the object i think it gives u a current speed expression which u can double check if the player actually stopped on the parking lot and not moving backwards from inertia.

    not sure now what movement behavior you are using. it depends on that to keep track of the car speed . but that is more of a safety thingy.

  • Why not just use an collision condition?

    When CAR is COLLIDING WITH PARKING SPOT

    AND CAR SPEED is less than 3

    Set CAR to rgb(whatever color)

    Or change animation frame.

    To make sure players park correctly you can make the parking spot hitbox smaller so they have to be more on the parking spot to register the collision.

    Hope this helps

  • Why not just use an collision condition?

    When CAR is COLLIDING WITH PARKING SPOT

    AND CAR SPEED is less than 3

    Set CAR to rgb(whatever color)

    Or change animation frame.

    To make sure players park correctly you can make the parking spot hitbox smaller so they have to be more on the parking spot to register the collision.

    Hope this helps

    using on collision would trigger the parking the moment the edges of the parking lot and car will collide with each other, and not when the car is actually on the parking lot. that's why comparing the distance from the parking lot X thinking it would have a centered origin point is a much better suit. cause at that point the car for sure would be over the parking lot.

    think of a 200px * 200px parking lot if has the center image in middle and 100px on each side, then if the car is at a distance of 20 or less from the center it means the car is overlaping the parking lot entirely, then double checking the speed would make sure the car has slowed down to a speed of 5 or 3 that is going downwards. however if there is movement that can make the car move by using innertia and slowing down in time, like physics cars for example the speed without pressing any keys from innertia would fluctuate from positive to negative values, that's why i said abs(car.speed) meaning any value that is under 3 or 5 its turned into a positive value even if its -100 speed it becomes 100 speed, therefore not being full stopped as would move backwards at a speed of 100.

  • > I'm not sure about the car speed though.

    > If you could try and explain it in simple terms (sorry), I would appreciate it.

    by car.speed i meant if u are using the 4 or 8 directions to move the object i think it gives u a current speed expression which u can double check if the player actually stopped on the parking lot and not moving backwards from inertia.

    not sure now what movement behavior you are using. it depends on that to keep track of the car speed . but that is more of a safety thingy.

    I was using the Car behaviour. Lemme get a link to the project.

    dropbox.com/s/6btv33r64uwq2px/Petty%20parkers.c3p

    I'm trying to do it bit by bit because I do eventually want to make this in 3D, (Because it's supposed to be a multiplayer game). I haven't even attempted the Ai or the timer/score system.

  • I was using the Car behaviour. Lemme get a link to the project.

    https://www.dropbox.com/s/6btv33r64uwq2px/Petty%20parkers.c3p?dl=0

    I'm trying to do it bit by bit because I do eventually want to make this in 3D, (Because it's supposed to be a multiplayer game). I haven't even attempted the Ai or the timer/score system.

    here is what i was saying modified ur template petty-parkers-v1

    good luck with the multiplayer part :D

  • > I was using the Car behaviour. Lemme get a link to the project.

    > dropbox.com/s/6btv33r64uwq2px/Petty%20parkers.c3p

    > I'm trying to do it bit by bit because I do eventually want to make this in 3D, (Because it's supposed to be a multiplayer game). I haven't even attempted the Ai or the timer/score system.

    here is what i was saying modified ur template petty-parkers-v1

    good luck with the multiplayer part :D

    Okay. I see what you did. To be blunt, I had no idea you could edit the speed and such. It's still turning brown instead of red though and the car can still move. I'll see if I can fix that.

    Question, The spot will only turn red if the speed is under 3 right? That's what the >3 speed tag is right? I just want to make sure I have this correct. (Like I said, I want to understand and learn, not just be given solutions)

    Thank you so much for your help, by the way. I really appreciate it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Okay. I see what you did. To be blunt, I had no idea you could edit the speed and such. It's still turning brown instead of red though and the car can still move. I'll see if I can fix that.

    Question, The spot will only turn red if the speed is under 3 right? That's what the >3 speed tag is right? I just want to make sure I have this correct. (Like I said, I want to understand and learn, not just be given solutions)

    Thank you so much for your help, by the way. I really appreciate it.

    its turning brown cause i didn't changed the color u used, for red use rgb(red-value,green-value,blue-value) if you want it to be red u do rgb(255,0,0). ( i can't recall what effect u used to change the color but i remember something about color values, u have to adjust them manually to get the result u want.)

    it can still move cause i thought u know how to go on further from there. u can disable the car.behavior when parking lot changes color.

    action> car.set_carbehavior- enable/disable

  • > Okay. I see what you did. To be blunt, I had no idea you could edit the speed and such. It's still turning brown instead of red though and the car can still move. I'll see if I can fix that.

    > Question, The spot will only turn red if the speed is under 3 right? That's what the >3 speed tag is right? I just want to make sure I have this correct. (Like I said, I want to understand and learn, not just be given solutions)

    > Thank you so much for your help, by the way. I really appreciate it.

    its turning brown cause i didn't changed the color u used, for red use rgb(red-value,green-value,blue-value) if you want it to be red u do rgb(255,0,0). ( i can't recall what effect u used to change the color but i remember something about color values, u have to adjust them manually to get the result u want.)

    it can still move cause i thought u know how to go on further from there. u can disable the car.behavior when parking lot changes color.

    action> car.set_carbehavior- enable/disable

    I knew how to kinda stick it to the car park sprite through objects rather than cease the car movement all together using coding. Like I said, I didn't know I could edit things like speed as there isn't really that many tutorials on this. It's just the beginner tutorial which is just for the shooting game. Not much help in this case. =/

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