transition object twice? (Corona SDK) - object

i have a problem with transitioning!
For example:
i have an object and a button. I want this object to fade out when i press the button, and then when i press the button again i want my object to fade in.
But i can't fade in my object, feels like it's just gone!
For transition i use transition.to, for ex:
object = transition.to( object, {time=500, alpha=0})
but when i perform another function in this exact scene to fade in, it just don't wanna work at all(button is pressing, but nothing is happening, even errors).
Help me out please!

Your code:
object = transition.to( object, {time=500, alpha=0})
You are saving the transition handler to the object. Try this:
trans = transition.to( object, {time=500, alpha=0})
Then if you want to cancel the transition you can do this
transition.cancel(trans)
you can check the the usage of transition.to here http://developer.coronalabs.com/node/2407
Cheers!

Try this code i don't know correctly but it's works well:
local myRectangle = display.newRect(100, 100, 150, 50)
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
myRectangle:setStrokeColor(180, 180, 180)
local button = display.newRect(100, 200, 50, 50)
button.strokeWidth = 3
button:setFillColor(140, 140, 140)
button:setStrokeColor(180, 180, 180)
local buttonfun=function(event)
if event.phase=="ended" then
print("fade")
if myRectangle.alpha ==1.0 then
transition.to( myRectangle, { delay=1, time=1000, alpha=1.0, alpha=0.0} )
myRectangle.alpha=0.0
print("alpha"..myRectangle.alpha)
else
transition.to( myRectangle, { delay=1, time=1000, alpha=0.0, alpha=1.0} )
myRectangle.alpha=1.0
print(myRectangle.alpha)
end
end
return true
end
button:addEventListener("touch", buttonfun)

After you write this trans = transition.to( object, {time=500, alpha=0}) in button pressed first time so you must chick make boolen variable to make this action twice.
and second time which fade it in again you must make alpha=1
For example:
local trans
function Listner (event)
transition.cancel(trans)
trans = nil
end
function onPress(event)
if(flage== true) then
flage = false
trans = transition.to( object, {time=500, alpha=0 , onComplete =Listner })
else
flage = true
trans = transition.to( object, {time=500, alpha=1 , onComplete =Listner })
end

Related

tkinter: revoke clickthrough

when you want to make a window and its elements clickthrough-able one will probably use code like that:
label = Label(root)
hwnd = label.winfo_id()
styles = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
styles = win32con.WS_EX_LAYERED | win32con.WS_EX_TRANSPARENT
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, styles)
win32gui.SetLayeredWindowAttributes(hwnd, 0, 255, win32con.LWA_ALPHA)
Note: you need to use the handle of the elements (here: label) and not the handle of the window (here: root)
assuming background of Window is alredy transparent:
root.config(bg='#000000')
root.attributes('-transparentcolor', '#000000')
Now the Question: how do I revoke the clickthrough? I assume its something like:
def revoke_click_through(hwnd):
... #maybe work with new styles?
win32gui.SetWindowLong(hwnd, ... )
win32gui.SetLayeredWindowAttributes(hwnd, ... )

Drag & Drop (swap) 3 texture buttons in a Margin Container->VBox

Following along a great tutorial, code is replicated yet does not function as shown. No new texture appears to be created when I try to drag the texture button. Only difference is the tutorial uses a TextureRect, while I'm using a TextureButton.
extends TextureButton
func get_drag_data(position: Vector2):
var vControl = Control.new()
var vData = {}
var vTexture = TextureRect.new()
vTexture.expand = true
vTexture.texture = texture_disabled
vTexture.rect_size = Vector2(320, 400)
vControl.add_child(vTexture)
vTexture.rect_position = -0.5 * vTexture.rect_size
set_drag_preview(vTexture)
return vData
Code above is attached to Party_1. texture_disabled does have a texture set.
It would work if you had the code in get_drag_data looking like this:
func get_drag_data(_position: Vector2):
var vTexture = TextureRect.new()
vTexture.expand = true
vTexture.texture = texture_disabled
vTexture.rect_size = Vector2(320, 400)
set_drag_preview(vTexture)
return {}
However, that would place the TextureRect top-left corner at the cursor position.
You want to offset the position of the TextureRect so it is centered at the cursor position. To do that, you create another Control, add the TextureRect as a child to it… And pass the TextureRect anyway? No, that does not work, you need to pass the new Control:
func get_drag_data(_position: Vector2):
var vTexture = TextureRect.new()
vTexture.expand = true
vTexture.texture = texture_disabled
vTexture.rect_size = Vector2(320, 400)
var vControl = Control.new()
vControl.add_child(vTexture)
vTexture.rect_position = -0.5 * vTexture.rect_size
set_drag_preview(vControl)
return {}
Please notice I'm giving vControl to set_drag_preview, not vTexture.
You cannot give to set_drag_preview a Control that has a parent. In fact, if you tried you would get an error in the Output console saying:
_gui_set_drag_preview: Condition "p_control->get_parent() != nullptr" is true.
Or
_gui_set_drag_preview: Condition "p_control->is_inside_tree()" is true.

does altair have a "play button" for sliders?

x = np.arange(100)
t = np.arange(100)
y = [p**2 for p in x]
source = pd.DataFrame({
't':t,
'x': x,
'f(x)': y
})
slider = alt.binding_range(min=int(min(t)), max=int(max(t)), step=1)
select_t = alt.selection_single(name="year", fields=['t'],
bind=slider, init={'year': 50})
alt.Chart(source).mark_line(point=True).encode(
alt.X('x',scale=alt.Scale(domain=(0,100))),
alt.Y('f(x)',scale=alt.Scale(domain=(0,10000)))
).add_selection(select_year).transform_filter(select_t)
so I'm putting together a simple animated point, and I've got the slider running ok. But I'd like it to run automatically. Is that possible?
No, there is not currently any direct way to automate the slider or produce an animation in Altair. Animations have been discussed within Vega (the renderer that underlies Altair), but have not yet been added to the implementation.
Here's how to add a Play button to play the slider.
HTML('''
<button onclick="play()">Play</button>
<script>
var timer;
function play(){
// restart if max
slider = document.querySelector("input[type=range]")
if (slider.value==slider.max) {
slider.value = slider.min
slider.dispatchEvent(new Event("input"))
}
timer = setInterval(step, 200) // change speed here
}
function step(){
slider = document.querySelector("input[type=range]")
slider.stepUp() // use defult step
slider.dispatchEvent(new Event("input"))
if (slider.value==slider.max){
clearInterval(timer)
}
}
</script>
''')

Trying to hide labels on button if color is red in visual studio

This will only work for the labels sender but, I need to use this also for the button sender so it can hide if the label is red only when the button is clicked.
I have 48 Seats
Private Sub Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Seat9.Click, Seat8.Click, Seat7.Click, Seat6.Click, Seat5.Click, Seat48.Click, Seat47.Click, Seat46.Click, Seat45.Click, Seat44.Click, Seat43.Click, Seat42.Click, Seat41.Click, Seat40.Click, Seat4.Click, Seat39.Click, Seat38.Click, Seat37.Click, Seat36.Click, Seat35.Click, Seat34.Click, Seat33.Click, Seat32.Click, Seat31.Click, Seat30.Click, Seat3.Click, Seat29.Click, Seat28.Click, Seat27.Click, Seat26.Click, Seat25.Click, Seat24.Click, Seat23.Click, Seat22.Click, Seat21.Click, Seat20.Click, Seat2.Click, Seat19.Click, Seat18.Click, Seat17.Click, Seat16.Click, Seat15.Click, Seat14.Click, Seat13.Click, Seat12.Click, Seat11.Click, Seat10.Click, Seat1.Click
Dim Seats As Label = CType(sender, Label)
If Seats.BackColor = Color.White Then
Seats.BackColor = Color.Red
Else
Seats.BackColor = Color.White
End If
Okay, I think I understand now.
You have multiple labels which represent seats and when the user clicks on the labels they change from white to red.
You are wanting to create a button that once clicked, it removes all red labels from the screen/form.
You would place the following in the click event of your button (assuming that your form is called frmMain)
For Each c As Control in frmMain.Controls
Dim l As Label = DirectCast(c, Label) ' Cast from control to label
If Not l Is Nothing ' If this control is indeed a label then process
If l.BackColor = Color.Red Then ' If color is red then hide label
l.Visible = False
Else
l.Visible = True
End If
l.Visible = False
End If
Next
I don't have VS pulled up, so syntax may be a little incorrect but I think you get the point.

How can i move my objects on the screen randomly on Corona?

I want my display objects to move on the screen with a velocity and without any interactions. How can i do that with corona? Thanks.
First you have to add your display object to the physics, and then set its velocity to a random value. You can use a timer to periodically change the movement of the display object. For example:
physics = require("physics");
physics.start()
rectangle = display.newRect(0, 0, 50, 50)
physics.addBody(rectangle, "kinematic", {isSensor = true})
function moveRandomly()
rectangle:setLinearVelocity(math.random(-300,300), math.random(-300,300));
end
timer.performWithDelay(500, moveRandomly, -1);

Resources