Cloning Sprites in MIT-Scratch - mit-scratch

Recently, in a project for school. I have come across an increasingly frustrating and what seems to be an unsolvable problem. Whilst attempting to create a diving game, in which the sprite of a diver (sprite x) touches clones of a fish sprite (referred to as y by me) to rack up scores as high as 25. While the mechanisms for diver movement appear to be completely fine. However, loading the game would result in no reaction from the fish and its clones. I had already programmed the clones of the fish sprites to hide and delete themselves if touching sprite x. However, the fish refused to clone itself even after many attempts at rewriting the script. I would like to know if there was anything I missed or screwed up. Thank you. And these are the images of the respective scripts of the sprites in links below. Thank you.

Here's your problem:
WHEN I RECEIVE "start game"
WAIT (2) SECS
REPEAT (25)
CREATE CLONE OF "myself"
WAIT (6) SECS
BROADCAST "game over"
You're starting the game, waiting 2 seconds, cloning the fish 25 times, and then ending the game.
There's at least one issue here, and probably another.
First of all, you're cloning all of the sprites into the exact same spot. The clones are piling on top of each other, giving the appearance of only being one fish, since they're all in the exact same space. I'd advise moving to a random x and y on the stage in between each clone.
Second, you have BROADCAST "game over" immediately there. This works if this is the way you're implementing a time limit on the game, but otherwise, you're just ending the game 6 seconds after the last fish appears.
So, correcting these two things, you end up with something like this:
WHEN I RECEIVE "start game"
WAIT (2) SECS
REPEAT (25)
GO TO X: ([RANDOM PICK (-200) TO (200)]) Y: ([RANDOM PICK (-150) TO (150)])
CREATE CLONE OF "myself"
WAIT (6) SECS
If you want each fish to disappear after 6 seconds, then add a DELETE THIS CLONE to the above script.
You can delete this script:
That's now covered by the other script, above, and is also slightly buggy. It's kinda useless now.
And, in your other script, the one starting WHEN GREEN FLAG CLICKED... to have the fish disappear when touching the diver, replace the WHEN GREEN FLAG clicked with a WHEN I START AS A CLONE.

Related

Why is my sprite constant in mint language?

He only moves a little bit and not moves forever
The (move 10 steps) block will only move your player by a tiny bit. It moves in the direction that your sprite is facing.
If you would like to have it moving for a longer period of time, (and smoother), I'd recommend using a loop of some kind.
Putting a Forever() loop around it will have it always move forward.
Repeat(number of times to repeat) will move it forward however many times you want.
Try to experiment with more of these loops and see which one best fits your project and goals.
You have multiple options. The first is to put the 'move 10 steps' block into a forever loop, so you code goes like the first one in the image and that will make your sprite move 10 blocks until the stop button is pressed.
Or alternatively, you could use a repeat (no. of times to repeat) block, like the second one:
Two Block Options
That's all!

Why does the sprite costume not change?

I'm just starting to play about in Scratch...
I seem to have a sprite of a cat with two 'costumes', which I guess are like frames.
I made this sequence:
...but when I click the green flag the cat moves to the right but the costumes don't switch.
If I make a simpler sequence:
...and manually change the costume in the drop-down then the costume does change.
What is the limitation here?
This is by design. By default, loops have a built-in delay of about 1/30 second. (There are ways to eliminate that delay, but that is off-topic here.) This was done to help inexperienced programmers witness the effect of a loop; possibly also to make execution speed more consistent (regardless of client's CPU power).
In your case, that means costume2 will be visible for 1/30 second before switching back to costume1.
Costume1 on the other hand, is instantly followed up by costume2.
Consequently, you will only see costume2.
There are various ways to fix that.
Change your script to repeat 5 { move 10 steps; next costume; } This gives both costumes an implicit 1/30 second delay. If this is still too short, add a delay (wait ... seconds). Note: next costume wraps around, so assuming the sprite has 2 costumes, it will flip back and forth between costume1 and costume2.
Too jerky? Use glide ... secs to ... instead of 'move and wait'.
Or just take smaller steps; swap costume once every few steps.
Make two separate scripts running in parallel, one for the movement, the other for switching costumes. That makes it easier to specify a different delay for each.
Try using a [wait] block: the change between costumes may be so fast that it seems like it is walking without changing costumes...

Adding and removing multiple nodes efficiently, without any lag

In my game, at specific intervals, a function is called that adds multiple nodes to the scene (between 2 and 6 nodes). These individual nodes are all the same - they consist of the same blender model, same SCNCone, same spotlight and same physics bodies - (The blender model is low-poly, nothing extreme).
When it's time to call the next interval of nodes, the nodes that were called previously are removed (including their actions). This process repeats until the player has died. Now when the nodes are removed and new ones are added, it creates noticeable lag for roughly a second, and doesn't appear smooth.
I'm wondering whether there is a more efficient way to add and remove these nodes that could possibly eliminate lag? Since these nodes are all visibly the same, would cloning a node multiple times be better than re-creating the same node over and over within a for loop?
Any advice on efficiency or better practises would be greatly appreciated too.
Thanks!
Edit: Just a thought, should I have a node at every required position, and basically un-hide and give them actions when needed, and once they've done their job, fade out, put back at initial position, remove actions and hide?
This would mean I would need about 20 nodes in the scene at all times, but at least there would be no need to add any more, or remove any.
Start by turning ON statistics.
scnView.showStatistics = YES;
Click on the + at the bottom left of the screen to the stats screen.
What could be causing the lag? Quick things to check are:
1. Is the geometry too complex?
2. Are the textures too large?
3. Are there too many draw calls?
Cloning is better.
Yes, I think your idea at the end will avoid the lag. If the nodes being added are the same as the nodes being removed it will be more efficient just to hide and reset them.
If you are creating the nodes each time it is likely that is causing the lag, and you could even remove and add them from the scene but instead of creating them when needed store them in an array ready to be reused.

Half scenes with static elements, other with spawn

I have 2D game, where half scene with spawn enemies and (for example) other half scene, where I want use static enemies and other elements.
I thought to create sript that after some time (for example 10 seconds), will stop spawn scripts , and run the movement of other elements.
So. Maybe there is a reasonable solution to this problem.
[UPDATE]
I need the most sensible solution of such a problem, I do not mean to do this, but how to make it better.
1) Can make static elements, which will be a certain time, just stand behind the camera, and then move ... or programmatically create static elements, over time, in advance of known locations...Or download the entire stack of elements over time.
2) Or can completely abandon this idea. A striking example is the Subway Surf, there static scenes (layout) are created in random order.
P.s. I hope I have explained my problem
Just learn to use "Invoke", it's extremely simple.
Invoke( "YourOtherRoutine", 10f );
So after ten seconds it will run the other routine. That routine could easily stop one script running, start another script running, or, whatever it is you want to do. There are tens of thousands of examples of Invoke() and InvokeRepeating() on the usual Unity forums, etc.
From your reference to Subway Surf, I assume that you want to generate static elements like the path and static trains in subway surf and non-Static elements like some moving trains. If so then I have a possible solution.
You can create pre-defined sets of elements (let say 20 or 30 set with different combination of elements) and then spawn them randomly one after another. e.g. have a look at the two reference images below.
Now, note that you might see these scenes exactly as in the images multiple times while playing the game, this is because they are pre-created, The developers behind Subway surf have created these paths and saved them as prefabs and then spawn them at different locations during game play.
You might have noticed that sometime the path is the same but the position of trains is different. This can be achieved by further creating spawn points on your path and then at runtime randomly select points on which you want to spawn your static elements.
In many cases when there are more than one gates you can pass through (I am referring to the gate in the second image). the moving trains spawns on the path of the gate you cross. Spawning the moving train can be achieved as mentioned in step two with a movement script attached to it. Regarding the question of how to know on what path to spawn there are two possible ways (that I can think of right know).
You can keep track of your players current lane and then spawn the train on that lane.
You can place separate triggers on each lane and then detect which lane trigger was triggered and then spawn the train on that lane.
For other moving trains just use the method in step 2 to spawn them but with a movement script attached.

Andengine ParticleSystem as Livewallpaper problems

First, I'll post link here where all is described by another person already
http://www.andengine.org/forums/gles2/particle-system-in-live-wallpaper-t8035.html
Well, the thing is, I set the ParticleSystem as a livewallpaper, and after the phone goes to sleep and I wake him up all particles are spawned at once. MaxRate and MinRate are ignored, max particles set in code is taken and the maxparticles possible are spawned.
But doesn't happens always, only sometimes. in 2 days it made this 3 times.
Any idea what could be wrong?
Question for ppl that know and engine.
Ty