Flying Lantern

Hello

I am in trouble with how to make flying lanterns through summer night. I am clueless that:

  • How can i reduce the brightness of the background image?
  • How to make multi-lanterns that can emit light? I tried with mask function but no luck. It can only set one mask .Also the background of the “circle.png” must be black. [import]uid: 111309 topic_id: 19156 reply_id: 319156[/import]

I’m having trouble picturing what your goal is. You could use a mask to dim the background or you could adjust it’s fill color if it is solid or you could place a semi transparent black image over it.

For the lanterns and their light it depends on the effect, you could use an image if it’s just an appearance of light.

For circle.png, you haven’t explained what that is or what you are using it for. If you want a png of a black circle you can create one using photoshop, gimp, inkscape, paint, etc. [import]uid: 52491 topic_id: 19156 reply_id: 73922[/import]

It sounds like he wants a background image that appears totally dark, with multiple flying lantern sprites that move across the screen and illuminate the areas of the background image that immediately surround each lantern, using circles of a given radius and perhaps alpha fall-off to define the illumination surrounding each lantern. [import]uid: 71767 topic_id: 19156 reply_id: 73952[/import]

If it were that simple there’s no reason the effect couldn’t be achieved by using images with various transparency, which is why I’m a little puzzled - if he’s looking at masks I imagine it’s not as simple.

We’ll see :slight_smile: [import]uid: 52491 topic_id: 19156 reply_id: 74116[/import]

Exactly like Clayton said. I finally figure out how to use mask. It is weird that if I want about ten illuminating areas, I have to call ten backgrounds:

display.setStatusBar( display.HiddenStatusBar )  
  
--Original background  
local darkBackground = display.newImage("countrySideDark.jpg")   
--Background which reduced saturation and lightness by Photoshop  
local lightBackground = display.newImage("countrySide.jpg")  
local lightBackground1 = display.newImage("countrySide.jpg")  
  
local halfW = display.contentCenterX  
local halfH = display.contentCenterY  
  
--Create lantern  
local lantern1 = display.newCircle(0,0,10)  
lantern1:setFillColor(0,102,204)  
lantern1:translate( halfW, halfH )  
  
local lantern2 = display.newCircle(-200,-200,10)  
lantern2:setFillColor(0,204,0)  
lantern2:translate( halfW, halfH )  
  
--Create mask  
local mask = graphics.newMask( "circlemask.png" )  
  
lightBackground:setMask( mask )  
  
lightBackground1:setMask( mask )  
lightBackground1.maskX = lantern2.x - halfW  
lightBackground1.maskY = lantern2.y - halfH  
  
--Move light of lantern1  
local function moveAround(self)  
 self.maskX = lantern1.x - halfW  
 self.maskY = lantern1.y - halfH  
end  
lightBackground.enterFrame = moveAround  
Runtime:addEventListener("enterFrame",lightBackground)  
  
--Move lantern1  
function moveLeft(obj)  
 transition.to(obj,{time=4000,alpha=1,x=obj.x + 300,y=obj.y,onComplete=moveRight})  
end  
function moveRight(obj)  
 transition.to(obj,{time=4000,alpha=1,x=obj.x - 300,y=obj.y,onComplete=moveLeft})  
end  
transition.to(lantern1,{time=4000,alpha=1,x=lantern1.x + 300,y=lantern1.y,onComplete=moveRight})  
  • I still wonder if corona can reduce the brightness of the image manually in code ?
  • And why does the “circlemask.png” 's background in Xray sample in “Sample Projects” have to be black?
    I try to change it to light color such as green or red, the mask is weird.
  • And tell me if there is another way to create this ?
    [import]uid: 111309 topic_id: 19156 reply_id: 74138[/import]

Hey again,

For your first question, no you can’t adjust brightness of an image. See my first post.

For your second question, black signifies areas that are transparent.

For your third question, there are many ways of doing most things however it is only by experimenting you’ll find the right way for you. If it works and you aren’t getting memory leaks, it’s solid.

Peach :slight_smile: [import]uid: 52491 topic_id: 19156 reply_id: 74162[/import]

Hi Peach,

Thank you for the information.

  • Too bad that we can’t adjust brightness of an image. I would rather adjusting in code than changing image when needed :frowning:

  • About the memory management, I have heard about a tool that can manage how much you are using your memory while working with corona. But I can’t find it.
    Could you tell me the name of the tool or send me the direct link if possible :stuck_out_tongue:

Thank in advanced :slight_smile: [import]uid: 111309 topic_id: 19156 reply_id: 74198[/import]

Hey again, are you a Leo? I assume so from your name. I’m a Leo :slight_smile:

For the brightness, I know, perhaps a post for feature requests?

For memory - I think you’re looking for this code?

[lua]local function monitorMem(event)
collectgarbage(“collect”)

print( “\nMemUsage: " … (collectgarbage(“count”)/1000) … " MB”)
print("Texture Usage " … system.getInfo( “textureMemoryUsed” ) / 1000000)

return true
end

Runtime:addEventListener(“enterFrame”, monitorMem)[/lua]

It will print your memory usage in MB so you can adjust things accordingly.

Peach :slight_smile: [import]uid: 52491 topic_id: 19156 reply_id: 74312[/import]

Yup, I 'm a Leo. My birthday is about in the middle of August :stuck_out_tongue:

For the brightness, it would be great if it is available in the next release :slight_smile:

And the monitorMem is exactly what I looking for. But I don’t know what is Texture Usage, which memory unit does it use? Because my Texture Usage line keep increasing.

One last problem: How can I know if my game can run smoothly on mobile?

  • Which factors does it depend on (memory, CPU or something else)?
  • If there is a tool that controls how much CPU you are using ?

Thank and Regard [import]uid: 111309 topic_id: 19156 reply_id: 74603[/import]

It will depend mostly on memory used and CPU cycles if you do a lot of calculations.
There’s no tool to control CPU usage. You just need to carefully program your application.
Texture usage is for images and text displayed on the screen. If it keeps increasing in number there’s objects you are not removing properly. [import]uid: 10389 topic_id: 19156 reply_id: 74619[/import]

My birthday is early August, the 5th. :slight_smile:

Texture usage comes down to the visuals - and what you see from that function is printed in MB.

How high is it?

The way to run smoothly on mobile is, mostly, keeping the texture memory as low as possible. Anything up to about 25MB seems to run well on most devices I’ve used.

Peach :slight_smile: [import]uid: 52491 topic_id: 19156 reply_id: 74622[/import]

  • If texture usage is for images and text displayed on the screen then what does MemUsage stand for ?

  • What is the different between MemUsage and Texture Usage ? At first I thought that MemUsage is total memory you are using. And why is the Texture Usage always higher than MemUsage.

  • If up to 25MB then there is no problem right now. My developing app shows about less than 10MB.

  • But something strange with the “Flying Lantern” code above. I use

  • countrySideDark.jpg : 1280 x 768 : 1.06MB
  • countrySide.jpg : 1280 x 768 : 479 KB
  • circlemask.png : 200 x 200 : 7.97 KB (from X-ray example)

Why did it end up to 16 MB ?
MemUsage: 0.0875498046875 MB
Texture Usage 16.842752
[import]uid: 111309 topic_id: 19156 reply_id: 74637[/import]

Take a look at this video Tom did regarding Texture Memory; http://www.youtube.com/watch?v=_oWWWueFl8I

The size an image is on your computer doesn’t equal the amount of texture memory it uses.

Peach :slight_smile: [import]uid: 52491 topic_id: 19156 reply_id: 74645[/import]

Quite interesting and useful video. My listening skill is quite bad so correct me if there are missing information.

If he could show us some facts affecting Texture Usage and tips to reduce redundant Texture Usage, it could be better.

So that I can estimate how much I can display on the screen rather than running the project to see how much memory I am using.

You have been a great help. Thank you very much. [import]uid: 111309 topic_id: 19156 reply_id: 75054[/import]