I have a problem with Corona SDK. I want my newRect to overlap newTextField control. My code:
local localGroup = display.newGroup()
local txtOne = display.newTextField( display.contentWidth/2 - 140, 260, 280, 60)
local txtTwo= display.newTextField( display.contentWidth/2 - 140, 360, 280, 60)
local rect= display.newRect( display.contentWidth/2 - 140, 160, 200, 360)
localGroup:insert(txtOne)
localGroup:insert(txtTwo)
localGroup:insert(rect)
Result i have: txtOne and txtTwo always overlapping my rect object. But I want rect object to be on top of
txtOne and txtTwo. Is there a way to do this?
According to the docs
Because native textfields are not part of the OpenGL canvas, they do
not obey the Corona display object hierarchy. They always appear
above normal display objects, and cannot be inserted into display
groups.
So you can't bring the rect object in front.
You can work around it if you want. Just hide the textfield when not necessary
Read This link.
Try:
rect:toFront()
Read this link for creating textfield.
Related
local rect = display.newRoundedRect(200, 200, 150, 150, 2)
rect.fill = {0,0,0}
rect.alpha = 0.1
rect.xScale = 0.1
rect.yScale = 0.1
transition.to(rect, {time=1000, xScale=1, yScale=1, alpha=1}) -- transA
local function moveListener()
transition.moveTo(rect, {time=800,x=300, y=300}) -- this will puase transA!!
end
timer.performWithDelay(400,moveListener, 1)
Any idea how to perform moveTo() without stopping other transitions?
Cheers!
I just tried this on my computer, and it seems to be an issue with transition.moveTo().
It works using transition.to().
I just tried the following:
local rect1 = display.newRoundedRect(100, 100, 150, 150, 2)
rect1.fill = {0,0,0}
local rect2 = display.newRoundedRect(300, 100, 150, 150, 2)
rect2.fill = {1,0,1}
transition.moveTo(rect1, {time=1000, y=500})
transition.to(rect2, {time=1000, y=500})
And noticed that rect1 moved after rect2 with some delay!. However, adding small delay to transition.to() will make the movement exactly identical as follows:
transition.to(rect2, {delay=1, time=1000, y=500})
To summerize, it is still an issue with moveTo() to stop other transitions. As work around, in order to get exact behavior just use transition.to() with micro delay as previous line of code!
Thanks.....
I have a UIView and I want to change background color for half the screen to gray and other half to be blue.
Is there a way to do this? I am using RMQ for but I'm not tied to it as long as I can get it done.
Should I create two different UIView's and put them next to each other?
This is something like what I'm after
I tried the following but it didn't work.
m = CGRectMake(10, 10, 100, 100)
self.view.addSubview(m)
If it should be one view, you can use a background image and call it a day: in your style:
st.background_image = image.resource('your_image')
You can also draw on your layer to add the two colors. I won't describe that because I doubt that is what you'll need. CGContextFillRect for your research.
You can make those two different views, assuming they are grouping something logical. But if not, you can add subviews purely for the coloring too:
rmq(self).append(UIView, :top_style).back.append(UIView, :bottom_style)
Then set the styles in your stylesheet:
def top_style(st)
st.frame = {w: screen_width, h: screen_height / 2}
st.background_color = color.gray
end
def bottom_style(st)
st.frame = {t: screen_height / 2, w: screen_width, h: screen_height / 2}
st.background_color = color.blue
end
I need some help with the MapView in Corona SDK. I want to put the map as background (but with all functions) and, in this case, a button to the front. Here is my code:
function scene:createScene( event )
local group = self.view
if ( system.getInfo( "environment" ) == "simulator" ) then
local simulatorMessage = "Maps not supported in Corona Simulator.\nYou must build for iOS or Android to test native.newMapView() support."
local label = display.newText( simulatorMessage, 36, 40, 270, 0, native.systemFont, 12 )
label.anchorX = 0
label.anchorY = 0
end
myMap = native.newMapView( 20, 20, display.contentWidth, display.contentHeight )
if ( myMap ) then
myMap.mapType = "normal"
myMap.x = display.contentCenterX
myMap.y = display.contentCenterY
myMap:setCenter( currentLatitude, currentLongitude )
myMap:addEventListener("mapLocation", mapLocationListener)
end
backBtn = widget.newButton
{
id="backButton",
label="Back",
fontSize="30",
labelColor={ default={1, 1, 1}, over={0, 0, 0, 0.5} },
defaultFile="images/button.png",
width = dispWidth * 0.25, height = dispHeight * 0.1,
onRelease = onBackBtnRelease
}
backBtn.anchorX = 0.5
backBtn.anchorY = 0.5
backBtn.x = display.contentWidth * 0.8
backBtn.y = dispHeight * 0.8
backBtn:toFront()
group:insert( backBtn )
group:toFront() --second try to put that button to front
end
Since the MapView is a native object I can't add it to any group and 'mapView:toBack()' doesn't work as well ('attempt to index upvalue 'myMap' (a nil value)'). In Corona SDK the button appears without the map, as expected. On device I get the map without my button, not as expected.
Is it any possible to put a native object to the back, or to force something to be in the front?
What you are trying to do with the map and the button is not currently possible with CoronaSDK.
Indeed the MapView is a native object. According to Corona's documentation, you cannot place other objects on top of a MapView.
The documentation says:
Map objects, like other native display objects, cannot be inserted into groups and are always displayed on top of regular Display Objects (groups, vector, images, and text).
See documentation here
Good luck coding.
First Check the Following :
If button doesn't appear on device most common problem will be , you might misspell the Image names(Check for Caps) or check the path of the file is proper or not.
To know in detail about the mapView : http://docs.coronalabs.com/api/library/native/newMapView.html
I know you might have visited already, its better you look again.
Thanks,
Hey guys just wondering how I can make a smooth transition of a rects change in colour? So for example I have a basic grey rect background which I turn red, the problem is that the change in colour is instant. How can i do it so its a gradual change over seconds?
Here is my quick example. Cheers
local myRectangle = display.newRect(0, 0, 480, 320)
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
local function changeColor()
myRectangle:setFillColor(240, 140, 140)
end
timer.performWithDelay(2500, changeColor)
If you need transition, basically, you really can't do this with transition.to . You can do it with the help of an enterFrame listener and increment values for your R, G and B on each call.
Otherwise there is a sample code/library posted by atoko in corona forum. I haven't tried that personally, but you can check it here: http://developer.coronalabs.com/code/color-transition-wrapper
Keep Coding............ :)
When I use VBA to create a rectangle similar to one I draw on a worksheet, whay are there no connection points? After adding the last node I use ConvertToShape. It doesn't matter if I use msoEditingAuto or msoEditingCorner for all of the points. I can make the connection points available only if I use SetPosition on one of the nodes and use the existing position.
The following code from Microsoft's object reference gives an example of using connector points with rectangles:
Sub buildshape3()
Dim myDocument As Worksheet
Dim s As Object
Dim firstRect As Shape
Dim secondRect As Shape
Dim c As Shape
Set myDocument = Worksheets(1)
Set s = ActiveSheet.Shapes
Set firstRect = s.AddShape(msoShapeRectangle, 100, 150, 150, 150) '50, 200, 100)
firstRect.Fill.Transparency = 1
Set secondRect = s.AddShape(msoShapeRectangle, 300, 300, 200, 100)
Set c = s.AddConnector(msoConnectorCurve, 0, 0, 100, 100)
With c.ConnectorFormat
.BeginConnect ConnectedShape:=firstRect, ConnectionSite:=1
.EndConnect ConnectedShape:=secondRect, ConnectionSite:=1
c.RerouteConnections
End With
End Sub