alternating panel animations inside a loop - basic4android

I have two panels animating (blinking on/off) fine as heartbeats. However I want them to alternate beating instead of at the same time. So panel1 beats with a 10 count and then panel2 beats with a 10 count. I then want this to loop so it continues the pattern until the user presses the back key to exit the activity. I tried a few things with no luck. Here is the two panels beating together...
Sub beats
PNL1.Initialize("PNL1")
gdpanel1.Initialize("TOP_BOTTOM", Array As Int(Colors.DarkGray, Colors.Red))
gdpanel1.CornerRadius=0
PNL1.Background=gdpanel1
mainPNL.AddView(PNL1,0,0,100%x,50%y)
SetRadialGradientRed(gdpanel1,PNL1.Height/1.5)
a.InitializeAlpha("a",0,1)
a.Duration = 200
a.RepeatCount = 10
a.Start(PNL1)
PNL2.Initialize("PNL1")
gdpanel2.Initialize("TOP_BOTTOM", Array As Int(Colors.DarkGray, Colors.Blue))
gdpanel2.CornerRadius=0
PNL2.Background=gdpanel2
mainPNL.AddView(PNL2,0,50%y,100%x,50%y)
SetRadialGradientBlue(gdpanel2,PNL2.Height/1.5)
b.InitializeAlpha("b",0,1)
b.Duration = 200
b.RepeatCount = 10
b.Start(PNL2)
End Sub
Sub a_AnimationEnd
'
End Sub
Sub b_AnimationEnd
'
End Sub

You should start animation b in Sub a_AnimationEnd and start animation a in Sub b_AnimationEnd.

Related

How to improve perl Gtk2 performance when we have a large number of widgets

I'm writing a perl GUI using Gtk2, it has a scrolled window which contains a number of GTk2::Expander which includes different widgets.
The poroblem is when i have a large number of Expanders (~80,000) the time it takes to perform show_all() is large, and when i open a single expander it takes several seconds. Running the same script with less expanders give a very fast response.
Since my expanders exists in a scrolled window and only part of them would be really visible, is there a way to improve the performance? like showing only the visible expanders and keeping all others as hidden?
I can't use GTK3, I need to use Perl and Gtk2 only.
Example Code:
my $ItemsCount = 10000;
my $ScWin = Gtk2::ScrolledWindow->new(undef, undef);
my $Frame = Gtk2::Frame->new('Items');
my $ItemsBox = Gtk2::Table->new(2, $ItemsCount+1, FALSE);
my $View = Gtk2::Viewport->new();
$ScWin->set_policy('automatic', 'automatic');
$View->add($ItemsBox);
$ScWin->add($View);
for my $i (0 .. $ItemsCount-1) {
my $exp = Gtk2::Expander->new();
$exp ->set_label("Item #$i");
$ItemsBox->attach($exp, 0, 1, $i, $i+1, 'fill', 'fill', 1, 2);
}
$MainBox ->pack_start ($ScWin , TRUE, TRUE, 0);

Script that loops after a random delay within an interval

I want to make a loop that clicks, then sleeps for roughly half of a second (but not the exact same delay per iteration), then clicks again, then sleeps for roughly 50 seconds (same situation as before), then loops.
Here's what I whipped up but it doesn't work at all:
loop
{
Click
Sleep %var1%
Click
Sleep %var2%
}
down::
Pause
Return
Random, var2, 50853, 58179
Return
Random, var1, 412, 942
Return
Also, if you could figure out how to make it so a hotkey (something like alt + n) would stop the loop, then pressing the key again would RESET the loop, not resume it.
This script is supposed to be simulating a person double-clicking something then waiting just under a minute to do it again (For a game with macro detection)
It looks like you're off to a good start! Unfortunately, if this is your full script, it would get stuck in the loop as soon as it gets loaded. In order to get a better understanding of the code below, you may want to read through the "Getting Started" section of the help documentation, specifically Hotkeys.
Please see if this works for you:
!n::
bToggle := !bToggle
If bToggle
SetTimer , label_ClickLoop , -1
Return
label_ClickLoop:
Loop
{
Random , var1 , 412 , 942
Random , var2 , 50853 , 58179
Click
Sleep , var1
Click
Loop , 100
{
Sleep , var2 / 100
If !bToggle
Break , 2
} }
MsgBox ,,, Loop cancelled! , 0.75
Return

Perl Tk: Canvas dynamic updating

I'm trying to animate the results of a mathematical process in a 2D canvas with Tk. I've decided to do it with Tk and not SDL because right now i'm working with both Linux and Windows machines and Strawberry Perl doesn't compile proberly in windows, whil Tk is up on both pcs.
What i would like to do with Tk is that:
1)Popping up the canvas while my program is working out the coordinates of the points i would like to draw.
2)Drawing them instantly into the canvas without waiting for the process to reach the end
It's actually a simple animation, where a bunch of points moves around the Canvas while my script updates their coordinates.
Here you have a code snippet i've been writing so far for a single point:
use Tk;
#calcuate the coordinate of a single point
$x=10;
$y=10;
$top = MainWindow->new();
# create a canvas widget
$canvas = $top->Canvas(width => 600, height => 400) -> pack();
# For example, let's create 1 point inside the canvas
$canvas->create ('oval', $x, $y, $x+3, $y+3, -fill=>"black"); # fill color of object
MainLoop;
The problem with the above code is that i would like to add my 'math' script inside it in order to update the $x and $y coordinates above (with some sort of for/while cycle) without shutting down the original canvas, by obtaining a single point moving all around it (atually there are more points i'm supposed to display but that's a minor detail).
FYI, using a simple for cycle embedding the ''Mainloop'' directive doesn't fix the problem.
Thanks in advance guys
Quoting from Mastering Perl/Tk, chapter 15 "Anatomy of the MainLoop":
Option 1: use your own MainLoop implementation
use Tk qw(:eventtypes);
while (Tk::MainWindow->Count) {
# process events - but don't block waiting for them
DoOneEvent(ALL_EVENTS | DONT_WAIT);
# your update implementation goes here
}
Option 2: use a repeat timer event
Later in the chapter it is stated that DoOneEvent() isn't really necessary for most stuff. You could use timer events instead, e.g.
my $update = sub {
# your update implementation goes here
};
# run update every 50ms
$top->repeat(50, $update);
MainLoop;
SOLUTION:
As per Stefan Becker suggested option nr.2, here is what has finally fixed the problem:
use Tk:
$top = MainWindow->new();
# create a canvas widget
$canvas = $top->Canvas(width => 600,
height => 400,
background => 'black') -> pack();
$x=300;
$y=200;
my $update = sub {
$canvas->delete('all'); #unquote this line if you don't want the original point positions to be drawn in the canvas. Viceversa
$x=$x+(-5+rand(10)); #white noise
$y=$y-(-5+rand(10)); #white noise
$canvas->create ('oval', $x , $y , $x+5, $y+5, -fill=>"red");
};
$top->repeat(50, $update);
MainLoop;
I've just added the statement $canvas->delete('all') at the beginning of the updating loop in order to draw just actual points and not the history.

Multiple for loops executing at the same time? Swift

Basically I am creating a game that spawns a ball after a certain amount of time has passed. However, as time goes on and the player score increases, balls that are more difficult to kill will spawn.
Prior to this, all the spawn methods I have set in place function as I would like them to, but they were contained in a switch statement that calculated the probability a ball would spawn.
//pseudo:
let spawnProbability = arc4random_uniform(100)
switch spawnProbability {
case 0…60: //60% spawn chance
//spawn small ball
case 61…90: //~30% spawn chance
//spawn medium ball
case 91…100: //~9% chance
//spawn large ball
default:
break
}
This worked as a plan B, but I'd like to implement what I originally had designed which was the method described above.
My thought process to accomplish what I originally had in mind is:
for loop that spawns small balls until the score counter reached a certain amount
after the score counter reached, say, 100pts, another for loop would be executed in addition to the first loop. So, medium and small balls spawn after a delay.
after the score counter reached another mark, large balls would begin to spawn on top of medium balls and small balls.
Here's what I mean: (pseudocode again)
for(var i = 0; i < 10; i++) {
//delay
//spawn small ball
}
if score >= 100 {
for (var x = 0; x < 10; x++) {
//delay
//spawn medium ball
}
}
// . . . and so on
I've put alot of thought into how I could accomplish what I want but I can't come up with a better approach to this problem. I understand why this isn't working and why multiple for loops can't be executed with delay in the same class at the same time (or maybe they can and I'm just going about it in the wrong way) but I'm stuck in the sense that I don't know a better way to implement the spawn technique that I want.. Any help is greatly appreciated!!

How can i move to right by dragging the scene to the left in Corona?

Well, i want to make levels to my game like in Angry Birds. So how can i move from left to right by dragging the scene? What should i use for this in Corona? Thanks.
Insert all the images on the screen you want to drag (presumably everything besides any GUI objects) into a group.
From there write a function with a touch listener assigned to the group itself. It would look something like this, supposing you're app is iPhone landscape mode.
local function constrainMap ()
if localGroup.x < -480 then
localGroup.x = -480
elseif localGroup.x > 0 then
localGroup.x = 0
end
end
Runtime:addEventListener("enterFrame", constrainMap)
local function moveMap (event)
if event.phase == "began" then
localX = localGroup.x
elseif event.phase == "moved" then
localGroup.x = localX + (event.x - event.xStart)
end
end
localGroup:addEventListener("touch", moveMap)
In the above case the localGroup contains all visual elements and the constrainMap function is used to prevent the user from scrolling the map off the screen.