I need help with my project

For questions about using Classic.

Post » Tue Dec 29, 2009 2:53 am

Hi there

Couple of things that i want to understand but i cant figure out. Been pondering about this for hours.

*** Please download the .cap file to understand what i'm talking about. ***
[url:3db7ybma]http://internet.is/eski/buttongame.cap[/url:3db7ybma]

1. I'm trying to code this so i can only select one item at a time, basicly only shoot one item and when it has stopped you can shoot another. I have tried to have loop, for each, always and all, just cant get it to work.
I have tried to compare the velocity of the items to 0 but it randomly selects items so it doesn't always work.

2. I'm trying to make the line be maximum length off 300 pixels.

3. There are two "teams" blue and red. Its the same sprite, blue is one animation and red is another. So basicly i just change the animation. Ok so i'm trying to make a textbox in the corner count the total of each team. I have tried to use AV 0 for blue and 1 for red and used a event like this

Sprite Value Team Equal 0
- Set text to Sprite.Count

Should this not work right, it gives me the total, counts the blue and red.
I also tried to use a event that checked what animation was playing, same story.


I know i have asked alot of questions on this forum but i am really eager to learn basicly everything about construct :D


PS.
Can i Spread Values in AV on Instances to know them from each other ? Like puting ID's on them.
Whats the diff from uID and oID ?
Can Sprites have transistions when creating and destroying ? (or do i have to program them like fading)
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

Post » Tue Dec 29, 2009 4:22 am

[quote="eski":1gjnzkov]1. I'm trying to code this so i can only select one item at a time, basicly only shoot one item and when it has stopped you can shoot another. I have tried to have loop, for each, always and all, just cant get it to work.[/quote:1gjnzkov]

The easiest way is to click the mouse to choose a piece, then release the mouse to shoot it. You can still cancel with right-click this way.

What's happening is that your Click triggers are both triggering at once, that's why you're choosing more than one piece at a time.

[quote="eski":1gjnzkov]2. I'm trying to make the line be maximum length off 300 pixels. [/quote:1gjnzkov]

You can do this with clamp(). Clamp restricts a number between two other numbers. Like so:

clamp(target value [this is the actual mouse distance], minimum value [this is the lowest the width should be], maximum value [this is the longest it should be])

Abbreviated: clamp(target, min, max)

The easiest way to make your line stop at 300 pixels is by using the sprite object, because you can easily set the width. I changed it to sprite object and did the following:

Set width to: clamp(distance(line.x, line.y, mouseX, mouseY) - 5, 10, 290)

I set the target to mouse-distance-minus-5 so that the edge of the sprite wouldn't poke out past the point of the arrowhead. The min length is 10, and the max length is 290 instead of 300, again so the end won't poke out past the arrowhead.

Setting the arrowhead distance and position is a bit trickier. You basically have to orbit it around the line object's x and y. I used cos and sin to find the position:

Set angle to: angle(line.x, line.y, mousex, mousey)
Set X to: line.x+cos(Sprite3.angle)*clamp(distance(line.x, line.y, mouseX, mouseY), 10, 300)
Set Y to: line.y+sin(Sprite3.angle)*clamp(distance(line.x, line.y, mouseX, mouseY), 10, 300)

You may be able to use the Orbiter or Custom Movement behavior for that instead, if you don't like math. I just happened to have the orbit expression laying around from another project and I reused it.

The Custom Movement behavior has actions that will restrict the distance an object is from a point though, so it shouldn't be too hard to figure out.

[quote="eski":1gjnzkov]3. There are two "teams" blue and red. Its the same sprite, blue is one animation and red is another. So basicly i just change the animation. Ok so i'm trying to make a textbox in the corner count the total of each team. I have tried to use AV 0 for blue and 1 for red and used a event like this

Sprite Value Team Equal 0
- Set text to Sprite.Count

Should this not work right, it gives me the total, counts the blue and red.[/quote:1gjnzkov]

Apparently .Count isn't respecting the Selected Object List. You can get around that by using a For Each loop and picking the sprites by their Team value. Example in the .cap below.


[quote="eski":1gjnzkov]Can i Spread Values in AV on Instances to know them from each other ? Like puting ID's on them.

Can Sprites have transistions when creating and destroying ? (or do i have to program them like fading)[/quote:1gjnzkov]

You don't need to spread values in Construct. The picking system generally knows what you're talking about as long as you keep your conditions straight. On the off chance you come across a situation that doesn't pick what you want, try a For Each coupled with the condition you're using to pick with.

As for sprite transitions, you pretty much have to make your own. There is a Fade behavior you can put on your sprites that might help you out, but the way you're doing it now is pretty much right on the money.

Anyway, here's the .cap with the changes I made. I didn't comment anything though so if you have any questions about what I did feel free to ask.

http://dl.dropbox.com/u/529356/shuffleboardThing.cap
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Dec 29, 2009 4:26 am

By the way, that's a cool little idea for a game :). Nice and simple, but still requires skill. Like billiards.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Dec 29, 2009 12:29 pm

wow that was a good answear :D

few things..

How would i go to shoot only one item at a time but all items have to be stopped to do so ? Compare the velocity of all the items to 0 ? For each loop ?

I have always used system create object, you use spawn object.. is there difference between the two ?

The difference between uID and oID ?

When you are using for each command and loops and all that, do you have to set the addidional events as sub events ? (Like you do with the text counter)


Thanks for the complement, i like the concept of the game, going to change the graphics when i have finished the game engine :D

Btw... Thats some math calculations you used there, nice work ;D
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

Post » Tue Dec 29, 2009 12:55 pm

[quote="eski":1v78g7jh]How would i go to shoot only one item at a time but all items have to be stopped to do so ? Compare the velocity of all the items to 0 ? For each loop ?[/quote:1v78g7jh]

You might try setting a global variable like global('shoot') to 1 when a puck is shot. Then you can do something like this:

[code:1v78g7jh]
+ Global('shoot') = 1
+ puckSprite.Value('clicked') = 1
+ PuckSprite: Physics: Velocity = 0
-> Set global('shoot') to 0
[/code:1v78g7jh]

Then you could use the shoot variable as a condition when clicking on a puck.

[quote="eski":1v78g7jh]I have always used system create object, you use spawn object.. is there difference between the two ?[/quote:1v78g7jh]

They are similar, but spawning will set the angle of the created object to the angle of the originating object automatically. There might be some other differences, I can't quite remember at the moment, I just woke up and haven't had my coffee yet. Check the wiki.

[quote="eski":1v78g7jh]The difference between uID and oID ?[/quote:1v78g7jh]

UID is unique to each instance of an object, OID is the same for each instance of an object. You will very rarely ever have to use them since the picking in Construct is pretty solid, not like in MMF.

[quote="eski":1v78g7jh]When you are using for each command and loops and all that, do you have to set the addidional events as sub events ? (Like you do with the text counter)[/quote:1v78g7jh]

It depends on what you're doing. Since I was doing two different things to two different groups of the same object, I split them up into two different sub-events.

If you are performing the same actions on every object in your For Each, you can stack the conditions in the same event as the For Each.

[quote="eski":1v78g7jh]Btw... Thats some math calculations you used there, nice work ;D[/quote:1v78g7jh]

It wasn't really me... Probably Madster or Lucid or Quazi. I suck at math :P. I just keep little snippets of math like that for use whenever I need them.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Dec 29, 2009 1:24 pm

Allright, dont i have to compare the global variable shoot to 0 when i click on a puck ?

+on left mouse button click on pucksprite
+global variable shoot = 0
-> do shoot stuff and that

With this i can only shoot one time and then its frozen at shoot 1.

I should use Sprite[Physics].AngularVelocity right ?
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

Post » Tue Dec 29, 2009 1:37 pm

Hey, nice game concept!
B
107
S
40
G
10
Posts: 456
Reputation: 13,202

Post » Tue Dec 29, 2009 2:37 pm

thanks :D
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

Post » Tue Dec 29, 2009 5:30 pm

i think the problem is that construct doesnt know the diffrence between the instances..
I feel that is the problem, maybe i'm wrong.

For example

+On left mouse click on Sprite
+Sprite Velocity = 0
--> Set global variable shoot = 1

I feel like it takes a random sprite and checks that the velocity is 0 because sometimes it works and sometimes not...
Could it be some problem with the instances ?
Do i have to compare the uID on the clicked item to make sure that is the same item.. ?
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

Post » Thu Dec 31, 2009 4:21 am

OK !
finally i found a way to make it work, dont know if its the "right" way but its working.. but please comment on it :D

other thing that i cant figure out with the physics.. it so slow at stopping..
The speed and the contact damping is the way i like but its so slow to reach the point of zero speed, you can see the AV "speed" on the sprites what i'm talking about.

Anyways the file is here.
[url:12mwso29]http://internet.is/eski/shuffleboardThing.cap[/url:12mwso29]


edit: aahh.. took out some crap that i figured out :o

but there is a bug in the 0.99.97 construct...
If you have done some changes on a .cap file and quit the program it just shuts right off..
it doesnt ask you if you want to save the changes that you have maked.. didnt do this in version before this one :roll: (i think)
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests