How do I set cursor from sprite in a better way

Get help using Construct 2

Post » Sat Mar 15, 2014 4:52 am

Someone knows how to do this without puting all the objects in the condition?cause its not a problem now, but will be when I have hundreds or thousands of colectable objects. And, in my understanding, it will decrease the performance a lot of the game. Someone knows if it's even true or a solution for it?


Image

Thank you
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Sat Mar 15, 2014 4:57 am

That depends,
If you have at least the personal version, use families for everything
Either way, It looks like some objects are cloned, is there a difference between trees 1 and 2?
B
52
S
10
G
7
Posts: 184
Reputation: 6,850

Post » Sat Mar 15, 2014 5:02 am

Your not actually using 1 Sprite Object for each different Game Object?

no no no

Use 1 Sprite Object and then use the animation frames to distinguish the image. Also add a variable to the Object called say TYPE of text. Then write down the TYPE ie TREE, ROCK, WELL, WHEAT..... um no you don't need to use CAPITALS, I only used them to identify key words.

So you can nicly sum up all your actions to

Cursor over Collectables
-- set CursorSprite.animation(Collectable.type)
-- mouse.setCurstorFromSprite( CursorSprite )


And then that's it.

This also makes your life easier than just EventCode too. In fact when you a tree image in your Collectables Sprite Object under say the animation name of "TREE". Then you just need to set the default animation to TREE for that object. Then you can copy/paste the tree where ever you want.

Then you take that tree and add a rock image to the animation name of ROCK. Clever huh :D. then set the default animation to ROCK. THen you can copy and paste your rock ALL over the place.

And best of all you EventCode will work the same for your mouse cursor change.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Sat Mar 15, 2014 6:05 am

jayderyu wrote:Your not actually using 1 Sprite Object for each different Game Object?

no no no

Use 1 Sprite Object and then use the animation frames to distinguish the image. Also add a variable to the Object called say TYPE of text. Then write down the TYPE ie TREE, ROCK, WELL, WHEAT..... um no you don't need to use CAPITALS, I only used them to identify key words.

So you can nicly sum up all your actions to

Cursor over Collectables
-- set CursorSprite.animation(Collectable.type)
-- mouse.setCurstorFromSprite( CursorSprite )


And then that's it.

This also makes your life easier than just EventCode too. In fact when you a tree image in your Collectables Sprite Object under say the animation name of "TREE". Then you just need to set the default animation to TREE for that object. Then you can copy/paste the tree where ever you want.

Then you take that tree and add a rock image to the animation name of ROCK. Clever huh :D. then set the default animation to ROCK. THen you can copy and paste your rock ALL over the place.

And best of all you EventCode will work the same for your mouse cursor change.


I didn't understand really well for the both tips. In this way, can I set different values, even using just one sprite with a bunch of diferrent animations (Tree, Rocks, etc)? Cause I need to control the loot of every single rock, tree, etc. For example: I see two rocks in the screen and then I collect all the loot of one rock, then I'll to another rock to collect more. Then, after 5 min(it start counting right after ends its loot), reset the loot again so I can collect more.

Thats how I've being doing about the collectable objects.

Image

About the cursor, I didn't understand at all. If you print an example event I will appreciate a lot.
Last edited by kossglobal on Sat Mar 15, 2014 7:29 am, edited 2 times in total.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Sat Mar 15, 2014 6:56 am

Yarfapet wrote:That depends,
If you have at least the personal version, use families for everything
Either way, It looks like some objects are cloned, is there a difference between trees 1 and 2?


Yes, they must have different instance variables to store their loot. So I can collect wood from tree 1 until it ends, then I collect more wood from tree2. The object didnt get destroied. Instead of it, I restore the loot after a couple minutes.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Sat Mar 15, 2014 8:22 am

kossglobal wrote:
Yarfapet wrote:That depends,
If you have at least the personal version, use families for everything
Either way, It looks like some objects are cloned, is there a difference between trees 1 and 2?


Yes, they must have different instance variables to store their loot. So I can collect wood from tree 1 until it ends, then I collect more wood from tree2. The object didnt get destroied. Instead of it, I restore the loot after a couple minutes.


From the sound of it,, the only difference between the two trees is how much wood they have. You can easily use the same object for both of them, instance variables are calculated and stored on a per instance basis. You could have any number of "tree1"s and set them all differently, and if you take loot from one "tree1" the other won't lose it's loot; as long as you make a distinction in your events, construct will pick out the right one. If you need to restore them back to a certain number in a few minutes, just make a second value to set it back to.
B
52
S
10
G
7
Posts: 184
Reputation: 6,850

Post » Sat Mar 15, 2014 9:12 am

Yarfapet wrote:
kossglobal wrote:
Yarfapet wrote:That depends,
If you have at least the personal version, use families for everything
Either way, It looks like some objects are cloned, is there a difference between trees 1 and 2?


Yes, they must have different instance variables to store their loot. So I can collect wood from tree 1 until it ends, then I collect more wood from tree2. The object didnt get destroied. Instead of it, I restore the loot after a couple minutes.


From the sound of it,, the only difference between the two trees is how much wood they have. You can easily use the same object for both of them, instance variables are calculated and stored on a per instance basis. You could have any number of "tree1"s and set them all differently, and if you take loot from one "tree1" the other won't lose it's loot; as long as you make a distinction in your events, construct will pick out the right one. If you need to restore them back to a certain number in a few minutes, just make a second value to set it back to.


See the pic I posted before? There is showing how I did and how I restore the instance variable(the loot). But using the same object like you are saying, I really don't know how to do this. The way I did, using the same tree object, I collect both but to restore that really gets me. How do I say to construct that it's needed to restore the loot of these 2 trees, which is the same object and respecting the delay of each one, otherwise they would be restored all in the same time.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Sat Mar 15, 2014 10:27 am

@kossglobal
Make another variable holding the timer. If wood=0. Subtract dt from timer. If timer less than or equal to 0. Set the timer and Wood back to their original values (To specify a restock time and amount per instance, just create just create a value for each, and set each to those values. Otherwise, just put a number to set them back to). There's also a timer behavior you can use, but it can be a bit tricky to work with.
B
52
S
10
G
7
Posts: 184
Reputation: 6,850

Post » Sat Mar 15, 2014 5:20 pm

Yarfapet wrote:@kossglobal
Make another variable holding the timer. If wood=0. Subtract dt from timer. If timer less than or equal to 0. Set the timer and Wood back to their original values (To specify a restock time and amount per instance, just create just create a value for each, and set each to those values. Otherwise, just put a number to set them back to). There's also a timer behavior you can use, but it can be a bit tricky to work with.


I think I got it. I'll try it as soon as possible..

Thank you, man!
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Sat Mar 15, 2014 8:34 pm

Thank you! I did like this and it works, apparently. I put 2 trees, which is the same object, and both have it's loot restored respecting the cooldown.
Image

I don't know if it was exactly like you were saying but what's your opinion about the events?
Thank you again buddy. I really appreciate the help.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612


Return to How do I....?

Who is online

Users browsing this forum: ChoosyZerk and 59 guests