PNG not rgb

Hello,

I’m stuck, I don’t know what to do. On my app project I’m only using png’s so when the player goes to the Options page to select purpleBall.png or fireBall.png or iceBall, what would be the code for that png ball to appear on level 1?

So Options page select ball then it’s there on level 1 and through out the game. I’m lost.

Appreciate any help

Hello,

Im not sure this is what you meen. However, one approach to do this is just save players choice somewhere (to file, to variable…) and then load proper ball when creating level 1.

I would like to help you but I have no clue what you are talking about…

What are you trying to do? What is not working?

Maybe you can provide som code example?

Hi @DLuck,

May be read Corona pass parameter in gotoScene

Have a nice day:)
ldurniat

Create a file called myData.lua as follows:

return {}

At the top of your options file put:

local myData = require "myData"

At the top of your level1 file put:

local myData = require "myData"

In your options file, where ever you select the image file put:

myData.imageFile = "purpleBall.png"

Or, whichever file name is appropriate. In your level1 file, when you create the image put:

ball = display.newImage(myData.imageFile)

That should achieve what you are trying to do.

A couple of things:

  1. Make sure to properly format your code so that it can be read more easily.
  2. Don’t just dump your entire code base here. You should instead create a small project that demonstrates your issue. This is especially important when you are using images and when your project is split into several files of code since no one can run your code without making changes to it first.
  3. Ask a question and try to be precise. In your last post, you just dumped your code and you didn’t say a thing about what you are doing, what’s wrong, what you need help with, etc.

And most importantly.

  1. Read your console output. You are getting the same warning twice that whatever image you are trying to use doesn’t exist and then the game crashes because you are trying to manipulate said display object that was never created. Check if the file exists in the folder, if you’ve made a typo, etc.

Hi @DLuck,

Try

  1. Replace
    myData.imageFile = ("blueBall.png")
    with
    myData.imageFile = "blueBall.png"
  2. Replace
    ball = display.newImageRect( "blueBall.png", 25, 25 ) 
    blue.x = 90    
    ball.y = 10 
    physics.addBody( ball, "static", { density=1.0, radius=12 } ) 

with

      ball = display.newImage( myData.imageFile,  90, 10 )
	  --ball = display.newImageRect( "blueBall.png", 25, 25 ) 
	  --blue.x = 90    
	  --ball.y = 10 
	  physics.addBody( ball, "static", { density=1.0, radius=12 } ) 

Do you have ‘ball.png’ image in main folder of project?

Have a nice day:)
ldurniat

Thanks for trying, but all I get are error messages.

I removed all the myData code.

I’m just trying to find out what is the code for when the player is in the Options page and taps to select one the the png balls.

The player then returns to the Menu page.

The player taps Level1 then the player enters into the Level1 page, and the ball that was selected in the Options page is waiting to be tapped to start the game.

I’m sure it’s sure simple code, but not for me.

I appreciate you, thanks

I don’t think you should give up on using myData… it’s pretty simple!
Here’s a demo project that should help. It’s a simplified version of what you are trying to do:

myData demo.zip (2.2 KB)

Thanks for trying to help, but I’m only using png balls, your code doesn’t work with png’s. Your code negates all of my code all I see are 3 rgb rects.

Thanks anyway

How would you do that? Please only png’s.

Thanks

I didn’t negate your code, I just used to least amount of code needed to demonstrate the use of myData.lua :blush:. Menu.lua is the equivalent of your options file. Just use display.newImage instead of display.newRect. Do the same in level1!