Moving clouds & a pressed state feeling

I the last few days we were traveling a lot so I did not had much time to make any large changes to my Rolly Bear World Project. Internet and Wifi was shitty which made it even harder to look up any Corona SDK resources. Nevertheless, I made a few changes which were a bit easier to do without having access to the Internet.

I added a bit more art work to the project so Rolly Bear World will look a bit more appealing to the larger public. I mentioned before that I was planning to add these kind of changes later, but I guess due to the traveling and not having access priorities changed just to keep on having progress with the game and try to have it finished by the end of my trip. What did I change? A few background images like bushes to both the level screens as well as the menu screen. I added some clouds which move through the sky. I also added a few lines of code that when a user clicks on the back-button or on the level icons the user gets the feeling of a button press. I did this by using the Corona SDK xScale and yScale APIs.

As always you can find the code in my GitHub Repository

We have travelled through Kuala Lumpur on our way to Thailand, but we decided to stay 3 nights in Kuala Lumpur, despite many negative things we heard about Kuala Lumpur being boring for travelers; we have to say otherwise. We liked Kuala Lumpur a lot, it has great night markets, tech malls :) and of course the famous Petronas towers of Kuala Lumpur. The tech mall is called plaza Low Yat, which has 7 floors of phones, cameras, laptops and other gadgets. Absolutely one of my highlights of our visit.

The moving clouds are the most interesting part of this update of Rolly Bear World. I created a table with 3 different cloud images (cloud01.png, cloud02.png, and cloud03.png) and use math.random to select 3 times random one of the 3 clouds. It did this by using a for loop. I displayed these clouds on the screen and transitioned them from left to right. Also the speed of the clouds are different per could ranging between 30.000 and 120.000 Milliseconds. I used math.random in the transition parameter to let Corona decide the speed within this range.

clouds ={
	 {getImage = "images/cloud01.png"}, 
	 {getImage = "images/cloud02.png"},
	 {getImage = "images/cloud03.png"}
	}

	for i=0,2 do

	imagesId = math.random (1,3)
	print(imagesId)
	local cloud = display.newImage(clouds[imagesId].getImage   )
	cloud.x = math.random (display.screenOriginX , centerX )
	cloud.y = math.random (display.screenOriginY + cloud.height, centerY)
	print(cloud.x, cloud.y)
	group:insert(cloud)
	cloud.alpha = 0.7
	print("alpha"..cloud.alpha)
	transition.to( cloud, {time = math.random (30000 , 120000), x = withScrn + 300 } )

	end

The other interesting part to mention is that when a user clicks either on the backbutton or on the level-icon button (in levels.lua) the back button provides feedback to the user that the button has been pressed. I realized this by using xScale and yScale and making the buttons a bit smaller when pressed. This saved me a lot of time in making additional pressed-state art work :).

The nice part? You don’t need to program this for each button separately, by using event.target in the btnTap function Corona SDK knows which object has been pressed by the user.

local function btnTap(event)
	event.target.xScale = 0.95
	event.target.yScale =0.95
	storyboard.gotoScene (  event.target.destination, {effect = "fade"} )
	return true
end

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*