Sprite falling off screen question

2 questions.

I have a sprite, how would I give it its own local title?

Ex.

local data = require("mysprite").getSpriteSheetData();  
local sheet = sprite.newSpriteSheetFromData("mysprite.png",data);  
local set = sprite.newSpriteSet(sheet, 1, 16);  

That’s my code that generates the sprite (or so I gather). How would I make it have its on local function like

Local sprite = …

Second, How would I make sprite falling off/past a platform (in this case a rectangle or rect) to trigger a game over image/ try again option?

Here’s what I’ve been trying so far:

local sprite = display.newImage("mysprite")  
local rect = display.newRect( 50, 50, 100, 100 )  
rect:setFillColor( 255, 255, 255, 100 )  
rect.isVisible = true -- optional  
rect.x = 364  
rect.y = 630  
  
local checkSprite = function(event)  
sprite.y \> then rect.y then  
gameover()  
end  
  
Runtime:addEventListener("enterFrame", checkSprite)  

Any help would be greatly appreciated.

Cheers,
Andrew
[import]uid: 72845 topic_id: 16012 reply_id: 316012[/import]

I can’t see where exactly gameover is defined but yes, that would work.

To give a sprite it’s own name see here; http://developer.anscamobile.com/reference/index/spritenewsprite

To “give it a function” try this;
[lua]local function touchSprite ()
print “I touched the sprite!”
end
spriteName:addEventListener(“touch”, touchSprite)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 16012 reply_id: 59457[/import]

Thank you for the response, any chance you could show me how to incorporate the code I posted into the code you suggested? I’ve been messing around with it for about an hour and keep getting errors and I’m not sure why : (

Thanks again
-Andrew [import]uid: 72845 topic_id: 16012 reply_id: 59573[/import]

Hey Andrew,

What errors are you getting?

I check in fairly regularly and will be more than happy to attempt to help you solve your problem (although it appears you’re maybe using a third party tool for sprites?) however if you are in a hurry or need fully coded examples, check here; http://www.anscamobile.com/corona/support/

Otherwise, let me know what errors you’re actually getting in the terminal :slight_smile:

Peach [import]uid: 52491 topic_id: 16012 reply_id: 59691[/import]

Thanks for the response. I’d love to get support help but I’d have to save for 2-3 weeks in order to pay for the minimum support, and don’t really have the option to do that at the moment : /

The error I’m getting is:
"Director Class - ERROR

Director ERROR: Failed to load ‘titlescreen’ -
Please check if the file exists and it is correct."
I’ve noticed that I only get that error if I input:

local checkSprite = function(event)  
sprite.y \> then rect.y then  
gameover()  
end  
   
Runtime:addEventListener("enterFrame", checkSprite)  

I found that snippet of code in another forum post and tried to make it work with my project.
I really dont know what the problem is but I think “sprite.y > then rect.y then gameover()” could be the problem as I dont have any other code defining what “gameover” is, nor do I know how to assign it an action. Basically all I want to do is make my sprite trigger a try again button when it falls off the screen. Been trying to figure this out for over a month and at this point my project has been at a stand still. I’ve looked into schools to teach me how to program the game but theres nothing in my area available for Lua programming or mobile game/app programming.

Appreciate the responses. Hopefully one of these days I’ll get back on track : )
Thanks
-Andrew

[import]uid: 72845 topic_id: 16012 reply_id: 59776[/import]

Wait …

So you have just put gameover() in your code and it isn’t actually attached to anything?

That is a problem.

It might be worth learning just a little bit about basic functions so you can create your gameover function, then call it, in the correct manner.

Have you tried the Corona For Newbies (4 parts) tutorials on Techority?

Peach :slight_smile: [import]uid: 52491 topic_id: 16012 reply_id: 59847[/import]

Hi Fakemode.

As a word of caution/advice, try not to rely too much on using other peoples snippets of code. I know it can be useful to copy/paste something in and have it work straight away, but it can be a huge headache if you don’t understand how it works.

It sounds to me like you’ve copied in some code which uses director, without actually intending to do that?

Presuming you can display a sprite and get it to fall using gravity, the next hurdle is to measure when the object has fallen off the screen. so something like

function gameover()  
 if yourObject.y \> 480 then  
 --display text and pause physics  
end  
  
gameover()  
--[[  
gameover is a function you set up. you want it to display "game over" text, in a certain colour, at a given x and y position. Then you need to pause/stop physics  
--]]  

I definitely recommend you visit the techority website and run through some of the tutorials there, they are really useful.

If you get stuck or have a specific question, ask and we’ll try to help, but be careful copying/pasting code you don’t fully understand, it’ll just give you a headache. [import]uid: 67933 topic_id: 16012 reply_id: 60204[/import]