Mouse cylinder behaviour (dual-screen config) - lua

I've already asked a question about this in Unix & Linux SE and I so actually use xdotool.
The idea is that the mouse goes at the left of the left screen when it reaches the right of the right screen and vice versa.
But I recently saw the mouse.coords table in the awesome API, so I'd like to give up xdotool to set mouse coordinates as do xdotool with this possibility.
I suppose I should add a signal to the root to know when the mouse is on the edge, but I don't konw how to do this...

I give a try to my idea, and it works. Here's the code for my right wibox :
s.myjumpbox = awful.wibar({
position = "right",
screen = s,
width = 1,
opacity = 0,
ontop = true,
-- bg = beautiful.noir
})
s.myjumpbox:connect_signal("mouse::enter", function(w)
mouse.coords {
x = 2 ,
y = mouse.coords().y
}
end
)
Edit : add Uli's suggestions

Related

Zoom into scene using transition - Corona

Hey so I am looking for something similar to in tennis when players challenge a point and the video shows whether the ball was in or out by zooming in really really close to the moment when the ball lands to see whether a fraction was on the line.
I have experimented with using transitions with xScale and yScale but the results I get is strange, almost as if the objects have moved during zooming in. If there was a way to lock in position and then zoom, that would work. The second method I tried is putting the graphics into a display group and then scaling the group. This also results in weird behaviour where the whole group begins moving diagonally across the screen.
Please help as this is confusing me
cheers.
Objects which will scale:
cloud = display.newImageRect("cloud.png", 419,273)
cloud.anchorY = 0
cloud.anchorX = 0.5
cloud.alpha = 1
cloud.x = display.contentCenterX
cloud.y = display.contentCenterY + 250
physics.addBody(cloud, {isSensor=true})
star = display.newImageRect("Star.png", 78,72)
star.anchorY = 0
star.anchorX = 0.5
star.alpha = 1
star.name = "Star"
physics.addBody(star, {isSensor=true})
star.x = display.contentCenterX
star.y = display.actualContentHeight - display.actualContentHeight - 100
Scale Function
function scale( event )
transition.to(star, {time=2000, xScale=1.5, yScale = 1.5})
transition.to(cloud, {time=2000, xScale=1.5, yScale=1.5})
end
When you scale an object, it may "move" due to its anchor position, which is the position of the object that is used to position it and also works as its 'anchor' during rotation or scale.
So, you have 2 options:
1) Set the anchor position (obj.anchorX = value , obj.anchorY = value ) to the one that will make your object stays in the position that you want;
2) During the transition, also change its x and y to compensate the moving.

How can I make an image fall down randomly as if meteors in Corona SDK?

What I want is that the images fall from the top side of the screen and start falling down accelerating, they would only be falling straight down, alternating positions around the width of the screen, meaning one on the right, then another one in the middle, and then another one on the left side and so on in the different positions, until they disappear at the bottom of the screen.
I tried this
function moveMeteors()
for i = 1, math.random(1, 2) do
meteors = display.newImage("meteor.png")
screenGroup:insert(meteors)
meteors.x = (math.random(display.contentWidth))
meteors.y = centerY - 340
transition.to(meteors, {time = math.random(3500 - speedMeteor, 4500 - speedMeteor),
y = 1000 + speedMeteor, onComplete = clear })
speedMeteor = speedMeteor + 10
end
end
But, sometimes the images appear one over the other and I do not want that, I mean, each image appear and go from the top to the bottom of the screen in his own line. I hope that I've explained this well.
You should look into utilizing the built in physics of Coronasdk. CoronaDocs:Physics.
As an example this code should easily simulate the effect you a trying to get, you will have to add functions to take care of removing objects as they leave the screen etc.
local physics = require("physics")
physics.start()
function SpawnMeteor()
local meteor = display.newImage( "meteor.png", math.random(display.contentWidth), centerY - 340)
physics.addBody( meteor)
end
timer.performWithDelay( 2000, SpawnMeteor)

How do I put a border on the left and right side of my UIViewController

im currently building this game and im having some trouble, at the top of my screen there is a ball that I have buttons to make move left and right, I want them to be stopped at the right and left side of the screens because they just keep going when i hold the button to make them move, I was wondering if there is any way I can set some sort of boundary or border to prevent them from keep moving
add the following instead of your 'redBall.center' line - it checks to see if the ball's new position is inside the border before it moves it..
// some border screen coords
borderLeft = 20;
borderRight = 200;
// move ball left
if (redBall.center.x - 1 > borderLeft) {
redBall.center = CGPointMake(redBall.center.x - 1, redBall.center.y);
}
// move ball right
if (redBall.center.x + 1 < borderRight) {
redBall.center = CGPointMake(redBall.center.x + 1, redBall.center.y);
}
Hope that helps!

Text alignment to left in Corona

My problem is that I can't align my text to left. I need to set a position where the text will start and it will go to the left and it wont be centered. Its like in html, you make position and it goes from that position to the right, eventually it makes another line. Maybe a picture example will make you understand better because its hard to describe it.
How it should look and where it should start all the time if I add more text it should just continue to the right.
How it looks if I add more text, and that's not how I want it
Here's a bit of the code
text = display.newText("Fair", 0, 0, "HelveticaNeue-Light", 22)
text.x = halfW - 300
text.y = halfH + 110
text.align = "left"
Are you using the Current Public Release (2014.2100) + ?
Try using text.anchorX = 0 instead of text.align = "left"
So anchorX = .5 is same as "middle" and anchorX = 1 is same as "right".

Sprite position in Corona SDK

I didn't understand some object position concepts in Corona SDK
I have created sprite sheet:
local spriteSheet = sprite.newSpriteSheet("button.png", 138, 64);
local spriteSet = sprite.newSpriteSet(spriteSheet, 1, 2);
local sp = sprite.newSprite( spriteSet );
and it's positions are strange and sprite is out of screen bounds even I set x and y positions to zero
config.lua is:
application =
{
content =
{
width = 320,
height = 480,
scale = "letterbox"
},
}
I think that problem in "referencePoint"
just say me how to change setReferencePoint of default screen (not image or group ...), just default screen...
Technically you can use a different coordinate system for all your graphics by creating a display group and attach everything to that group, but really it seems like you're asking the wrong question. Rather than trying to change the reference point of the screen, you should be wondering why your sprites aren't positioned correctly.
Please create a new question that focuses on that problem and explains it further, because all you say here is that the positions are "strange". What's that mean?
You can modify your code like below and just check it,it will work:
local spriteSheet = sprite.newSpriteSheetFromData( "button.png",require("button").getSpriteSheetData())
local spriteSet = sprite.newSpriteSet(spriteSheet,1,9);
sprite.add(spriteset,"button",1,9,1000,0);
//button is lua file use button.lua
local sp = sprite.newSprite( spriteSet );
sp:prepare("button");
sp.x = display.screenOriginX+138;
sp.y = display.screenOriginY+64;

Resources