Free Developer Support

@Naomi,

Twitter is very simple:

[lua]native.showWebPopup( x, y, width, height, “http://twitter.com/intent/tweet?text=”…theString )[/lua] [import]uid: 16734 topic_id: 20965 reply_id: 91569[/import]

Hey, Ken, thank you for your reply. What I want, though, is to avoid native.showWebPopup. Is there a way to implement Twitter without the use of native.showWebPopup??

Here are some of the posts that I looked at, but all of them appear to use native.showWebPopup:
http://developer.anscamobile.com/forum/2012/01/10/twitter-oauth
http://developer.anscamobile.com/code/oauth-library
http://techority.com/2011/05/26/post-to-twitter-from-your-application/

Here’s the reason why I’d like to avoid using native.showWebPopup:
http://developer.anscamobile.com/forum/2012/01/25/memory-leak-webpopups

I thought this aggressive caching business wasn’t all that bad, until I did some intense testing of my game that led to memory warning on console and eventually crashed my game…

Naomi [import]uid: 67217 topic_id: 20965 reply_id: 91578[/import]

The problem you have is that you have to give the user some way to Log In and to do the actual “Tweet”. Otherwise you could just use this:

[lua]system.openURL(“https://twitter.com/intent/tweet?text=Test”)[/lua] [import]uid: 16734 topic_id: 20965 reply_id: 91581[/import]

System.openurl will still open a web popup, its just opened by the system which might not make a difference in terms of memory. You could try it and I’m not sure if there is a difference in the call in terms of memory retention, but it should be essentially the same as using native.showWebPopup for all intents and purposes.

Have you tried internally making your own network call to twitter with the text as your post? Then you wouldn’t need to use a web popup, but you can make tweets in the minimal way possible. For getting the username/password, you can make your own interface with a textfield where they can enter information for the tweet.

Let me know what you think. [import]uid: 49520 topic_id: 20965 reply_id: 91592[/import]

@Ken, thank you for your thoughts and suggestions.

@James, internally making the network call sounds great to me. I did look at network.request API ( http://developer.anscamobile.com/node/5305 ), but I’m not sure how I may go about marrying the Twitter App with the network.request. I’d so appreciate it if you can put together some sort of generic sample code that we can all work off of.

Thanks again.

Naomi
[import]uid: 67217 topic_id: 20965 reply_id: 91594[/import]

@Naomi,

I’ll see what I can do about it and get back to you either tonight or tomorrow.

[import]uid: 49520 topic_id: 20965 reply_id: 91603[/import]

@James, that sounds great. Thank you so much!

Naomi [import]uid: 67217 topic_id: 20965 reply_id: 91604[/import]

Hi James,

Thanks so much for taking the time to help me out.

I looked over your code and tried to integrate it with mine, but cannot get it to behave as expected. I’d like the sprite to continue spinning for a bit after the swipe has stopped (based on velocity of flick). Perhaps an example for line #63 could help with my non-understanding.

I have zipped up my project along with the sprite so you can see the current state and my version of spinning.

http://db.tt/Irs5sLpm

Thanks again for your time, it’s greatly appreciated.

Greg [import]uid: 2108 topic_id: 20965 reply_id: 91752[/import]

Physics Button problem.

I have a physics based game using buttons. When a button falls, it may land on the floor on its right side, left side, upside down and occasionally right side up. I need it to fall, spin, bounce, etc. but always end up with the right side up. Can you suggest a way to do this? I’m using Storyboard. [import]uid: 6288 topic_id: 20965 reply_id: 91840[/import]

If something collides with my object, I detect it with Physics and set
[lua]myObjectRotated = true[/lua]

Then, later in the game code:

[lua]if myObjectRotated == true then
transition.to(myObject, { time = 5000, rotation = 0 })
myObjectRotated = false
end [/lua] [import]uid: 10389 topic_id: 20965 reply_id: 91842[/import]

neat thread… i just bumped into it…

woohoo +1

c
[import]uid: 24 topic_id: 20965 reply_id: 91854[/import]

@Naomi,

This twitter client is going to take some time to do. I need to work on it on the weekend and I’ll show my results.

@Carlos,

I’m glad you like it. Just trying to do what we can.

@GP,

I tried this out and it seems to work. Try this:

main.lua
[lua]-- hide status bar
display.setStatusBar(display.HiddenStatusBar)

– pipe terminal output to Sublime Text’s build console; strip out on publish
io.output():setvbuf(“no”)

– load classes
local grabber = require(“SpriteGrabber”)

– set forward referencing & variables
local spinNum
local prevX = 0
local prevY = 0
local dragDist = 0
local math_abs = math.abs
local dragDistNum = 15
local i

– make sprite clips
local function makeClips1(num)
local spriteClips1 = {}
for i = 1, num do
spriteClips1[“spin”…i] = {i,1,1,1}
end
@jt
–you need to add a full rotation to play when you want to spin it
–you will need to add sprites for a reversed spin effect
spriteClips1[“fullSpin”] = {1,15,5000,0}
return spriteClips1
end

– load sprites
local spritesheetSpin1 = grabber.grabSheet(“DragonSpin”)
local spin1 = spritesheetSpin1:grabSprite(“Dragon”,true,makeClips1(15))
–local fullSprite = spritesheetSpin1:grabSprite(“Dragon”,true,makeClips1(15))

@start jt edit: hold previous time
local prevTime
@end jt edit

local function makeSpin(e)
dragDist = math_abs(e.x - prevX)
local t = e.target
local phase = e.phase
if “began” == phase then
local parent = t.parent – make image top-most object
parent:insert(t)
display.getCurrentStage():setFocus(t)
t.isFocus = true – prevents touch events off target
prevX = e.x – store initial touch position
elseif t.isFocus then
if “moved” == phase then

@start jt edits
local newTime = e.time – renamed from event
local velocity = 0 – assigned value to prevent nil
–set the new previous time
prevTime = newTime
@end jt edits

if e.x > prevX and dragDist > dragDistNum then – moving right
if spinNum < 15 then
spinNum = spinNum + 1
elseif spinNum == 15 then
spinNum = spinNum - 14
end
print("Image # "…spinNum)
spin1:playClip(“spin”…spinNum)
elseif e.x < prevX and dragDist > dragDistNum then – moving left
if spinNum > 1 then
spinNum = spinNum - 1
elseif spinNum == 1 then
spinNum = spinNum + 14
end
print("Image # "…spinNum)
spin1:playClip(“spin”…spinNum)
end

– factor back swipDist
if e.x > prevX + dragDistNum or e.x < prevX - dragDistNum then
prevX = e.x
end

elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus(nil)
t.isFocus = false

@start jt edits
–we need to so all of our logiv in the end phase
local newTime = e.time
local x = e.x
local y = e.y
local velocity = 0

– we need to do some math here to get the speed used to get from one point to another
if prevTime ~= nil then
local totalTime = newTime - prevTime
local dist = math.sqrt(((x-prevX)*(x-prevX))+((y - prevY)*(y - prevY)))
velocity = dist/totalTime
–print('velocity is '…velocity)
end

– if the velocity is greater than 20 , we’ll play the animation at the current speed
if velocity > 20 then
– switch to some new frames

local spinVelocity = velocity * 0.2
if spinVelocity > 16 then --the maximum you can have this value is 20 but i used 15
spinVelocity = 15
end

spin1.timeScale = spinVelocity
spin1:playClip(“fullSpin”)

–now for the velocity to decrease during a certain period of time
–this gives the look that it’s winding down
local function onSpriteSpin(event)
spin1.timeScale = spin1.timeScale - 0.2
print(spin1.timeScale)
if spin1.timeScale < 1 or spin1.timeScale == 1 then
spin1.timeScale = 1
spin1:pause()
spin1:removeEventListener(‘sprite’,onSpriteSpin)
end
end

spin1:addEventListener(‘sprite’,onSpriteSpin)

end

@end jt edits

end
end
return true
end

–set initial state
local function init()
spin1:scale(1.35,1.35)
spinNum = 2
spin1:playClip(“spin”…spinNum)
spin1:addEventListener(“touch”, makeSpin)
end
init()[/lua] [import]uid: 49520 topic_id: 20965 reply_id: 91918[/import]

Hi James, thank you so much for the follow up. I appreciate all you do, and look forward to what you may come up with – and hopefully it won’t be too complex for me :slight_smile:

Naomi [import]uid: 67217 topic_id: 20965 reply_id: 91990[/import]

Wow, this is impressive…thanks!

I followed your code comments and created the additional sprite frames to simulate a backwards spin. The only problem with this method is the sprite clip’s starting frame (fired during the end phase) is not contiguous with the ending frame (fired during the moved phase). End result, the sprite jumps to the respective starting frames when flicking.

I tried replacing the clip’s startFrame with the spinNum variable, but that throws off the frame count. Maybe add difference between spinNum and original startFrame, to get new startFrame, then subtract difference from totalFrames, then reset. Cannot seem to wrap my head around this one. Any ideas?

Also, is prevY and e.y even needed if spinning is only on a horizontal axis?

Here is the updated project: http://db.tt/Grt1xvcO [import]uid: 2108 topic_id: 20965 reply_id: 92112[/import]

Hi,

I wonder if someone can answer this question : Is it possible to add a pinch-zoom function AND a pan function in a single scene? I tried it myself but the functions kept interfering.

any help will be appreciated [import]uid: 44110 topic_id: 20965 reply_id: 92393[/import]

@GP,

I think you may have already figured that out in another part of your code. Have you tried adding this to the sprite event?

[lua] --now for the velocity to decrease during a certain period of time
–this gives the look that it’s winding down
local function onSpriteSpin(event)
spin1.timeScale = spin1.timeScale - 0.7
if spin1.timeScale < 1 or spin1.timeScale == 1 then
spin1.timeScale = 1

@jt this will run on every frame event, so it will keep track of the frames you loose because of the spinning
if spinDir == “right” then
if spinNum >= 1 and spinNum < 15 then
spinNum = spinNum + 1
elseif spinNum == 15 then
spinNum = 1
end
elseif spinDir == “left” then
if spinNum > 1 and spinNum <= 15 then
spinNum = spinNum - 1
elseif spinNum == 1 then
spinNum = 15
end
end
spin1:pause()
spin1:removeEventListener(‘sprite’,onSpriteSpin)
end

@jt you can use this to make sure its on the right frame number when it’s done
– if event.phase == ‘end’ then
– print('current spriteNum '…spinNum)
– end
end
spin1:addEventListener(‘sprite’,onSpriteSpin)[/lua]

Let me know if this helps.

@emerson,

I would suggest holding a number value to determine the number of touches total on the screen. When a touch event starts, it adds one to the touch count and decreases the touch count by one when it leaves. If there is one touch count, do a pan event, and if there is two do a zoom effect.

Let me know if this works for you. If not, please send some sample code so I can help with the current issue.
@Naomi,

I am still at work making this twitter client. There are a lot of things to check for authorization, but when I’m done with the module, you should only have to enter a few things to get it to work.

I don’t want to release it until its complete, so I’m going take until the upcoming week to finish and make a tutorial on how to use it. [import]uid: 49520 topic_id: 20965 reply_id: 92680[/import]

I tried it before but it didn’t work Sorry:)

Then it did some web-searching andI came across this:

http://developer.anscamobile.com/code/pinch-zoom-xl

This gave me what I wanted, except that I want to apply it to the whole scene and get the physics ( and gameUI )working.

Heres what I got so far, the terminal kept saying that there is an error with it!!

I am still quite a newbie so the code (maybe, it seems nothing wrong with me) has many errors in it

www.geogamez.com/level1.lua

The code is too long to fit in this comment box, so I uploaded to my website’s server instead
[import]uid: 44110 topic_id: 20965 reply_id: 92754[/import]

Never mind, got it working after a lot of attempts!

One more thing: is it possible NOT to let the user to pan to the edge of the scene?

And gameUI drag body doesn’t work like before…(works weird)

Corona is awesome! I think I did the right move when I gave up on Objective-C

Code:

www.geogamez.com/level1%20new.lua [import]uid: 44110 topic_id: 20965 reply_id: 93232[/import]

@emerson,

Cool! Glad it’s resolved. And if you don’t want the user to go past a certain part, you can put something in the panning event that prevents the screen from moving when the event.x and event.y property are above or below certain values. Let me know if t his works for you. [import]uid: 49520 topic_id: 20965 reply_id: 93289[/import]

Well, I still quite a noob so I don’t know how to do that. Could you please send me some code?Thanks

PS How about the Twitter Client? [import]uid: 44110 topic_id: 20965 reply_id: 94045[/import]