Corona adding collision and playing a sound - lua

EDIT: Ignore most the below as the problem seems to be I don't have the "movieclip" module loaded according to the debugger... how in the hell do you load the movieclip or physics module I have wrote code for both and that is the issue. Is this module included? do I download it from somewhere? what gives?
I have the following code in Lua (corona specifically)
function scene:createScene( event )
local group = self.view
local bg = display.newImage("stage.png")
local vio = display.newImage("vio.png")
vio.x = 150
vio.y = 180
local b = display.newImage("b.png")
b.x = -70
b.y = 200
end
I need there to be a touch screen event so that dragging left or right moves object B left or right on the horizontal axis..and detects it crossing the center of the screen and plays an sound...
I found some code that would do this as a movieclip but the example code
local myAnim = movieclip.newAnim( b.png )
local function pressFunction()
myAnim.alpha = 0.7
end
local function releaseFunction()
myAnim.alpha = 1
end
myAnim:setDrag()
drag=true,
onPress=pressFunction,
onRelease=releaseFunction,
bounds= { 50,200, 220, 200}
end
Also I added the local movieclip = requires (movieclip) at the top of my code and it removes all my background images and tabBar :(
Please help me figure this out I am new to Corona and Lua.

Physics is part of the core Corona SDK API. You should not have to include any external files. Simply adding:
local physics = require("physics")
at the top of the module where you plan to use physics should suffice. As #speeder said, the movieclip.lua module has been deprecated in favor of using the new sprite sheets. Personally I loved using movieclip, but it's pretty wasteful on memory and isn't nearly as efficient or functional as sprite sheets.

Movieclip is a ancient thing...
It is a library, that used now deprecated and obsolete parts of the API.
I wonder even how you found it (I never had heard of it until seeing your question, and had to dig some forum skills to figure what it was).
So, yes, movieclip is a separate .lua file that you need to find and download. But I suggest you don't do that, since it uses things that don't exist anymore.

Related

how to use lua to get all files from desktop

I am making a project with lua that gets a list of all the file names from your desktop in lua. however, I can't figure out how to do it, and I am also going to be using love2d for it, because it is going to be a game. can you tell me how to do it? thanks!
Here is the code
function love.load()
require "player"
-- Lets add Some Variables!
-- Some Directory Suff first for Variables...
DesktopDirectory = love.filesystem.getUserDirectory().."Desktop"
DesktopFiles = love.filesystem.getDirectoryItems(DesktopDirectory)
-- These are the Images!
images = {
background = love.graphics.newImage("gfx/desktop.png")
}
players = {Player.New(50, 300, 40, 40, "gfx/stickman.png", true)}
love.graphics.setBackgroundColor(100, 220, 255)
for k in pairs(DesktopFiles) do
print(DesktopFiles[k])
end
end
function love.keypressed(k)
if k == "j" then
players[1].jump()
end
end
function love.update(dt)
for i in pairs(players) do
players[i].update()
end
end
function love.draw()
love.graphics.draw(images.background)
for i in pairs(players) do
players[i].draw()
end
end
Love2D (tries to) sandbox file system access, you're not supposed to touch anything outside your game's code or the "save directory" (where anything that you write goes). In particular, the Desktop folder is also out of reach. If you try to use love.filesystem.getDirectoryItems on that path, you'll just get an empty table. Same for other functions – they'll just refuse to work.
The easiest way to get that functionality is to include lfs and use its functions together with Lua's base io library for general file system access.

3DS Max model won't appear in Blitz3D

First post, yay, I guess. I'm new to Blitz3D, so I'm just now learning how to import a model from 3DS Max into Blitz. Here's the code:
Graphics3D 640,480,32,2
SetBuffer BackBuffer()
camera = CreateCamera()
light = CreateLight()
bottle = LoadMesh("bottle.3DS")
ScaleEntity bottle,0.1,0.1,0.1
End
I put the model file and the code in a folder together, but there's just black when I compile and run the code.
Since ScaleEntity isn't giving you an error, the model does seem to load. However, entities are created at 0, 0, 0 by default, so chances are you just can't see the bottle because your camera is inside it. Try something along the lines of PositionEntity camera, 0, 0, -5 and see if that helps.
Also, if that is your entire code, you're missing a RenderWorld and Flip; either within a loop, or followed by something like WaitKey, so that you can see what's being displayed before your program closes.

MATLAB MSER Feature detection not working

I am using the detectMSERFeatures function in the computer vision toolbox of MATLAB and have been running into a few errors. I have a black and white image that I am reading in to detect the features of, however I want to invert the image before running the feature detection or I am filtering for the red in an image. Therefore, either way I have a binary image that I am trying to use in detectMSERFeatures. I know that does not work, but I have tried several conversions to a usable format and none of them have seemed to work. detectMSERFeatures will pick up features if I use rgb2gray on the original image, but not if I try to convert it. Here is everything I have tried so far:
Target1=imread('Decal0.JPG');
Target1bw=~im2bw(Target1);
Target=uint8(Target1bw);
[m,n]=size(Target);
regionsTarget = detectMSERFeatures(Target, 'MaxAreaVariation',0.15,...
'ThresholdDelta',15, 'RegionAreaRange',[10000 (m*n)/2]);
Target1=imread('Decal0.JPG');
Target1bw=~im2bw(Target1);
Target=im2double(Target1bw);
regionsTarget = detectMSERFeatures(Target, 'MaxAreaVariation',0.15,...
'ThresholdDelta',15, 'RegionAreaRange',[10000 (m*n)/2]);
Target1=imread('Decal0.JPG');
Target1bw=~im2bw(Target1);
Target2=255*Target1bw;
[m,n]=size(Target2);
Target3=zeros(m,n,3);
Target3(:,:,1)=Target2;
Target3(:,:,2)=Target2;
Target3(:,:,3)=Target2;
Target3=uint8(Target3);
Target=rgb2gray(Target3);
regionsTarget = detectMSERFeatures(Target, 'MaxAreaVariation',0.15,...
'ThresholdDelta',15, 'RegionAreaRange',[10000 (m*n)/2]);
What have I done incorrectly?
I brought the question up to Mathworks and it was a bug in MATLAB. Here is their response:
"We have detected a bug in detectMSERFeatures when it handles binary images. A workaround would be is to use regionprops to detect the regions for binary images. Then, MSERRegions can be constructed as follows:
props = regionprops(im2bw(newGrayTarget),'PixelList');
pixlist = {}
for i = 1:numel(props)
pixlist = [pixlist; int32(props(i).PixelList)]; end
r = MSERRegions(pixlist);
Thanks for the help!

How to properly use an "images" subdirectory in Corona?

Seems like this should be pretty simple, but I'm finding it frustratingly difficult to get right. Rather than jam all my images into my project's base directory, I'm placing them in a subdirectory named "images". However when I try to load an image from this directory, I receive:
ERROR: bad argument #2 to display.newImageRect(): width expected, but got string.
local background = display.newImageRect( "menu-bg.jpg", "images/", 570, 360 )
From the docs, I don't see any problems with the syntax. Is this a bug with the display library, or the docs, or am I handling the baseDir property wrong (and seeing a wonky error message)?
Ok after fiddling with this some more, it looks like I can append the path to the filename, e.g.
local background = display.newImageRect( "images/menu-bg.jpg", 570, 360 )
In other words, I misunderstood the meaning of "baseDir".

Using Google Maps lib with Polymer

I'm converting a Dart app that uses the GMap lib to Polymer. The map however does not seem to get rendered and nothing else of my app is as well. All I get is a blank screen. I'm not getting a runtime error.
The div where the map is rendered in is in a polymer element. In the Dart file, I'm instantiating the map like this:
final mapOptions = new MapOptions()
..zoom = 15
..center = LAT_LONG_KORTRIJK
..mapTypeId = MapTypeId.ROADMAP;
Element mapView = getShadowRoot("my-element").query("#mapView");
_map = js.retain(new GMap(mapView, mapOptions));
Any ideas on what be going on?
The js package does not support Shadow DOM for now. You are facing to issue-99. Until a native Element support in dart:js lands I don't think this issue will be fixed.
Danger Zone : There could perhaps be a dirty way to work around this problem based on this message by manually replacing /packages/js/ with the content of the pointed js branch.

Resources